client: ensure a proper init order for server-client communication

This commit is contained in:
jean-emmanuel 2025-12-04 17:56:12 +01:00
parent dc7ac2bcd3
commit acf5f74ea2
3 changed files with 32 additions and 23 deletions

View file

@ -13,18 +13,20 @@ function init() {
setTimeout(()=>{
ipc.init()
ipc.init(()=>{
document.title = TITLE
ipc.send('open', {hotReload: backup.exists})
document.title = TITLE
window.onunload = ()=>{
ipc.send('close')
}
ipc.send('open', {hotReload: backup.exists})
backup.load()
window.onunload = ()=>{
ipc.send('close')
}
backup.load()
})
}, 100)

View file

@ -4,7 +4,8 @@ import cache from '../managers/cache.mjs'
import {ENV} from '../globals.mjs'
var notifications, locales, callbacks
;(async()=>{
var loadDeps = (async()=>{
notifications = (await import('../ui/notifications.mjs')).default
locales = (await import('../locales/index.mjs')).default
callbacks = (await import('./callbacks.mjs')).default
@ -49,24 +50,30 @@ class Ipc extends EventEmitter {
document.cookie = 'client_id=' + uuid + ';samesite=strict'
try {
this.open()
} catch(e) {
console.warn('Could not open a WebSocket connection')
console.log(e)
}
}
init() {
init(callback) {
for (let i in callbacks) {
let callback = callbacks[i]
this.on(i, (data)=>{
callback(data)
})
}
loadDeps.then(()=>{
for (let i in callbacks) {
let callback = callbacks[i]
this.on(i, (data)=>{
callback(data)
})
}
try {
this.open()
} catch(e) {
console.warn('Could not open a WebSocket connection')
console.log(e)
}
callback()
})
}