mirror of
https://github.com/cline/cline.git
synced 2026-09-24 23:20:16 +08:00
migrate accountButtonClicked (#4008)
Co-authored-by: Elephant Lumps <celestial_vault@Elephants-MacBook-Pro.local>
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
import { Controller } from "../index"
|
||||
import { Empty, EmptyRequest } from "@shared/proto/common"
|
||||
import { StreamingResponseHandler, getRequestRegistry } from "../grpc-handler"
|
||||
|
||||
// Track subscriptions by controller ID
|
||||
const activeSubscriptions = new Map<string, StreamingResponseHandler>()
|
||||
|
||||
/**
|
||||
* Subscribe to account button clicked events
|
||||
* @param controller The controller instance
|
||||
* @param request The empty request
|
||||
* @param responseStream The streaming response handler
|
||||
* @param requestId The request ID for cleanup
|
||||
*/
|
||||
export async function subscribeToAccountButtonClicked(
|
||||
controller: Controller,
|
||||
request: EmptyRequest,
|
||||
responseStream: StreamingResponseHandler,
|
||||
requestId?: string,
|
||||
): Promise<void> {
|
||||
const controllerId = controller.id
|
||||
|
||||
// Store subscription with controller ID
|
||||
activeSubscriptions.set(controllerId, responseStream)
|
||||
|
||||
// Register cleanup
|
||||
const cleanup = () => {
|
||||
activeSubscriptions.delete(controllerId)
|
||||
}
|
||||
|
||||
if (requestId) {
|
||||
getRequestRegistry().registerRequest(requestId, cleanup, { type: "account_button_subscription" }, responseStream)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Send account button clicked event to a specific controller
|
||||
* @param controllerId The ID of the controller to send the event to
|
||||
*/
|
||||
export async function sendAccountButtonClickedEvent(controllerId: string): Promise<void> {
|
||||
const responseStream = activeSubscriptions.get(controllerId)
|
||||
|
||||
if (!responseStream) {
|
||||
console.log(`No active subscription for controller ${controllerId}`)
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
const event: Empty = {}
|
||||
await responseStream(event, false)
|
||||
} catch (error) {
|
||||
console.error(`Error sending account button clicked event to controller ${controllerId}:`, error)
|
||||
activeSubscriptions.delete(controllerId)
|
||||
}
|
||||
}
|
||||
+15
-12
@@ -20,6 +20,7 @@ import { v4 as uuidv4 } from "uuid"
|
||||
import { WebviewProviderType as WebviewProviderTypeEnum } from "@shared/proto/ui"
|
||||
import { WebviewProviderType } from "./shared/webview/types"
|
||||
import { sendHistoryButtonClickedEvent } from "./core/controller/ui/subscribeToHistoryButtonClicked"
|
||||
import { sendAccountButtonClickedEvent } from "./core/controller/ui/subscribeToAccountButtonClicked"
|
||||
|
||||
/*
|
||||
Built using https://github.com/microsoft/vscode-webview-ui-toolkit
|
||||
@@ -199,20 +200,22 @@ export async function activate(context: vscode.ExtensionContext) {
|
||||
|
||||
context.subscriptions.push(
|
||||
vscode.commands.registerCommand("cline.accountButtonClicked", (webview: any) => {
|
||||
WebviewProvider.getAllInstances().forEach((instance) => {
|
||||
const openAccount = async (instance?: WebviewProvider) => {
|
||||
instance?.controller.postMessageToWebview({
|
||||
type: "action",
|
||||
action: "accountButtonClicked",
|
||||
})
|
||||
console.log("[DEBUG] accountButtonClicked", webview)
|
||||
|
||||
const isSidebar = !webview
|
||||
if (isSidebar) {
|
||||
const sidebarInstance = WebviewProvider.getSidebarInstance()
|
||||
if (sidebarInstance) {
|
||||
// Send event to sidebar controller
|
||||
sendAccountButtonClickedEvent(sidebarInstance.controller.id)
|
||||
}
|
||||
const isSidebar = !webview
|
||||
if (isSidebar) {
|
||||
openAccount(WebviewProvider.getSidebarInstance())
|
||||
} else {
|
||||
WebviewProvider.getTabInstances().forEach(openAccount)
|
||||
} else {
|
||||
// Send to all tab instances
|
||||
const tabInstances = WebviewProvider.getTabInstances()
|
||||
for (const instance of tabInstances) {
|
||||
sendAccountButtonClickedEvent(instance.controller.id)
|
||||
}
|
||||
})
|
||||
}
|
||||
}),
|
||||
)
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ export interface ExtensionMessage {
|
||||
| "fileSearchResults"
|
||||
| "grpc_response" // New type for gRPC responses
|
||||
text?: string
|
||||
action?: "settingsButtonClicked" | "didBecomeVisible" | "accountLogoutClicked" | "accountButtonClicked" | "focusChatInput"
|
||||
action?: "settingsButtonClicked" | "didBecomeVisible" | "accountLogoutClicked" | "focusChatInput"
|
||||
state?: ExtensionState
|
||||
images?: string[]
|
||||
files?: string[]
|
||||
|
||||
Reference in New Issue
Block a user