Skip to content

Commit

Permalink
feat: vscode自动连接
Browse files Browse the repository at this point in the history
  • Loading branch information
CodFrm committed Nov 15, 2021
1 parent 4906c79 commit dac2cc6
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/apps/tools/manager.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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);

Expand Down Expand Up @@ -82,6 +90,7 @@ export class ToolsManager extends Manager {

this.wsc.addEventListener('error', (ev) => {
resolve('ws服务连接失败');
this.wsc = undefined;
});
});
}
Expand Down
8 changes: 8 additions & 0 deletions src/pkg/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
12 changes: 11 additions & 1 deletion src/views/pages/Option/tabs/Tools.vue
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,24 @@ 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,
change(val: ConfigItem) {
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: "连接",
Expand Down

0 comments on commit dac2cc6

Please sign in to comment.