()
| 43 | } |
| 44 | |
| 45 | async init() { |
| 46 | this.messageQueue.subscribe<string>("setSandboxLanguage", async (lang) => { |
| 47 | setSandboxLanguage(this.windowMessage, lang); |
| 48 | }); |
| 49 | this.messageQueue.subscribe<TEnableScript[]>("enableScripts", async (data) => { |
| 50 | for (const { uuid, enable } of data) { |
| 51 | const script = await this.scriptClient.info(uuid); |
| 52 | if (script.type === SCRIPT_TYPE_NORMAL) { |
| 53 | continue; |
| 54 | } |
| 55 | if (enable) { |
| 56 | // 构造脚本运行资源,发送给沙盒运行 |
| 57 | enableScript(this.windowMessage, await this.scriptClient.getScriptRunResourceByUUID(uuid)); |
| 58 | } else { |
| 59 | // 发送给沙盒停止 |
| 60 | disableScript(this.windowMessage, script.uuid); |
| 61 | } |
| 62 | } |
| 63 | }); |
| 64 | this.messageQueue.subscribe<TInstallScript>("installScript", async (data) => { |
| 65 | // 普通脚本不处理 |
| 66 | if (data.script.type === SCRIPT_TYPE_NORMAL) { |
| 67 | return; |
| 68 | } |
| 69 | // 判断是开启还是关闭 |
| 70 | if (data.script.status === SCRIPT_STATUS_ENABLE) { |
| 71 | // 构造脚本运行资源,发送给沙盒运行 |
| 72 | enableScript(this.windowMessage, await this.scriptClient.getScriptRunResourceByUUID(data.script.uuid)); |
| 73 | } else { |
| 74 | // 发送给沙盒停止 |
| 75 | disableScript(this.windowMessage, data.script.uuid); |
| 76 | } |
| 77 | }); |
| 78 | this.messageQueue.subscribe<TDeleteScript[]>("deleteScripts", async (data) => { |
| 79 | for (const { uuid, type } of data) { |
| 80 | // 只发送后台脚本和定时脚本 |
| 81 | if (type === SCRIPT_TYPE_BACKGROUND || type === SCRIPT_TYPE_CRONTAB) { |
| 82 | await disableScript(this.windowMessage, uuid); |
| 83 | } |
| 84 | } |
| 85 | }); |
| 86 | |
| 87 | this.group.on("runScript", this.runScript.bind(this)); |
| 88 | this.group.on("stopScript", this.stopScript.bind(this)); |
| 89 | } |
| 90 | } |
no test coverage detected