feat(desktop-client): give login and main views their own BrowserWindow

Spawn a separate window per mode keyed by a ?window= query param so each surface keeps its size, devtools, and renderer state independently. Logout now persists the cleared session and switches windows before awaiting the runtime release, avoiding a stale main-window flash on the way out.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-30 20:56:03 +08:00
parent cdd63db7f1
commit ed38721feb
7 changed files with 265 additions and 95 deletions
+40 -10
View File
@@ -1,14 +1,23 @@
<script setup lang="ts">
import { defineAsyncComponent, onMounted, watch } from "vue";
import { computed, defineAsyncComponent, onMounted, watch } from "vue";
import { useDesktopSession } from "./composables/useDesktopSession";
const DesktopShell = defineAsyncComponent(() => import("./components/DesktopShell.vue"));
const LoginView = defineAsyncComponent(() => import("./views/LoginView.vue"));
const { isAuthenticated, syncRuntimeSession } = useDesktopSession();
type RendererWindowMode = "auto" | "login" | "main";
interface WindowModeBridge {
setWindowMode?: (mode: "login" | "main") => Promise<unknown>;
setWindowMode?: (
mode: "login" | "main",
request?: { source?: "auth-state" | "login" | "logout"; animate?: boolean },
) => Promise<unknown>;
}
function resolveRendererWindowMode(): RendererWindowMode {
const mode = new URLSearchParams(window.location.search).get("window");
return mode === "login" || mode === "main" ? mode : "auto";
}
function getModeBridge(): WindowModeBridge | undefined {
@@ -18,21 +27,42 @@ function getModeBridge(): WindowModeBridge | undefined {
}
function syncWindowMode(authenticated: boolean): void {
void getModeBridge()?.setWindowMode?.(authenticated ? "main" : "login");
void getModeBridge()?.setWindowMode?.(authenticated ? "main" : "login", { source: "auth-state" });
}
// Fire immediately during setup so the main process can size + reveal the
// window before the user sees any "wrong-sized" frame.
syncWindowMode(isAuthenticated.value);
watch(isAuthenticated, (next) => syncWindowMode(next));
const rendererWindowMode = resolveRendererWindowMode();
const usesAutomaticWindowMode = rendererWindowMode === "auto";
const showsMainSurface = computed(() =>
rendererWindowMode === "main" || (rendererWindowMode === "auto" && isAuthenticated.value),
);
if (usesAutomaticWindowMode) {
syncWindowMode(isAuthenticated.value);
watch(isAuthenticated, (next) => syncWindowMode(next));
}
if (rendererWindowMode === "main") {
if (!isAuthenticated.value) {
syncWindowMode(false);
}
watch(isAuthenticated, (next) => {
if (!next) {
syncWindowMode(false);
}
});
}
onMounted(() => {
void syncRuntimeSession();
syncWindowMode(isAuthenticated.value);
if (rendererWindowMode !== "login") {
void syncRuntimeSession();
}
if (usesAutomaticWindowMode) {
syncWindowMode(isAuthenticated.value);
}
});
</script>
<template>
<DesktopShell v-if="isAuthenticated" />
<DesktopShell v-if="showsMainSurface" />
<LoginView v-else />
</template>