-
Notifications
You must be signed in to change notification settings - Fork 329
Expand file tree
/
Copy pathclient.ts
More file actions
52 lines (42 loc) · 1.96 KB
/
client.ts
File metadata and controls
52 lines (42 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import { type WindowMessage } from "@Packages/message/window_message";
import type { SCRIPT_RUN_STATUS, ScriptRunResource } from "@App/app/repo/scripts";
import { Client, sendMessage } from "@Packages/message/client";
import type { MessageSend } from "@Packages/message/types";
import { type VSCodeConnectParam } from "./vscode-connect";
export function preparationSandbox(windowMessage: WindowMessage) {
return sendMessage(windowMessage, "offscreen/preparationSandbox");
}
export function getExtensionEnv(windowMessage: WindowMessage) {
return sendMessage(windowMessage, "offscreen/getExtensionEnv", { requireUAD: true });
}
// 代理发送消息到ServiceWorker
export function sendMessageToServiceWorker(windowMessage: WindowMessage, action: string, data?: any) {
return sendMessage(windowMessage, "offscreen/sendMessageToServiceWorker", { action, data });
}
// 代理连接ServiceWorker
export function connectServiceWorker(windowMessage: WindowMessage) {
return sendMessage(windowMessage, "offscreen/connectServiceWorker");
}
export function proxyUpdateRunStatus(
windowMessage: WindowMessage,
data: { uuid: string; runStatus: SCRIPT_RUN_STATUS; error?: any; nextruntime?: number }
) {
return sendMessageToServiceWorker(windowMessage, "script/updateRunStatus", data);
}
export function runScript(msgSender: MessageSend, data: ScriptRunResource) {
return sendMessage(msgSender, "offscreen/script/runScript", data);
}
export function stopScript(msgSender: MessageSend, uuid: string) {
return sendMessage(msgSender, "offscreen/script/stopScript", uuid);
}
export function createObjectURL(msgSender: MessageSend, params: { blob: Blob; persistence: boolean }) {
return sendMessage(msgSender, "offscreen/createObjectURL", params);
}
export class VscodeConnectClient extends Client {
constructor(msgSender: MessageSend) {
super(msgSender, "offscreen/vscodeConnect");
}
connect(params: VSCodeConnectParam): Promise<void> {
return this.do("connect", params);
}
}