-
Notifications
You must be signed in to change notification settings - Fork 145
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
200 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
export const ExtVersion = "0.6.4"; | ||
export const ExtVersion = "0.7.0"; | ||
|
||
export const Server = process.env.NODE_ENV == "production" ? "https://sc.icodef.com/" : "http://localhost:8080/"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { ToolsConnectVSCode, ToolsDisconnecttVSCode } from "../msg-center/event"; | ||
import { MsgCenter } from "../msg-center/msg-center"; | ||
|
||
export class ToolsController { | ||
|
||
public connectVScode(url: string) { | ||
return new Promise(resolve => { | ||
MsgCenter.sendMessage(ToolsConnectVSCode, url, resp => { | ||
resolve(resp); | ||
}); | ||
}); | ||
} | ||
|
||
public disconnectVScode(url: string) { | ||
return new Promise(resolve => { | ||
MsgCenter.sendMessage(ToolsDisconnecttVSCode, undefined, resp => { | ||
resolve(resp); | ||
}); | ||
}); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import { Manager } from "@App/pkg/apps/manager"; | ||
import { ToolsConnectVSCode, ToolsDisconnecttVSCode } from "../msg-center/event"; | ||
import { ScriptController } from "../script/controller"; | ||
import { ScriptManager } from "../script/manager"; | ||
|
||
|
||
export class ToolsManager extends Manager { | ||
|
||
protected scriptManager: ScriptManager; | ||
protected scriptController: ScriptController = new ScriptController(); | ||
|
||
protected wsc?: WebSocket; | ||
|
||
constructor(scriptManager: ScriptManager) { | ||
super(); | ||
this.scriptManager = scriptManager; | ||
} | ||
|
||
public listenEvent() { | ||
this.listenerMessage(ToolsConnectVSCode, this.connectVSCode); | ||
this.listenerMessage(ToolsDisconnecttVSCode, this.connectVSCode); | ||
} | ||
|
||
public connectVSCode(url: string) { | ||
return new Promise(resolve => { | ||
// 与vsc扩展建立连接 | ||
if (this.wsc) { | ||
this.wsc.close(); | ||
} | ||
try { | ||
this.wsc = new WebSocket(url); | ||
} catch (e: any) { | ||
return resolve(e.message); | ||
} | ||
this.wsc.addEventListener('open', (ev) => { | ||
this.wsc!.send('Hello Server!'); | ||
resolve(true); | ||
}); | ||
|
||
// Listen for messages | ||
this.wsc.addEventListener('message', async (ev) => { | ||
let data = JSON.parse(ev.data); | ||
switch (data.action) { | ||
case 'onchange': { | ||
let code = data.data.script; | ||
let [newScript, oldScript] = await this.scriptController.prepareScriptByCode(code, ""); | ||
if (typeof oldScript === "string") { | ||
return; | ||
} | ||
if (oldScript) { | ||
this.scriptManager.scriptReinstall(newScript!); | ||
} else { | ||
this.scriptManager.scriptInstall(newScript!); | ||
} | ||
break; | ||
} | ||
} | ||
}); | ||
|
||
this.wsc.addEventListener('error', (ev) => { | ||
resolve('ws服务连接失败'); | ||
}); | ||
}); | ||
} | ||
|
||
public disconnectVSCode() { | ||
return new Promise(resolve => { | ||
if (this.wsc) { | ||
this.wsc.close(); | ||
this.wsc = undefined; | ||
} | ||
resolve(true); | ||
}); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { MessageCallback, MsgCenter } from "@App/apps/msg-center/msg-center"; | ||
|
||
export class Manager { | ||
|
||
public listenerMessage(topic: string, callback: MessageCallback) { | ||
MsgCenter.listenerMessage(topic, async (body, send, sender) => { | ||
let ret = <any>callback.call(this, body, send, sender) | ||
if (ret instanceof Promise) { | ||
ret = await ret; | ||
} | ||
send(ret); | ||
}); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters