@@ -17,7 +17,7 @@ import { authStore } from "~/store";
1717import { clientEnv } from "~/utils/env" ;
1818import { getCurrentWindow } from "@tauri-apps/api/window" ;
1919import { commands } from "~/utils/tauri" ;
20-
20+ import { Window } from "@tauri-apps/api/window" ;
2121const signInAction = action ( async ( ) => {
2222 let res : ( url : URL ) => void ;
2323
@@ -94,9 +94,27 @@ const signInAction = action(async () => {
9494 } ,
9595 } ) ;
9696
97- const currentWindow = getCurrentWindow ( ) ;
97+ const currentWindow = await Window . getByLabel ( "signin" ) ;
9898 await commands . openMainWindow ( ) ;
99- await currentWindow . close ( ) ;
99+
100+ // Add a small delay to ensure window is ready
101+ await new Promise ( ( resolve ) => setTimeout ( resolve , 500 ) ) ;
102+
103+ const mainWindow = await Window . getByLabel ( "main" ) ;
104+ console . log ( "Main window reference:" , mainWindow ? "found" : "not found" ) ;
105+
106+ if ( mainWindow ) {
107+ try {
108+ await mainWindow . setFocus ( ) ;
109+ console . log ( "Successfully set focus on main window" ) ;
110+ } catch ( e ) {
111+ console . error ( "Failed to focus main window:" , e ) ;
112+ }
113+ }
114+
115+ if ( currentWindow ) {
116+ await currentWindow . close ( ) ;
117+ }
100118
101119 return redirect ( "/" ) ;
102120 } catch ( error ) {
@@ -167,7 +185,30 @@ export default function Page() {
167185 } ,
168186 } ) ;
169187 setIsSignedIn ( true ) ;
170- alert ( "Successfully signed in to Cap!" ) ;
188+ const currentWindow = await Window . getByLabel ( "signin" ) ;
189+ await commands . openMainWindow ( ) ;
190+
191+ // Add a small delay to ensure window is ready
192+ await new Promise ( ( resolve ) => setTimeout ( resolve , 500 ) ) ;
193+
194+ const mainWindow = await Window . getByLabel ( "main" ) ;
195+ console . log (
196+ "Main window reference:" ,
197+ mainWindow ? "found" : "not found"
198+ ) ;
199+
200+ if ( mainWindow ) {
201+ try {
202+ await mainWindow . setFocus ( ) ;
203+ console . log ( "Successfully set focus on main window" ) ;
204+ } catch ( e ) {
205+ console . error ( "Failed to focus main window:" , e ) ;
206+ }
207+ }
208+
209+ if ( currentWindow ) {
210+ await currentWindow . close ( ) ;
211+ }
171212 }
172213 } ) ;
173214
0 commit comments