处理service worker的问题
Some checks failed
test / Run tests (push) Failing after 3s
build / Build (push) Failing after 6s
Some checks failed
test / Run tests (push) Failing after 3s
build / Build (push) Failing after 6s
This commit is contained in:
parent
315f5f148c
commit
db8c5ec7b5
@ -1,12 +1,6 @@
|
|||||||
import { MessageQueue } from "@Packages/message/message_queue";
|
import { MessageQueue } from "@Packages/message/message_queue";
|
||||||
import { Group, MessageSend } from "@Packages/message/server";
|
import { Group, MessageSend } from "@Packages/message/server";
|
||||||
import {
|
import { Script, SCRIPT_STATUS_ENABLE, SCRIPT_TYPE_NORMAL, ScriptDAO, ScriptRunResouce } from "@App/app/repo/scripts";
|
||||||
Script,
|
|
||||||
SCRIPT_STATUS_ENABLE,
|
|
||||||
SCRIPT_TYPE_NORMAL,
|
|
||||||
ScriptDAO,
|
|
||||||
ScriptRunResouce,
|
|
||||||
} from "@App/app/repo/scripts";
|
|
||||||
import { ValueService } from "./value";
|
import { ValueService } from "./value";
|
||||||
import GMApi from "./gm_api";
|
import GMApi from "./gm_api";
|
||||||
import { subscribeScriptDelete, subscribeScriptEnable, subscribeScriptInstall } from "../queue";
|
import { subscribeScriptDelete, subscribeScriptEnable, subscribeScriptInstall } from "../queue";
|
||||||
@ -15,11 +9,12 @@ import { runScript, stopScript } from "../offscreen/client";
|
|||||||
import { dealMatches, getRunAt } from "./utils";
|
import { dealMatches, getRunAt } from "./utils";
|
||||||
import { randomString } from "@App/pkg/utils/utils";
|
import { randomString } from "@App/pkg/utils/utils";
|
||||||
import { compileInjectScript, compileScriptCode } from "@App/runtime/content/utils";
|
import { compileInjectScript, compileScriptCode } from "@App/runtime/content/utils";
|
||||||
|
import Cache from "@App/app/cache";
|
||||||
|
|
||||||
export class RuntimeService {
|
export class RuntimeService {
|
||||||
scriptDAO: ScriptDAO = new ScriptDAO();
|
scriptDAO: ScriptDAO = new ScriptDAO();
|
||||||
|
|
||||||
scriptFlag: string = randomString(8);
|
scriptFlag: string = "";
|
||||||
|
|
||||||
// 运行中的页面脚本
|
// 运行中的页面脚本
|
||||||
runningPageScript = new Map<string, ScriptRunResouce>();
|
runningPageScript = new Map<string, ScriptRunResouce>();
|
||||||
@ -33,6 +28,9 @@ export class RuntimeService {
|
|||||||
) {}
|
) {}
|
||||||
|
|
||||||
async init() {
|
async init() {
|
||||||
|
this.scriptFlag = await Cache.getInstance().getOrSet("scriptInjectFlag", () => {
|
||||||
|
return Promise.resolve(randomString(16));
|
||||||
|
});
|
||||||
// 读取inject.js注入页面
|
// 读取inject.js注入页面
|
||||||
this.registerInjectScript();
|
this.registerInjectScript();
|
||||||
// 监听脚本开启
|
// 监听脚本开启
|
||||||
|
@ -217,3 +217,13 @@ export function sleep(time: number) {
|
|||||||
setTimeout(resolve, time);
|
setTimeout(resolve, time);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 使service_worker长时间存活
|
||||||
|
export async function waitUntil(promise: Promise<any>) {
|
||||||
|
const keepAlive = setInterval(chrome.runtime.getPlatformInfo, 25 * 1000);
|
||||||
|
try {
|
||||||
|
await promise;
|
||||||
|
} finally {
|
||||||
|
clearInterval(keepAlive);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user