refactor: abstract and simplify the communication between home page and vscode

* refactor the infertace in index.html
* adapt the change of interface in home page and vscode
This commit is contained in:
Levi Yan
2024-10-23 01:58:10 +08:00
parent 5672003901
commit 08168dfd3f
3 changed files with 49 additions and 63 deletions

View File

@@ -29,20 +29,22 @@ export default class DSHome {
panel.webview.onDidReceiveMessage(
async (message) => {
const data = message.data
switch (message.command) {
case 'firstOpenRemoteFolder':
await this.remoteContainer.firstConnect(message.host, message.username, message.port)
const path = data.path
await this.remoteContainer.firstConnect(data.host, data.username, data.port)
.then((_res) => {
if (_res == 'success') {
// only success then open folder
this.remoteContainer.openRemoteFolder(message.host, message.path);
this.remoteContainer.openRemoteFolder(data.host, path);
}
}).catch(error => {
console.error(`Failed to connect ${message.host}: `, error)
console.error(`Failed to connect ${data.host}: `, error)
})
break;
case 'openRemoteFolder':
this.remoteContainer.openRemoteFolder(message.host, message.path);
this.remoteContainer.openRemoteFolder(data.host, data.path);
break;
case 'getUserToken':
const userToken = this.context.globalState.get('devstarUserToken')
@@ -54,7 +56,7 @@ export default class DSHome {
break;
}
case 'setUserToken':
this.context.globalState.update('devstarUserToken', message.data.userToken)
this.context.globalState.update('devstarUserToken', data.userToken)
console.log(this.context.globalState.get('devstarUserToken'))
console.log(message.data.userToken)
if (message.data.userToken === this.context.globalState.get('devstarUserToken')) {