1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Fix ERR_FAILED for splash screen on windows sometimes (#5534)

This commit is contained in:
Sebastian Malton 2022-06-01 11:21:36 -07:00 committed by GitHub
parent e3cb23e111
commit 79c7cb2106
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 24 deletions

View File

@ -1,18 +0,0 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
// Register custom protocols
import { protocol } from "electron";
import path from "path";
export function registerFileProtocol(name: string, basePath: string) {
protocol.registerFileProtocol(name, (request, callback) => {
const filePath = request.url.replace(`${name}://`, "");
const absPath = path.resolve(basePath, filePath);
callback({ path: absPath });
});
}

View File

@ -11,13 +11,12 @@ import httpProxy from "http-proxy";
import * as LensExtensionsCommonApi from "../extensions/common-api";
import * as LensExtensionsMainApi from "../extensions/main-api";
import { app, autoUpdater, dialog, powerMonitor } from "electron";
import { appName, isIntegrationTesting, isMac, isWindows, productName, staticFilesDirectory } from "../common/vars";
import { appName, isIntegrationTesting, isMac, isWindows, productName } from "../common/vars";
import { LensProxy } from "./lens-proxy";
import { WindowManager } from "./window-manager";
import { ClusterManager } from "./cluster-manager";
import { shellSync } from "./shell-sync";
import { mangleProxyEnv } from "./proxy-env";
import { registerFileProtocol } from "../common/register-protocol";
import logger from "./logger";
import { appEventBus } from "../common/app-event-bus/event-bus";
import type { InstalledExtension } from "../extensions/extension-discovery/extension-discovery";
@ -198,8 +197,6 @@ async function main(di: DiContainer) {
powerMonitor.on("shutdown", () => app.exit());
registerFileProtocol("static", staticFilesDirectory);
PrometheusProviderRegistry.createInstance();
initializers.initPrometheusProviderRegistry();

View File

@ -14,9 +14,10 @@ import type { ClusterFrameInfo } from "../common/cluster-frames";
import { clusterFrameMap } from "../common/cluster-frames";
import { IpcRendererNavigationEvents } from "../renderer/navigation/events";
import logger from "./logger";
import { isMac, productName } from "../common/vars";
import { isMac, productName, staticFilesDirectory } from "../common/vars";
import { LensProxy } from "./lens-proxy";
import { bundledExtensionsLoaded } from "../common/ipc/extension-handling";
import path from "path";
function isHideable(window: BrowserWindow | null): boolean {
return Boolean(window && !window.isDestroyed());
@ -257,7 +258,20 @@ export class WindowManager extends Singleton {
nativeWindowOpen: true,
},
});
await this.splashWindow.loadURL("static://splash.html");
const splashWindowFilePath = path.join(staticFilesDirectory, "splash.html");
try {
await this.splashWindow.loadFile(splashWindowFilePath);
} catch (error) {
if (String(error).includes("ERR_FAILED")) {
logger.warn("[WINDOW-MANAGER]: failed to load splash window on first attempt, trying again...");
// Try again, from reading some issues it seems that trying again immedeiately sometimes works
await this.splashWindow.loadFile(splashWindowFilePath);
} else {
throw error;
}
}
}
this.splashWindow.show();
}