From 4f7dc6fb36676af1c818c282b215e8cefbb0e80f Mon Sep 17 00:00:00 2001 From: Sarah Fortune Date: Wed, 4 Jun 2025 17:44:38 -0700 Subject: [PATCH] Add a postMessage handler for standalone cline app (#4038) * Add a postMessage handler for standalone cline app. If there is no vscode api defined, try to use the standalone post Message handler. * Imports * Update logs --- .../ui/subscribeToAccountButtonClicked.ts | 2 +- webview-ui/src/utils/vscode.ts | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/core/controller/ui/subscribeToAccountButtonClicked.ts b/src/core/controller/ui/subscribeToAccountButtonClicked.ts index b980908e..b13c8db4 100644 --- a/src/core/controller/ui/subscribeToAccountButtonClicked.ts +++ b/src/core/controller/ui/subscribeToAccountButtonClicked.ts @@ -14,7 +14,7 @@ const activeSubscriptions = new Map() */ export async function subscribeToAccountButtonClicked( controller: Controller, - request: EmptyRequest, + _request: EmptyRequest, responseStream: StreamingResponseHandler, requestId?: string, ): Promise { diff --git a/webview-ui/src/utils/vscode.ts b/webview-ui/src/utils/vscode.ts index 0f84c918..f4102607 100644 --- a/webview-ui/src/utils/vscode.ts +++ b/webview-ui/src/utils/vscode.ts @@ -10,6 +10,13 @@ import type { WebviewApi } from "vscode-webview" * dev server by using native web browser features that mock the functionality * enabled by acquireVsCodeApi. */ +declare global { + interface Window { + __is_standalone__?: boolean + standalonePostMessage?: (event: any) => void + } +} + class VSCodeAPIWrapper { private readonly vsCodeApi: WebviewApi | undefined @@ -32,8 +39,16 @@ class VSCodeAPIWrapper { public postMessage(message: WebviewMessage) { if (this.vsCodeApi) { this.vsCodeApi.postMessage(message) + } else if (window.__is_standalone__) { + if (!window.standalonePostMessage) { + console.warn("Standalone postMessage not found.") + return + } + const json = JSON.stringify(message) + console.log("Standalone postMessage: " + json.slice(0, 200)) + window.standalonePostMessage(json) } else { - console.log(message) + console.log("postMessage fallback: ", message) } }