fix: Electron desktop not logging in
This commit is contained in:
@@ -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) {
|
||||||
|
|||||||
@@ -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;
|
||||||
(
|
|
||||||
window as Window &
|
const hasElectronAPI = !!(
|
||||||
typeof globalThis & {
|
window as Window &
|
||||||
IS_ELECTRON?: boolean;
|
typeof globalThis & {
|
||||||
electronAPI?: unknown;
|
IS_ELECTRON?: boolean;
|
||||||
configuredServerUrl?: string;
|
electronAPI?: unknown;
|
||||||
}
|
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,31 +543,41 @@ export let authApi: AxiosInstance;
|
|||||||
// Homepage API (port 30006)
|
// Homepage API (port 30006)
|
||||||
export let homepageApi: AxiosInstance;
|
export let homepageApi: AxiosInstance;
|
||||||
|
|
||||||
if (isElectron()) {
|
function initializeApp() {
|
||||||
getServerConfig()
|
if (isElectron()) {
|
||||||
.then((config) => {
|
getServerConfig()
|
||||||
if (config?.serverUrl) {
|
.then((config) => {
|
||||||
configuredServerUrl = config.serverUrl;
|
if (config?.serverUrl) {
|
||||||
(
|
configuredServerUrl = config.serverUrl;
|
||||||
window as Window &
|
(
|
||||||
typeof globalThis & {
|
window as Window &
|
||||||
IS_ELECTRON?: boolean;
|
typeof globalThis & {
|
||||||
electronAPI?: unknown;
|
IS_ELECTRON?: boolean;
|
||||||
configuredServerUrl?: string;
|
electronAPI?: unknown;
|
||||||
}
|
configuredServerUrl?: string;
|
||||||
).configuredServerUrl = configuredServerUrl;
|
}
|
||||||
}
|
).configuredServerUrl = configuredServerUrl;
|
||||||
initializeApiInstances();
|
} else {
|
||||||
})
|
console.warn("No server URL in config");
|
||||||
.catch((error) => {
|
}
|
||||||
console.error(
|
initializeApiInstances();
|
||||||
"Failed to load server config, initializing with default:",
|
})
|
||||||
error,
|
.catch((error) => {
|
||||||
);
|
console.error(
|
||||||
initializeApiInstances();
|
"Failed to load server config, initializing with default:",
|
||||||
});
|
error,
|
||||||
|
);
|
||||||
|
initializeApiInstances();
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
initializeApiInstances();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (document.readyState === "loading") {
|
||||||
|
document.addEventListener("DOMContentLoaded", initializeApp);
|
||||||
} else {
|
} else {
|
||||||
initializeApiInstances();
|
initializeApp();
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateApiInstances() {
|
function updateApiInstances() {
|
||||||
|
|||||||
Reference in New Issue
Block a user