fix msg
Some checks failed
build / Build (push) Failing after 9s
test / Run tests (push) Failing after 9s
Some checks failed
build / Build (push) Failing after 9s
test / Run tests (push) Failing after 9s
This commit is contained in:
parent
9f8f7c8347
commit
23b8efcdf5
@ -1,7 +1,13 @@
|
||||
import { Message, MessageConnect } from "./server";
|
||||
|
||||
export function sendMessage(msg: Message, action: string, data?: any): Promise<any> {
|
||||
return msg.sendMessage({ action, data });
|
||||
export async function sendMessage(msg: Message, action: string, data?: any): Promise<any> {
|
||||
const res = await msg.sendMessage({ action, data });
|
||||
if (res.code) {
|
||||
console.error(res);
|
||||
return Promise.reject(res.message);
|
||||
} else {
|
||||
return Promise.resolve(res.data);
|
||||
}
|
||||
}
|
||||
|
||||
export function connect(msg: Message, action: string, data?: any): Promise<MessageConnect> {
|
||||
|
@ -43,7 +43,13 @@ export class OffscreenManager {
|
||||
this.windowApi.on("logger", this.logger.bind(this));
|
||||
this.windowApi.on("preparationSandbox", this.preparationSandbox.bind(this));
|
||||
this.windowApi.on("sendMessageToServiceWorker", this.sendMessageToServiceWorker.bind(this));
|
||||
const script = new ScriptService(group.group("script"), this.mq, this.windowMessage, this.broker);
|
||||
const script = new ScriptService(
|
||||
group.group("script"),
|
||||
this.mq,
|
||||
this.extensionMessage,
|
||||
this.windowMessage,
|
||||
this.broker
|
||||
);
|
||||
script.init();
|
||||
// 转发gm api请求
|
||||
forwardMessage("serviceWorker/runtime/gmApi", this.windowApi, this.extensionMessage);
|
||||
|
@ -1,7 +1,7 @@
|
||||
import LoggerCore from "@App/app/logger/core";
|
||||
import Logger from "@App/app/logger/logger";
|
||||
import { Broker, MessageQueue } from "@Packages/message/message_queue";
|
||||
import { Group } from "@Packages/message/server";
|
||||
import { Group, Message } from "@Packages/message/server";
|
||||
import { WindowMessage } from "@Packages/message/window_message";
|
||||
import {
|
||||
ResourceClient,
|
||||
@ -16,13 +16,14 @@ import { disableScript, enableScript } from "../sandbox/client";
|
||||
export class ScriptService {
|
||||
logger: Logger;
|
||||
|
||||
scriptClient: ScriptClient = new ScriptClient();
|
||||
resourceClient: ResourceClient = new ResourceClient();
|
||||
valueClient: ValueClient = new ValueClient();
|
||||
scriptClient: ScriptClient = new ScriptClient(this.extensionMessage);
|
||||
resourceClient: ResourceClient = new ResourceClient(this.extensionMessage);
|
||||
valueClient: ValueClient = new ValueClient(this.extensionMessage);
|
||||
|
||||
constructor(
|
||||
private group: Group,
|
||||
private mq: MessageQueue,
|
||||
private extensionMessage: Message,
|
||||
private windowMessage: WindowMessage,
|
||||
private broker: Broker
|
||||
) {
|
||||
@ -31,20 +32,21 @@ export class ScriptService {
|
||||
|
||||
async init() {
|
||||
subscribeScriptEnable(this.broker, async (data) => {
|
||||
const info = await this.scriptClient.info(data.uuid);
|
||||
if (info.type === SCRIPT_TYPE_NORMAL) {
|
||||
const script = await this.scriptClient.info(data.uuid);
|
||||
if (script.type === SCRIPT_TYPE_NORMAL) {
|
||||
return;
|
||||
}
|
||||
if (data.enable) {
|
||||
// 构造脚本运行资源,发送给沙盒运行
|
||||
enableScript(this.windowMessage, await this.scriptClient.getScriptRunResource(info));
|
||||
enableScript(this.windowMessage, await this.scriptClient.getScriptRunResource(script));
|
||||
} else {
|
||||
// 发送给沙盒停止
|
||||
disableScript(this.windowMessage, info.uuid);
|
||||
disableScript(this.windowMessage, script.uuid);
|
||||
}
|
||||
});
|
||||
subscribeScriptInstall(this.broker, async (data) => {
|
||||
// 判断是开启还是关闭
|
||||
console.log("1dd23", data);
|
||||
if (data.script.status === SCRIPT_STATUS_ENABLE) {
|
||||
// 构造脚本运行资源,发送给沙盒运行
|
||||
enableScript(this.windowMessage, await this.scriptClient.getScriptRunResource(data.script));
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { Script } from "@App/app/repo/scripts";
|
||||
|
||||
export function storageKey(script: Script): string {
|
||||
if (script.metadata.storagename) {
|
||||
if (script.metadata && script.metadata.storagename) {
|
||||
return script.metadata.storagename[0];
|
||||
}
|
||||
return script.uuid;
|
||||
|
Loading…
x
Reference in New Issue
Block a user