feat: add communication method without return value that communicate with devstar-home

This commit is contained in:
Levi Yan
2025-01-15 15:13:26 +08:00
parent 5e0848715b
commit 4f831a0d5b

View File

@@ -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);