diff --git a/src/apps/tools/manager.ts b/src/apps/tools/manager.ts index 96be124b..b076c6bf 100644 --- a/src/apps/tools/manager.ts +++ b/src/apps/tools/manager.ts @@ -1,4 +1,5 @@ import { Manager } from "@App/pkg/apps/manager"; +import { SystemConfig } from "@App/pkg/config"; import { ExternalWhitelist } from "../config"; import { ExternalMessage, ToolsConnectVSCode, ToolsDisconnecttVSCode } from "../msg-center/event"; import { ScriptController } from "../script/controller"; @@ -17,6 +18,13 @@ export class ToolsManager extends Manager { } public listenEvent() { + // 每30秒检测一次自动连接vscode + setInterval(() => { + if (SystemConfig.vscode_reconnect && !this.wsc) { + this.connectVSCode(SystemConfig.vscode_url); + } + }, 3e4); + this.listenerMessage(ToolsConnectVSCode, this.connectVSCode); this.listenerMessage(ToolsDisconnecttVSCode, this.connectVSCode); @@ -82,6 +90,7 @@ export class ToolsManager extends Manager { this.wsc.addEventListener('error', (ev) => { resolve('ws服务连接失败'); + this.wsc = undefined; }); }); } diff --git a/src/pkg/config.ts b/src/pkg/config.ts index b616e379..e5f6ffb8 100644 --- a/src/pkg/config.ts +++ b/src/pkg/config.ts @@ -85,6 +85,14 @@ export class SystemConfig { public static set vscode_url(val: string) { this.set("vscode_url", val); } + + public static get vscode_reconnect(): boolean { + return this.cache.get("vscode_reconnect") || false; + } + + public static set vscode_reconnect(val: boolean) { + this.set("vscode_reconnect", val); + } } SystemConfig.storage = new ChromeStorage("system"); diff --git a/src/views/pages/Option/tabs/Tools.vue b/src/views/pages/Option/tabs/Tools.vue index 5af39285..825f1b5c 100644 --- a/src/views/pages/Option/tabs/Tools.vue +++ b/src/views/pages/Option/tabs/Tools.vue @@ -60,7 +60,8 @@ export default class Tools extends Vue { { type: "text", title: "VSCode地址", - describe: "连接地址,默认一般为: ws://localhost:8642,需要在vscode扩展商店中安装'scriptcat-vscode'配合食用", + describe: + "连接地址,默认一般为: ws://localhost:8642,需要在vscode扩展商店中安装'scriptcat-vscode'配合食用", value: SystemConfig.vscode_url, loading: false, disabled: false, @@ -68,6 +69,15 @@ export default class Tools extends Vue { SystemConfig.vscode_url = val.value; }, }, + { + type: "check", + title: "自动连接vscode服务", + describe: "启动时自动连接到vscode扩展服务,断开连接后也会自动重连", + value: SystemConfig.vscode_reconnect, + change(val: any) { + SystemConfig.vscode_reconnect = val.value; + }, + }, { type: "button", title: "连接",