start bootstrapper

This commit is contained in:
Avad3 2024-07-30 22:09:17 -04:00
parent 034c8e1c6d
commit 17b440ea37
15 changed files with 166 additions and 131 deletions

View file

@ -1,3 +1,4 @@
import IDBMap from "idb-map-entries";
import { FakeServiceWorker } from "./fakesw";
import { swfetch } from "./fetch";
import { ScramjetThreadpool } from "./threadpool";
@ -18,10 +19,9 @@ export class ScramjetServiceWorker {
serviceWorkers: FakeServiceWorker[] = [];
constructor(config = self.$scramjet.config) {
constructor() {
this.loadConfig();
this.client = new self.$scramjet.shared.util.BareClient();
if (!config.prefix) config.prefix = "/scramjet/";
this.config = config;
this.threadpool = new ScramjetThreadpool();
@ -46,6 +46,20 @@ export class ScramjetServiceWorker {
});
}
loadConfig() {
const store = new IDBMap("config", {
prefix: "scramjet"
});
if (store.has("config")) {
store.get("config").then((config) => {
this.config = config;
self.$scramjet.config = config;
self.$scramjet.codec = self.$scramjet.codecs[config.codec]
});
}
}
async getLocalStorage(): Promise<Record<string, string>> {
let clients = await self.clients.matchAll();
clients = clients.filter(