Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion packages/cloud/src/bridge/BridgeOrchestrator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,19 @@ export class BridgeOrchestrator {
public static async connectOrDisconnect(
userInfo: CloudUserInfo | null,
remoteControlEnabled: boolean | undefined,
options: BridgeOrchestratorOptions,
options?: BridgeOrchestratorOptions,
): Promise<void> {
const isEnabled = BridgeOrchestrator.isEnabled(userInfo, remoteControlEnabled)
const instance = BridgeOrchestrator.instance

if (isEnabled) {
if (!instance) {
if (!options) {
console.error(
`[BridgeOrchestrator#connectOrDisconnect] Cannot connect: options are required for connection`,
)
return
}
try {
console.log(`[BridgeOrchestrator#connectOrDisconnect] Connecting...`)
BridgeOrchestrator.instance = new BridgeOrchestrator(options)
Expand Down
27 changes: 24 additions & 3 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ try {
console.warn("Failed to load environment variables:", e)
}

import type { CloudUserInfo } from "@roo-code/types"
import type { CloudUserInfo, AuthState } from "@roo-code/types"
import { CloudService, BridgeOrchestrator } from "@roo-code/cloud"
import { TelemetryService, PostHogTelemetryClient } from "@roo-code/telemetry"

Expand Down Expand Up @@ -53,7 +53,7 @@ let outputChannel: vscode.OutputChannel
let extensionContext: vscode.ExtensionContext
let cloudService: CloudService | undefined

let authStateChangedHandler: (() => void) | undefined
let authStateChangedHandler: ((data: { state: AuthState; previousState: AuthState }) => Promise<void>) | undefined
let settingsUpdatedHandler: (() => void) | undefined
let userInfoHandler: ((data: { userInfo: CloudUserInfo }) => Promise<void>) | undefined

Expand Down Expand Up @@ -127,7 +127,28 @@ export async function activate(context: vscode.ExtensionContext) {

// Initialize Roo Code Cloud service.
const postStateListener = () => ClineProvider.getVisibleInstance()?.postStateToWebview()
authStateChangedHandler = postStateListener

authStateChangedHandler = async (data: { state: AuthState; previousState: AuthState }) => {
postStateListener()

// Check if user has logged out
if (data.state === "logged-out") {
try {
// Disconnect the bridge when user logs out
// When userInfo is null and remoteControlEnabled is false, BridgeOrchestrator
// will disconnect. The options parameter is not needed for disconnection.
await BridgeOrchestrator.connectOrDisconnect(null, false)

cloudLogger("[CloudService] BridgeOrchestrator disconnected on logout")
} catch (error) {
cloudLogger(
`[CloudService] Failed to disconnect BridgeOrchestrator on logout: ${
error instanceof Error ? error.message : String(error)
}`,
)
}
}
}

settingsUpdatedHandler = async () => {
const userInfo = CloudService.instance.getUserInfo()
Expand Down
Loading