fix(desktop): Change Launch Mode menu performs reset entirely in main

Replace the renderer-event approach (which silently failed when the
renderer-side listener wasn't yet registered) with an onChangeLaunchMode
callback wired through AppMenuOptions. The callback runs
resetLaunchModeAndReload in main: writes shell settings to clear the
chosen mode, stops the embedded runtime, then navigates the window
directly to the renderer entrypoint with no cached query params so the
launch gate re-prompts.

Also surface the same flow from the dashboard's BackendConnectionErrorPage:
when running inside the desktop shell, the "Can't reach the Fusion backend"
page now offers a "Change Launch Mode…" button alongside Retry, so a user
who chose a broken backend isn't stuck without the Electron menubar.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
gsxdsm
2026-05-17 22:58:34 -07:00
parent 02ba659dd8
commit 10d5afdb8e
3 changed files with 75 additions and 6 deletions

View File

@@ -7,12 +7,31 @@ interface BackendConnectionErrorPageProps {
onManageConnection?: () => void;
}
function isDesktopShell(): boolean {
if (typeof window === "undefined") return false;
return typeof window.fusionShell?.resetDesktopMode === "function";
}
async function changeLaunchMode(): Promise<void> {
const shell = typeof window !== "undefined" ? window.fusionShell : undefined;
try {
await shell?.resetDesktopMode?.();
} catch {
// Best-effort; still strip query params and reload.
}
const url = new URL(window.location.href);
url.searchParams.delete("serverBaseUrl");
url.searchParams.delete("shellMode");
window.location.replace(url.toString());
}
export function BackendConnectionErrorPage({
errorMessage,
isRetrying,
onRetry,
onManageConnection,
}: BackendConnectionErrorPageProps) {
const showChangeLaunchMode = isDesktopShell();
return (
<div className="project-overview-empty" role="alert" aria-live="polite">
<h2>Can&apos;t reach the Fusion backend</h2>
@@ -24,6 +43,11 @@ export function BackendConnectionErrorPage({
<button type="button" className="btn btn-primary" onClick={onRetry} disabled={isRetrying}>
{isRetrying ? "Retrying…" : "Retry Connection"}
</button>
{showChangeLaunchMode && (
<button type="button" className="btn" onClick={() => void changeLaunchMode()}>
Change Launch Mode…
</button>
)}
{onManageConnection && (
<button type="button" className="btn" onClick={onManageConnection}>
Manage Connection