|
12 | 12 | console.warn("Failed to load environment variables:", e) |
13 | 13 | } |
14 | 14 |
|
15 | | -import type { CloudUserInfo } from "@roo-code/types" |
| 15 | +import type { CloudUserInfo, AuthState } from "@roo-code/types" |
16 | 16 | import { CloudService, BridgeOrchestrator } from "@roo-code/cloud" |
17 | 17 | import { TelemetryService, PostHogTelemetryClient } from "@roo-code/telemetry" |
18 | 18 |
|
@@ -53,7 +53,7 @@ let outputChannel: vscode.OutputChannel |
53 | 53 | let extensionContext: vscode.ExtensionContext |
54 | 54 | let cloudService: CloudService | undefined |
55 | 55 |
|
56 | | -let authStateChangedHandler: (() => void) | undefined |
| 56 | +let authStateChangedHandler: ((data: { state: AuthState; previousState: AuthState }) => Promise<void>) | undefined |
57 | 57 | let settingsUpdatedHandler: (() => void) | undefined |
58 | 58 | let userInfoHandler: ((data: { userInfo: CloudUserInfo }) => Promise<void>) | undefined |
59 | 59 |
|
@@ -127,7 +127,28 @@ export async function activate(context: vscode.ExtensionContext) { |
127 | 127 |
|
128 | 128 | // Initialize Roo Code Cloud service. |
129 | 129 | const postStateListener = () => ClineProvider.getVisibleInstance()?.postStateToWebview() |
130 | | - authStateChangedHandler = postStateListener |
| 130 | + |
| 131 | + authStateChangedHandler = async (data: { state: AuthState; previousState: AuthState }) => { |
| 132 | + postStateListener() |
| 133 | + |
| 134 | + // Check if user has logged out |
| 135 | + if (data.state === "logged-out") { |
| 136 | + try { |
| 137 | + // Disconnect the bridge when user logs out |
| 138 | + // When userInfo is null and remoteControlEnabled is false, BridgeOrchestrator |
| 139 | + // will disconnect. The options parameter is not needed for disconnection. |
| 140 | + await BridgeOrchestrator.connectOrDisconnect(null, false) |
| 141 | + |
| 142 | + cloudLogger("[CloudService] BridgeOrchestrator disconnected on logout") |
| 143 | + } catch (error) { |
| 144 | + cloudLogger( |
| 145 | + `[CloudService] Failed to disconnect BridgeOrchestrator on logout: ${ |
| 146 | + error instanceof Error ? error.message : String(error) |
| 147 | + }`, |
| 148 | + ) |
| 149 | + } |
| 150 | + } |
| 151 | + } |
131 | 152 |
|
132 | 153 | settingsUpdatedHandler = async () => { |
133 | 154 | const userInfo = CloudService.instance.getUserInfo() |
|
0 commit comments