From 293a84af8e94e637d1bdaed97e3a5254bbfb7cb7 Mon Sep 17 00:00:00 2001 From: ThinLiquid Date: Sat, 25 Nov 2023 02:59:17 +0000 Subject: [PATCH] [:bug:] Fixed UV issue --- public/uv-sw.js | 12 ++++-------- public/uv/uv.sw.js | 4 ++-- src/builtin/apps/settings.ts | 10 +--------- src/index.ts | 8 ++++++-- 4 files changed, 13 insertions(+), 21 deletions(-) diff --git a/public/uv-sw.js b/public/uv-sw.js index 843853a..2adfadd 100644 --- a/public/uv-sw.js +++ b/public/uv-sw.js @@ -1,12 +1,8 @@ importScripts('/uv/uv.sw.js'); -const params = new URLSearchParams(self.serviceWorker.scriptURL) - -var cfg = JSON.parse(params.get('config')); -const sw = new UVServiceWorker(cfg); - -self.addEventListener('fetch', event => - event.respondWith(sw.fetch(event)) -); +const params = new URL(self.serviceWorker.scriptURL).searchParams +const serverURL = atob(params.get('url')); +const sw = new UVServiceWorker(serverURL); +self.addEventListener('fetch', event => event.respondWith(sw.fetch(event))); \ No newline at end of file diff --git a/public/uv/uv.sw.js b/public/uv/uv.sw.js index 4e851eb..2b2e8cb 100644 --- a/public/uv/uv.sw.js +++ b/public/uv/uv.sw.js @@ -2,9 +2,9 @@ importScripts('/uv/uv.bundle.js'); importScripts('/uv/uv.config.js'); class UVServiceWorker extends EventEmitter { - constructor(flowURL, config = __uv$config) { + constructor(serverURL, config = __uv$config) { super(); - config.bare = flowURL + '/bare/'; + config.bare = serverURL + '/bare/'; this.addresses = typeof config.bare === 'string' ? [ new URL(config.bare, location) ] : config.bare.map(str => new URL(str, location)); this.headers = { csp: [ diff --git a/src/builtin/apps/settings.ts b/src/builtin/apps/settings.ts index 5b858aa..d5110e3 100644 --- a/src/builtin/apps/settings.ts +++ b/src/builtin/apps/settings.ts @@ -82,15 +82,7 @@ export default class SettingsApp implements App { win.content.querySelector('.save')?.addEventListener('click', () => { (config as any)[key] = input.value - navigator.serviceWorker.getRegistrations().then(function (registrations) { - for (const registration of registrations) { - registration.unregister().then(() => { - navigator.serviceWorker.register('/uv-sw.js?config=' + encodeURIComponent(config.SERVER_URL), { - scope: '/service/' - }).catch(e => console.error(e)) - }).catch(e => console.error(e)) - } - }).catch(e => console.error(e)) + window.location.reload() }) } diff --git a/src/index.ts b/src/index.ts index 769b889..cba42a6 100644 --- a/src/index.ts +++ b/src/index.ts @@ -75,9 +75,13 @@ window.wm = new WindowManager(); }) } - navigator.serviceWorker.register('/uv-sw.js?config=' + encodeURIComponent((await window.config()).SERVER_URL), { + const registrations = await navigator.serviceWorker.getRegistrations() + for (const registration of registrations) { + await registration.unregister() + } + await navigator.serviceWorker.register('/uv-sw.js?url=' + encodeURIComponent(btoa((await window.config()).SERVER_URL)), { scope: '/service/' - }).catch(e => console.error(e)) + }) await window.preloader.setDone('filesystem')