fix: Electron desktop not logging in

This commit is contained in:
LukeGus
2025-11-01 16:30:28 -05:00
parent 00e19f054f
commit dd19b2b990
2 changed files with 64 additions and 39 deletions

View File

@@ -93,6 +93,11 @@ export function ElectronLoginForm({
try { try {
const injectedScript = ` const injectedScript = `
(function() { (function() {
window.IS_ELECTRON = true;
if (typeof window.electronAPI === 'undefined') {
window.electronAPI = { isElectron: true };
}
let hasNotified = false; let hasNotified = false;
function postJWTToParent(token, source) { function postJWTToParent(token, source) {

View File

@@ -91,7 +91,7 @@ interface OIDCAuthorize {
// ============================================================================ // ============================================================================
export function isElectron(): boolean { export function isElectron(): boolean {
return ( const hasISElectron =
( (
window as Window & window as Window &
typeof globalThis & { typeof globalThis & {
@@ -99,16 +99,20 @@ export function isElectron(): boolean {
electronAPI?: unknown; electronAPI?: unknown;
configuredServerUrl?: string; configuredServerUrl?: string;
} }
).IS_ELECTRON === true || ).IS_ELECTRON === true;
(
const hasElectronAPI = !!(
window as Window & window as Window &
typeof globalThis & { typeof globalThis & {
IS_ELECTRON?: boolean; IS_ELECTRON?: boolean;
electronAPI?: unknown; electronAPI?: unknown;
configuredServerUrl?: string; configuredServerUrl?: string;
} }
).electronAPI?.isElectron === true ).electronAPI;
);
const result = hasISElectron || hasElectronAPI;
return result;
} }
function getLoggerForService(serviceName: string) { function getLoggerForService(serviceName: string) {
@@ -477,15 +481,21 @@ export async function checkElectronUpdate(): Promise<{
} }
function getApiUrl(path: string, defaultPort: number): string { function getApiUrl(path: string, defaultPort: number): string {
if (isDev()) { const devMode = isDev();
const electronMode = isElectron();
if (devMode) {
const protocol = window.location.protocol === "https:" ? "https" : "http"; const protocol = window.location.protocol === "https:" ? "https" : "http";
const sslPort = protocol === "https" ? 8443 : defaultPort; const sslPort = protocol === "https" ? 8443 : defaultPort;
return `${protocol}://${apiHost}:${sslPort}${path}`; const url = `${protocol}://${apiHost}:${sslPort}${path}`;
} else if (isElectron()) { return url;
} else if (electronMode) {
if (configuredServerUrl) { if (configuredServerUrl) {
const baseUrl = configuredServerUrl.replace(/\/$/, ""); const baseUrl = configuredServerUrl.replace(/\/$/, "");
return `${baseUrl}${path}`; const url = `${baseUrl}${path}`;
return url;
} }
console.warn("Electron mode but no server configured!");
return "http://no-server-configured"; return "http://no-server-configured";
} else { } else {
return path; return path;
@@ -533,7 +543,8 @@ export let authApi: AxiosInstance;
// Homepage API (port 30006) // Homepage API (port 30006)
export let homepageApi: AxiosInstance; export let homepageApi: AxiosInstance;
if (isElectron()) { function initializeApp() {
if (isElectron()) {
getServerConfig() getServerConfig()
.then((config) => { .then((config) => {
if (config?.serverUrl) { if (config?.serverUrl) {
@@ -546,6 +557,8 @@ if (isElectron()) {
configuredServerUrl?: string; configuredServerUrl?: string;
} }
).configuredServerUrl = configuredServerUrl; ).configuredServerUrl = configuredServerUrl;
} else {
console.warn("No server URL in config");
} }
initializeApiInstances(); initializeApiInstances();
}) })
@@ -556,8 +569,15 @@ if (isElectron()) {
); );
initializeApiInstances(); initializeApiInstances();
}); });
} else { } else {
initializeApiInstances(); initializeApiInstances();
}
}
if (document.readyState === "loading") {
document.addEventListener("DOMContentLoaded", initializeApp);
} else {
initializeApp();
} }
function updateApiInstances() { function updateApiInstances() {