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:
12
src/home.ts
12
src/home.ts
@@ -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')) {
|
||||
|
Reference in New Issue
Block a user