From acf5f74ea22ccda9ca57458affe7dce867b9b851 Mon Sep 17 00:00:00 2001 From: jean-emmanuel Date: Thu, 4 Dec 2025 17:56:12 +0100 Subject: [PATCH] client: ensure a proper init order for server-client communication --- package.json | 2 +- src/client/index.mjs | 16 +++++++++------- src/client/ipc/index.mjs | 37 ++++++++++++++++++++++--------------- 3 files changed, 32 insertions(+), 23 deletions(-) diff --git a/package.json b/package.json index 7f0d5be6..745a9a23 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "open-stage-control", "productName": "Open Stage Control", "description": "Libre and modular OSC / MIDI controller", - "version": "1.30.0-beta4", + "version": "1.30.0-beta5", "author": { "name": "Jean-Emmanuel Doucet", "email": "jean-emmanuel@ammd.net" diff --git a/src/client/index.mjs b/src/client/index.mjs index 3029c061..fef5d21a 100644 --- a/src/client/index.mjs +++ b/src/client/index.mjs @@ -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) diff --git a/src/client/ipc/index.mjs b/src/client/ipc/index.mjs index 9723e3b5..b702384d 100644 --- a/src/client/ipc/index.mjs +++ b/src/client/ipc/index.mjs @@ -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() + + }) }