From 4635dc4eec5156b9cbfbdf5a3ec6ce60f0f35890 Mon Sep 17 00:00:00 2001 From: Tamius Han Date: Fri, 4 Dec 2020 02:02:25 +0100 Subject: [PATCH] fix ui --- src/ext/lib/uwui/UI.js | 44 +++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/src/ext/lib/uwui/UI.js b/src/ext/lib/uwui/UI.js index 3f0bb36..35eb9ff 100644 --- a/src/ext/lib/uwui/UI.js +++ b/src/ext/lib/uwui/UI.js @@ -22,27 +22,17 @@ class UI { } async init() { - // If comms exist, we need to destroy it - if (this.comms) { - this.comms.destroy(); - } - if (!this.settings) { - this.settings = new Settings({ - onSettingsChanged: () => this.reloadSettings(), - logger: this.logger - }); - await this.settings.init(); - } - - this.comms = new CommsClient('content-ui-port', null, this.commsConfig.handlers); - // initialize vuejs, but only once (check handled in initVue()) // we need to initialize this _after_ initializing comms. + this.initVue(); } async initVue() { - this.vuexStore = createStore(this.storeConfig); + if (this.storeConfig) { + this.vuexStore = createStore(this.storeConfig); + } + this.initUi(); } @@ -52,10 +42,18 @@ class UI { const uwid = 'not-so-random-id' const rootDiv = document.createElement('div'); - rootDiv.setAttribute('style', `position: ${uiConfig.style?.position ?? 'relative'}; width: ${uiConfig.style?.width ?? '100%'}; height: ${uiConfig.style?.height ?? '100%'}; ${uiConfig.additionalStyle}`); - rootDiv.setAttribute('id', uwid); - if (this.uiConfig.parentElement) { + try { + rootDiv.setAttribute('style', `position: ${this.uiConfig.style?.position ?? 'relative'}; width: ${this.uiConfig.style?.width ?? '100%'}; height: ${this.uiConfig.style?.height ?? '100%'}; ${this.uiConfig.additionalStyle ?? ''}`); + rootDiv.setAttribute('id', uwid); + } catch (e) { + console.error("ERROR:", e) + } + + console.warn('UI: init 3', this.uiConfig); + + + if (this.uiConfig?.parentElement) { this.uiConfig.parentElement.appendChild(rootDiv); } else { document.body.appendChild(rootDiv); @@ -63,9 +61,11 @@ class UI { this.element = rootDiv; - createApp(this.uiConfig.component) - .use(this.vuexStore) - .mount(`${uwid}`); + const app = createApp(this.uiConfig.component); + if (this.vuexStore) { + app.use(this.vuexStore); + } + app.mount(`#${uwid}`); } /** @@ -79,7 +79,7 @@ class UI { } destroy() { - this.comms?.destroy(); + // this.comms?.destroy(); this.element?.remove(); } }