From 5dbc44a6ca4ffcf68280f5b236929111df310ad4 Mon Sep 17 00:00:00 2001 From: haritabh-z01 Date: Tue, 2 Dec 2025 21:15:55 +0530 Subject: [PATCH] chore: auto focus windows post auth --- apps/desktop/src/main/core/app-manager.ts | 14 +++++++- .../components/screens/ModelSetupModal.tsx | 33 +++++++++++-------- 2 files changed, 33 insertions(+), 14 deletions(-) diff --git a/apps/desktop/src/main/core/app-manager.ts b/apps/desktop/src/main/core/app-manager.ts index dd76fc6..50da1e5 100644 --- a/apps/desktop/src/main/core/app-manager.ts +++ b/apps/desktop/src/main/core/app-manager.ts @@ -46,7 +46,19 @@ export class AppManager { } } - // Add other deep link handlers here in the future + // Auto-focus the appropriate window after handling deep link + const onboardingWindow = this.windowManager.getOnboardingWindow(); + if (onboardingWindow && !onboardingWindow.isDestroyed()) { + onboardingWindow.show(); + onboardingWindow.focus(); + } else { + // Create or show main window + this.windowManager.createOrShowMainWindow(); + const mainWindow = this.windowManager.getMainWindow(); + if (mainWindow && !mainWindow.isDestroyed()) { + mainWindow.focus(); + } + } } catch (error) { logger.main.error("Error handling deep link:", error); } diff --git a/apps/desktop/src/renderer/onboarding/components/screens/ModelSetupModal.tsx b/apps/desktop/src/renderer/onboarding/components/screens/ModelSetupModal.tsx index ba93cfd..21dfe2e 100644 --- a/apps/desktop/src/renderer/onboarding/components/screens/ModelSetupModal.tsx +++ b/apps/desktop/src/renderer/onboarding/components/screens/ModelSetupModal.tsx @@ -44,28 +44,35 @@ export function ModelSetupModal({ const [installedModelName, setInstalledModelName] = useState(""); const [downloadComplete, setDownloadComplete] = useState(false); - // tRPC mutations and utils - const utils = api.useUtils(); + // tRPC mutations const loginMutation = api.auth.login.useMutation({ - onSuccess: async () => { - // After login, check auth status - const authStatus = await utils.auth.getAuthStatus.fetch(); - if (authStatus.isAuthenticated) { - toast.success("Successfully authenticated!"); - onContinue(); - } else { - setError("Authentication failed. Please try again."); - } - setIsLoading(false); + onSuccess: () => { + // Browser opened, waiting for OAuth completion via subscription + toast.info("Complete login in your browser"); }, onError: (err) => { console.error("OAuth error:", err); - setError("Failed to authenticate. Please try again."); + setError("Failed to open login. Please try again."); setIsLoading(false); }, }); const downloadModelMutation = api.models.downloadModel.useMutation(); + // Subscribe to auth state changes for Cloud model OAuth completion + api.auth.onAuthStateChange.useSubscription(undefined, { + onData: (authState) => { + if (authState.isAuthenticated && isLoading) { + toast.success("Successfully authenticated!"); + setIsLoading(false); + onContinue(); + } + }, + onError: (error) => { + console.error("Auth state subscription error:", error); + }, + enabled: modelType === ModelType.Cloud && isOpen, + }); + // Check for existing downloaded models const { data: downloadedModels } = api.models.getDownloadedModels.useQuery( undefined,