From 41c93ca47fc43d70c6b234650ec11b175d723b39 Mon Sep 17 00:00:00 2001 From: Arc Date: Fri, 3 Jan 2025 12:52:20 +0000 Subject: [PATCH] getting there --- lnbits/static/js/init-app.js | 91 ++++++++++++++++++++++-------------- 1 file changed, 57 insertions(+), 34 deletions(-) diff --git a/lnbits/static/js/init-app.js b/lnbits/static/js/init-app.js index 952796ccd..7acc9e4bb 100644 --- a/lnbits/static/js/init-app.js +++ b/lnbits/static/js/init-app.js @@ -1,39 +1,62 @@ -window.router = VueRouter.createRouter({ +function loadScript(src) { + return new Promise((resolve, reject) => { + const script = document.createElement('script'); + script.src = src; + script.async = true; + script.onload = resolve; + script.onerror = reject; + document.head.appendChild(script); + }); + } + + window.router = VueRouter.createRouter({ history: VueRouter.createWebHistory(), - routes: [ + routes: [ { - path: '/wallet', - name: 'Wallet', - component: { - template: '
', - async mounted() { - try { - const response = await fetch('/wallet', { - credentials: 'include', - headers: { - 'Accept': 'text/html', - 'X-Requested-With': 'XMLHttpRequest' - } - }) - const html = await response.text() - this.$refs.content.innerHTML = html - this.$forceUpdate() - } catch (error) { - console.error('Error loading wallet:', error) - } + path: '/wallet', + name: 'Wallet', + component: { + template: '
', + async mounted() { + try { + // Fetch and inject the HTML + const response = await fetch('/wallet', { + credentials: 'include', + headers: { + 'Accept': 'text/html', + 'X-Requested-With': 'XMLHttpRequest', + }, + }); + const html = await response.text(); + this.$refs.content.innerHTML = html; + + // Dynamically load the wallet.js script + await loadScript('/static/js/wallet.js'); + + // Initialize the wallet app if necessary + if (window.app && typeof window.app.mount === 'function') { + window.app.mount(this.$refs.content); // Adjust the mount target if needed } - } - } - ] - }) + + this.$forceUpdate(); + } catch (error) { + console.error('Error loading wallet:', error); + } + }, + }, + }, + ], + }); window.router.beforeEach((to, from, next) => { - console.log('Route changing from', from.path, 'to', to.path) - next() - }) - -window.app.use(VueQrcodeReader) -window.app.use(Quasar) -window.app.use(window.i18n) -window.app.use(window.router) -window.app.mount('#vue') + console.log('Route changing from', from.path, 'to', to.path); + next(); + }); + + // Initialize Vue app + window.app.use(VueQrcodeReader); + window.app.use(Quasar); + window.app.use(window.i18n); + window.app.use(window.router); + window.app.mount('#vue'); + \ No newline at end of file