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
This commit is contained in:
1 parent
b7096a77db
commit
4f7dc6fb36
2 files changed
+17
-2
No files matched your search
@@ -14,7 +14,7 @@ const activeSubscriptions = new Map<string, StreamingResponseHandler>()
|
||||
*/
|
||||
export async function subscribeToAccountButtonClicked(
|
||||
controller: Controller,
|
||||
request: EmptyRequest,
|
||||
_request: EmptyRequest,
|
||||
responseStream: StreamingResponseHandler,
|
||||
requestId?: string,
|
||||
): Promise<void> {
|
||||
|
||||
@@ -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<unknown> | 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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user