diff --git a/src/core/webview/index.ts b/src/core/webview/index.ts index 5f115fffff..6ad3e62b99 100644 --- a/src/core/webview/index.ts +++ b/src/core/webview/index.ts @@ -44,6 +44,10 @@ export class WebviewProvider implements vscode.WebviewViewProvider { return findLast(Array.from(this.activeInstances), (instance) => instance.view?.visible === true) } + public static getAllInstances(): WebviewProvider[] { + return Array.from(this.activeInstances) + } + async resolveWebviewView(webviewView: vscode.WebviewView | vscode.WebviewPanel) { this.view = webviewView diff --git a/src/extension.ts b/src/extension.ts index 42300ca30a..2123ce3242 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -42,33 +42,24 @@ export function activate(context: vscode.ExtensionContext) { context.subscriptions.push( vscode.commands.registerCommand("cline.plusButtonClicked", async () => { - Logger.log("Plus button Clicked") - const visibleWebview = WebviewProvider.getVisibleInstance() - if (!visibleWebview) { - Logger.log("Cannot find any visible Cline instances.") - return - } - - await visibleWebview.controller.clearTask() - await visibleWebview.controller.postStateToWebview() - await visibleWebview.controller.postMessageToWebview({ - type: "action", - action: "chatButtonClicked", + WebviewProvider.getAllInstances().forEach(async (instance) => { + await instance.controller.clearTask() + await instance.controller.postStateToWebview() + await instance.controller.postMessageToWebview({ + type: "action", + action: "chatButtonClicked", + }) }) }), ) context.subscriptions.push( vscode.commands.registerCommand("cline.mcpButtonClicked", () => { - const visibleWebview = WebviewProvider.getVisibleInstance() - if (!visibleWebview) { - Logger.log("Cannot find any visible Cline instances.") - return - } - - visibleWebview.controller.postMessageToWebview({ - type: "action", - action: "mcpButtonClicked", + WebviewProvider.getAllInstances().forEach((instance) => { + instance.controller.postMessageToWebview({ + type: "action", + action: "mcpButtonClicked", + }) }) }), ) @@ -111,46 +102,33 @@ export function activate(context: vscode.ExtensionContext) { context.subscriptions.push( vscode.commands.registerCommand("cline.settingsButtonClicked", () => { - //vscode.window.showInformationMessage(message) - const visibleWebview = WebviewProvider.getVisibleInstance() - if (!visibleWebview) { - Logger.log("Cannot find any visible Cline instances.") - return - } - - visibleWebview.controller.postMessageToWebview({ - type: "action", - action: "settingsButtonClicked", + WebviewProvider.getAllInstances().forEach((instance) => { + instance.controller.postMessageToWebview({ + type: "action", + action: "settingsButtonClicked", + }) }) }), ) context.subscriptions.push( vscode.commands.registerCommand("cline.historyButtonClicked", () => { - const visibleWebview = WebviewProvider.getVisibleInstance() - if (!visibleWebview) { - Logger.log("Cannot find any visible Cline instances.") - return - } - - visibleWebview.controller.postMessageToWebview({ - type: "action", - action: "historyButtonClicked", + WebviewProvider.getAllInstances().forEach((instance) => { + instance.controller.postMessageToWebview({ + type: "action", + action: "historyButtonClicked", + }) }) }), ) context.subscriptions.push( vscode.commands.registerCommand("cline.accountButtonClicked", () => { - const visibleWebview = WebviewProvider.getVisibleInstance() - if (!visibleWebview) { - Logger.log("Cannot find any visible Cline instances.") - return - } - - visibleWebview.controller.postMessageToWebview({ - type: "action", - action: "accountButtonClicked", + WebviewProvider.getAllInstances().forEach((instance) => { + instance.controller.postMessageToWebview({ + type: "action", + action: "accountButtonClicked", + }) }) }), )