a
Some checks failed
build / Build (push) Failing after 6s
test / Run tests (push) Failing after 10s

This commit is contained in:
2025-02-12 22:28:56 +08:00
parent 9b9513fea5
commit 3a41bf0f21
3 changed files with 104 additions and 14 deletions

View File

@ -12,7 +12,7 @@ import { GMApi } from "./gm_api";
export class OffscreenManager {
private extensionMessage: MessageSend = new ExtensionMessageSend("service_worker");
private windowMessage = new WindowMessage(window, sandbox);
private windowMessage = new WindowMessage(window, sandbox, true);
private windowApi: Server = new Server(this.windowMessage);
@ -35,6 +35,11 @@ export class OffscreenManager {
}
async initManager() {
navigator.serviceWorker.ready.then((registration) => {
// 通知service worker已经准备好了
registration.active?.postMessage("okkkk");
});
// 监听消息
this.windowApi.on("logger", this.logger.bind(this));
this.windowApi.on("preparationSandbox", this.preparationSandbox.bind(this));

View File

@ -5,24 +5,27 @@ import { ExtensionMessage } from "@Packages/message/extension_message";
import { ResourceService } from "./resource";
import { ValueService } from "./value";
import { RuntimeService } from "./runtime";
import { ServiceWorkerMessageSend } from "@Packages/message/window_message";
import { sendMessageToOffscreen } from "./gm_api";
export type InstallSource = "user" | "system" | "sync" | "subscribe" | "vscode";
// service worker的管理器
export default class ServiceWorkerManager {
constructor() {}
private api: Server = new Server(new ExtensionMessage("service_worker"));
private mq: MessageQueue = new MessageQueue(this.api);
private sender: ServiceWorkerMessageSend = new ServiceWorkerMessageSend();
async initManager() {
const group = this.api.group("serviceWorker");
group.on("preparationOffscreen", async () => {
// 准备好环境
sendMessageToOffscreen("aa", "aa");
await this.sender.init();
this.mq.emit("preparationOffscreen", {});
// sendMessageToOffscreen("preparationOffscreen", {});
this.sender.sendMessage("test");
});
const resource = new ResourceService(group.group("resource"), this.mq);