王一之 fd2aba4286
Some checks failed
test / Run tests (push) Failing after 6s
build / Build (push) Failing after 9s
test
2025-03-19 18:05:54 +08:00

36 lines
1.2 KiB
TypeScript

import { Server } from "@Packages/message/server";
import { MessageQueue } from "@Packages/message/message_queue";
import { ScriptService } from "./script";
import { ResourceService } from "./resource";
import { ValueService } from "./value";
import { RuntimeService } from "./runtime";
import { ServiceWorkerMessageSend } from "@Packages/message/window_message";
export type InstallSource = "user" | "system" | "sync" | "subscribe" | "vscode";
// service worker的管理器
export default class ServiceWorkerManager {
constructor(
private api: Server,
private mq: MessageQueue,
private sender: ServiceWorkerMessageSend
) {}
async initManager() {
this.api.on("preparationOffscreen", async () => {
// 准备好环境
await this.sender.init();
this.mq.emit("preparationOffscreen", {});
});
const resource = new ResourceService(this.api.group("resource"), this.mq);
resource.init();
const value = new ValueService(this.api.group("value"), this.mq);
value.init();
const script = new ScriptService(this.api.group("script"), this.mq, value, resource);
script.init();
const runtime = new RuntimeService(this.api.group("runtime"), this.sender, this.mq, value);
runtime.init();
}
}