fix: stabilize desktop environment auth navigation

This commit is contained in:
Simos Mikelatos
2026-06-24 20:09:41 +00:00
parent 81eb966904
commit 490e66ebdb
6 changed files with 301 additions and 26 deletions

View File

@@ -195,8 +195,9 @@ export class DesktopWindowManager {
this.actions.setActiveTarget(target);
this.buildAppMenu();
this.mainWindow.setTitle(`${this.appName} - ${target.name}`);
await this.showContentTarget(target);
const finalUrl = await this.showContentTarget(target);
this.emitDesktopState();
return finalUrl;
}
async showLauncher() {

View File

@@ -1,4 +1,4 @@
import { app, BrowserWindow, clipboard, dialog, ipcMain, shell, systemPreferences } from 'electron';
import { app, BrowserWindow, clipboard, dialog, ipcMain, session, shell, systemPreferences } from 'electron';
import { spawn } from 'node:child_process';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
@@ -259,6 +259,28 @@ async function getEnvironmentLaunchTarget(environment) {
};
}
async function hasCloudWebSession() {
const cookies = await session.defaultSession.cookies.get({});
return cookies.some((cookie) => {
const cookieDomain = String(cookie.domain || '');
return cookieDomain.includes('cloudcli.ai')
&& /-auth-token(?:\.\d+)?$/.test(cookie.name)
&& Boolean(cookie.value);
});
}
function isCloudAuthRedirect(url) {
if (!url) return false;
try {
const parsed = new URL(url);
const controlPlane = new URL(CLOUDCLI_CONTROL_PLANE_URL);
return parsed.origin === controlPlane.origin
&& (parsed.pathname === '/login' || parsed.pathname.startsWith('/auth/'));
} catch {
return false;
}
}
function getDiagnosticsText() {
const cloudAccount = cloud.getAccount();
const localState = getLocalState();
@@ -676,8 +698,18 @@ async function openEnvironmentInDesktop(environment) {
nextEnvironment = await cloud.startEnvironmentAndWait(environment, REMOTE_START_TIMEOUT_MS);
}
const target = await getEnvironmentLaunchTarget(nextEnvironment);
await desktopWindow.showTarget(target);
let target = getEnvironmentTarget(nextEnvironment);
if (!(await hasCloudWebSession())) {
target = await getEnvironmentLaunchTarget(nextEnvironment);
}
const usedBootstrap = Boolean(target.loadUrl);
const finalUrl = await desktopWindow.showTarget(target);
if (!usedBootstrap && isCloudAuthRedirect(finalUrl)) {
const bootstrapTarget = await getEnvironmentLaunchTarget(nextEnvironment);
bootstrapTarget.forceLoad = true;
await desktopWindow.showTarget(bootstrapTarget);
}
return getDesktopState();
}

View File

@@ -233,19 +233,21 @@ export class ViewHost {
}
const view = this.getOrCreateTabView(tabId);
this.attach(view);
if (view.__cloudcliLoadedUrl !== target.url) {
if (target.forceLoad || view.__cloudcliLoadedUrl !== target.url) {
view.__cloudcliLoadingUrl = loadUrl;
try {
await loadUrlWithTimeout(view.webContents, loadUrl);
view.__cloudcliLoadedUrl = target.url;
view.__cloudcliStartupHtml = null;
delete target.loadUrl;
delete target.forceLoad;
} finally {
if (view.__cloudcliLoadingUrl === loadUrl) {
view.__cloudcliLoadingUrl = null;
}
}
}
return view.webContents.getURL();
}
reloadTab(tabId) {