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