Skip to content

Commit

Permalink
feat: Open main window/bring to focus after auth
Browse files Browse the repository at this point in the history
  • Loading branch information
richiemcilroy committed Jan 19, 2025
1 parent b74a96b commit 4b72314
Showing 1 changed file with 45 additions and 4 deletions.
49 changes: 45 additions & 4 deletions apps/desktop/src/routes/(window-chrome)/signin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { authStore } from "~/store";
import { clientEnv } from "~/utils/env";
import { getCurrentWindow } from "@tauri-apps/api/window";
import { commands } from "~/utils/tauri";

import { Window } from "@tauri-apps/api/window";
const signInAction = action(async () => {
let res: (url: URL) => void;

Expand Down Expand Up @@ -94,9 +94,27 @@ const signInAction = action(async () => {
},
});

const currentWindow = getCurrentWindow();
const currentWindow = await Window.getByLabel("signin");
await commands.openMainWindow();
await currentWindow.close();

// Add a small delay to ensure window is ready
await new Promise((resolve) => setTimeout(resolve, 500));

const mainWindow = await Window.getByLabel("main");
console.log("Main window reference:", mainWindow ? "found" : "not found");

if (mainWindow) {
try {
await mainWindow.setFocus();
console.log("Successfully set focus on main window");
} catch (e) {
console.error("Failed to focus main window:", e);
}
}

if (currentWindow) {
await currentWindow.close();
}

return redirect("/");
} catch (error) {
Expand Down Expand Up @@ -167,7 +185,30 @@ export default function Page() {
},
});
setIsSignedIn(true);
alert("Successfully signed in to Cap!");
const currentWindow = await Window.getByLabel("signin");
await commands.openMainWindow();

// Add a small delay to ensure window is ready
await new Promise((resolve) => setTimeout(resolve, 500));

const mainWindow = await Window.getByLabel("main");
console.log(
"Main window reference:",
mainWindow ? "found" : "not found"
);

if (mainWindow) {
try {
await mainWindow.setFocus();
console.log("Successfully set focus on main window");
} catch (e) {
console.error("Failed to focus main window:", e);
}
}

if (currentWindow) {
await currentWindow.close();
}
}
});

Expand Down

1 comment on commit 4b72314

@vercel
Copy link

@vercel vercel bot commented on 4b72314 Jan 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.