[🐛] Fixed UV issue

This commit is contained in:
ThinLiquid 2023-11-25 02:59:17 +00:00 committed by GitHub
parent 4a9aad5005
commit 293a84af8e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 13 additions and 21 deletions

View file

@ -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)));

View file

@ -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: [

View file

@ -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()
})
}

View file

@ -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')