feat: add communication method without return value that communicate with devstar-home
This commit is contained in:
10
src/home.ts
10
src/home.ts
@@ -40,6 +40,11 @@ export default class DSHome {
|
||||
panel.webview.onDidReceiveMessage(
|
||||
async (message) => {
|
||||
const data = message.data
|
||||
const need_return = message.need_return
|
||||
if (!need_return) {
|
||||
// ================= don't need return ==============
|
||||
} else {
|
||||
// ================= need return ====================
|
||||
switch (message.command) {
|
||||
// ----------------- frequent -----------------------
|
||||
case 'getUserToken':
|
||||
@@ -129,6 +134,7 @@ export default class DSHome {
|
||||
}
|
||||
panel.webview.postMessage({ command: 'getDefaultPublicKey', data: { defaultPublicKey: defaultPublicKey } })
|
||||
}
|
||||
}
|
||||
},
|
||||
undefined,
|
||||
this.context.subscriptions
|
||||
@@ -183,7 +189,7 @@ export default class DSHome {
|
||||
async function communicateVSCode(command, data) {
|
||||
return new Promise((resolve, reject) => {
|
||||
// request to vscode
|
||||
vscode.postMessage({ command: command, data: data })
|
||||
vscode.postMessage({ command: command, need_return: true, data: data })
|
||||
|
||||
function handleResponse(event) {
|
||||
const jsonData = event.data;
|
||||
@@ -223,6 +229,8 @@ export default class DSHome {
|
||||
if (iframe && iframe.contentWindow) {
|
||||
iframe.contentWindow.postMessage({ action: actionFromHome, data: dataFromVSCodeResponse }, '*')
|
||||
}
|
||||
} else if (jsonData.target === 'vscode_no_return') {
|
||||
vscode.postMessage({ command: jsonData.action, need_return: false, data: jsonData.data })
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error parsing message:', error);
|
||||
|
Reference in New Issue
Block a user