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 (#5539)
This commit is contained in:
parent
ec1df4717d
commit
06db3119a6
@ -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 });
|
|
||||||
});
|
|
||||||
}
|
|
||||||
@ -1,28 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
|
||||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
|
||||||
*/
|
|
||||||
import { getInjectable } from "@ogre-tools/injectable";
|
|
||||||
import { protocol } from "electron";
|
|
||||||
import getAbsolutePathInjectable from "../../../common/path/get-absolute-path.injectable";
|
|
||||||
|
|
||||||
const registerFileProtocolInjectable = getInjectable({
|
|
||||||
id: "register-file-protocol",
|
|
||||||
|
|
||||||
instantiate: (di) => {
|
|
||||||
const getAbsolutePath = di.inject(getAbsolutePathInjectable);
|
|
||||||
|
|
||||||
return (name: string, basePath: string) => {
|
|
||||||
protocol.registerFileProtocol(name, (request, callback) => {
|
|
||||||
const filePath = request.url.replace(`${name}://`, "");
|
|
||||||
const absPath = getAbsolutePath(basePath, filePath);
|
|
||||||
|
|
||||||
callback({ path: absPath });
|
|
||||||
});
|
|
||||||
};
|
|
||||||
},
|
|
||||||
|
|
||||||
causesSideEffects: true,
|
|
||||||
});
|
|
||||||
|
|
||||||
export default registerFileProtocolInjectable;
|
|
||||||
@ -38,7 +38,6 @@ import type { AppEvent } from "../common/app-event-bus/event-bus";
|
|||||||
import commandLineArgumentsInjectable from "./utils/command-line-arguments.injectable";
|
import commandLineArgumentsInjectable from "./utils/command-line-arguments.injectable";
|
||||||
import initializeExtensionsInjectable from "./start-main-application/runnables/initialize-extensions.injectable";
|
import initializeExtensionsInjectable from "./start-main-application/runnables/initialize-extensions.injectable";
|
||||||
import lensResourcesDirInjectable from "../common/vars/lens-resources-dir.injectable";
|
import lensResourcesDirInjectable from "../common/vars/lens-resources-dir.injectable";
|
||||||
import registerFileProtocolInjectable from "./electron-app/features/register-file-protocol.injectable";
|
|
||||||
import environmentVariablesInjectable from "../common/utils/environment-variables.injectable";
|
import environmentVariablesInjectable from "../common/utils/environment-variables.injectable";
|
||||||
import setupIpcMainHandlersInjectable from "./electron-app/runnables/setup-ipc-main-handlers/setup-ipc-main-handlers.injectable";
|
import setupIpcMainHandlersInjectable from "./electron-app/runnables/setup-ipc-main-handlers/setup-ipc-main-handlers.injectable";
|
||||||
import setupLensProxyInjectable from "./start-main-application/runnables/setup-lens-proxy.injectable";
|
import setupLensProxyInjectable from "./start-main-application/runnables/setup-lens-proxy.injectable";
|
||||||
@ -237,5 +236,4 @@ const overrideElectronFeatures = (di: DiContainer) => {
|
|||||||
|
|
||||||
di.override(setElectronAppPathInjectable, () => () => {});
|
di.override(setElectronAppPathInjectable, () => () => {});
|
||||||
di.override(isAutoUpdateEnabledInjectable, () => () => false);
|
di.override(isAutoUpdateEnabledInjectable, () => () => false);
|
||||||
di.override(registerFileProtocolInjectable, () => () => {});
|
|
||||||
};
|
};
|
||||||
|
|||||||
@ -29,7 +29,9 @@ const applicationWindowInjectable = getInjectable({
|
|||||||
title: applicationName,
|
title: applicationName,
|
||||||
defaultHeight: 900,
|
defaultHeight: 900,
|
||||||
defaultWidth: 1440,
|
defaultWidth: 1440,
|
||||||
getContentUrl: () => `http://localhost:${lensProxyPort.get()}`,
|
getContentSource: () => ({
|
||||||
|
url: `http://localhost:${lensProxyPort.get()}`,
|
||||||
|
}),
|
||||||
resizable: true,
|
resizable: true,
|
||||||
windowFrameUtilitiesAreShown: isMac,
|
windowFrameUtilitiesAreShown: isMac,
|
||||||
titleBarStyle: isMac ? "hiddenInset" : "hidden",
|
titleBarStyle: isMac ? "hiddenInset" : "hidden",
|
||||||
|
|||||||
@ -7,18 +7,26 @@ import loggerInjectable from "../../../../common/logger.injectable";
|
|||||||
import applicationWindowStateInjectable from "./application-window-state.injectable";
|
import applicationWindowStateInjectable from "./application-window-state.injectable";
|
||||||
import { BrowserWindow } from "electron";
|
import { BrowserWindow } from "electron";
|
||||||
import { openBrowser } from "../../../../common/utils";
|
import { openBrowser } from "../../../../common/utils";
|
||||||
import type { SendToViewArgs } from "./lens-window-injection-token";
|
|
||||||
import sendToChannelInElectronBrowserWindowInjectable from "./send-to-channel-in-electron-browser-window.injectable";
|
import sendToChannelInElectronBrowserWindowInjectable from "./send-to-channel-in-electron-browser-window.injectable";
|
||||||
import type { LensWindow } from "./create-lens-window.injectable";
|
import type { LensWindow } from "./create-lens-window.injectable";
|
||||||
|
import type { RequireExactlyOne } from "type-fest";
|
||||||
|
|
||||||
export type ElectronWindowTitleBarStyle = "hiddenInset" | "hidden" | "default" | "customButtonsOnHover";
|
export type ElectronWindowTitleBarStyle = "hiddenInset" | "hidden" | "default" | "customButtonsOnHover";
|
||||||
|
|
||||||
|
export interface FileSource {
|
||||||
|
file: string;
|
||||||
|
}
|
||||||
|
export interface UrlSource {
|
||||||
|
url: string;
|
||||||
|
}
|
||||||
|
export type ContentSource = RequireExactlyOne<FileSource & UrlSource>;
|
||||||
|
|
||||||
export interface ElectronWindowConfiguration {
|
export interface ElectronWindowConfiguration {
|
||||||
id: string;
|
id: string;
|
||||||
title: string;
|
title: string;
|
||||||
defaultHeight: number;
|
defaultHeight: number;
|
||||||
defaultWidth: number;
|
defaultWidth: number;
|
||||||
getContentUrl: () => string;
|
getContentSource: () => ContentSource;
|
||||||
resizable: boolean;
|
resizable: boolean;
|
||||||
windowFrameUtilitiesAreShown: boolean;
|
windowFrameUtilitiesAreShown: boolean;
|
||||||
centered: boolean;
|
centered: boolean;
|
||||||
@ -33,6 +41,10 @@ export interface ElectronWindowConfiguration {
|
|||||||
export type CreateElectronWindow = () => Promise<LensWindow>;
|
export type CreateElectronWindow = () => Promise<LensWindow>;
|
||||||
export type CreateElectronWindowFor = (config: ElectronWindowConfiguration) => CreateElectronWindow;
|
export type CreateElectronWindowFor = (config: ElectronWindowConfiguration) => CreateElectronWindow;
|
||||||
|
|
||||||
|
function isFileSource(src: ContentSource): src is FileSource {
|
||||||
|
return typeof (src as FileSource).file === "string";
|
||||||
|
}
|
||||||
|
|
||||||
const createElectronWindowFor = getInjectable({
|
const createElectronWindowFor = getInjectable({
|
||||||
id: "create-electron-window-for",
|
id: "create-electron-window-for",
|
||||||
|
|
||||||
@ -159,17 +171,22 @@ const createElectronWindowFor = getInjectable({
|
|||||||
return { action: "deny" };
|
return { action: "deny" };
|
||||||
});
|
});
|
||||||
|
|
||||||
const contentUrl = configuration.getContentUrl();
|
const contentSource = configuration.getContentSource();
|
||||||
|
|
||||||
logger.info(`[CREATE-ELECTRON-WINDOW]: Loading content for window "${configuration.id}" from url: ${contentUrl}...`);
|
if (isFileSource(contentSource)) {
|
||||||
|
logger.info(`[CREATE-ELECTRON-WINDOW]: Loading content for window "${configuration.id}" from file: ${contentSource.file}...`);
|
||||||
|
await browserWindow.loadFile(contentSource.file);
|
||||||
|
} else {
|
||||||
|
logger.info(`[CREATE-ELECTRON-WINDOW]: Loading content for window "${configuration.id}" from url: ${contentSource.url}...`);
|
||||||
|
await browserWindow.loadURL(contentSource.url);
|
||||||
|
}
|
||||||
|
|
||||||
await browserWindow.loadURL(contentUrl);
|
|
||||||
await configuration.beforeOpen?.();
|
await configuration.beforeOpen?.();
|
||||||
|
|
||||||
return {
|
return {
|
||||||
show: () => browserWindow.show(),
|
show: () => browserWindow.show(),
|
||||||
close: () => browserWindow.close(),
|
close: () => browserWindow.close(),
|
||||||
send: (args: SendToViewArgs) => sendToChannelInLensWindow(browserWindow, args),
|
send: (args) => sendToChannelInLensWindow(browserWindow, args),
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|||||||
@ -4,7 +4,7 @@
|
|||||||
*/
|
*/
|
||||||
import { getInjectable } from "@ogre-tools/injectable";
|
import { getInjectable } from "@ogre-tools/injectable";
|
||||||
import type { SendToViewArgs } from "./lens-window-injection-token";
|
import type { SendToViewArgs } from "./lens-window-injection-token";
|
||||||
import type { ElectronWindowTitleBarStyle } from "./create-electron-window-for.injectable";
|
import type { ContentSource, ElectronWindowTitleBarStyle } from "./create-electron-window-for.injectable";
|
||||||
import createElectronWindowForInjectable from "./create-electron-window-for.injectable";
|
import createElectronWindowForInjectable from "./create-electron-window-for.injectable";
|
||||||
|
|
||||||
export interface LensWindow {
|
export interface LensWindow {
|
||||||
@ -13,12 +13,12 @@ export interface LensWindow {
|
|||||||
send: (args: SendToViewArgs) => void;
|
send: (args: SendToViewArgs) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface LensWindowConfiguration {
|
export interface LensWindowConfiguration {
|
||||||
id: string;
|
id: string;
|
||||||
title: string;
|
title: string;
|
||||||
defaultHeight: number;
|
defaultHeight: number;
|
||||||
defaultWidth: number;
|
defaultWidth: number;
|
||||||
getContentUrl: () => string;
|
getContentSource: () => ContentSource;
|
||||||
resizable: boolean;
|
resizable: boolean;
|
||||||
windowFrameUtilitiesAreShown: boolean;
|
windowFrameUtilitiesAreShown: boolean;
|
||||||
centered: boolean;
|
centered: boolean;
|
||||||
@ -38,12 +38,10 @@ const createLensWindowInjectable = getInjectable({
|
|||||||
return (configuration: LensWindowConfiguration) => {
|
return (configuration: LensWindowConfiguration) => {
|
||||||
let browserWindow: LensWindow | undefined;
|
let browserWindow: LensWindow | undefined;
|
||||||
|
|
||||||
const createElectronWindow = createElectronWindowFor(Object.assign(
|
const createElectronWindow = createElectronWindowFor({
|
||||||
{
|
...configuration,
|
||||||
onClose: () => browserWindow = undefined,
|
onClose: () => browserWindow = undefined,
|
||||||
},
|
});
|
||||||
configuration,
|
|
||||||
));
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
get visible() {
|
get visible() {
|
||||||
|
|||||||
@ -5,17 +5,24 @@
|
|||||||
import { getInjectable } from "@ogre-tools/injectable";
|
import { getInjectable } from "@ogre-tools/injectable";
|
||||||
import { lensWindowInjectionToken } from "../application-window/lens-window-injection-token";
|
import { lensWindowInjectionToken } from "../application-window/lens-window-injection-token";
|
||||||
import createLensWindowInjectable from "../application-window/create-lens-window.injectable";
|
import createLensWindowInjectable from "../application-window/create-lens-window.injectable";
|
||||||
|
import staticFilesDirectoryInjectable from "../../../../common/vars/static-files-directory.injectable";
|
||||||
|
import getAbsolutePathInjectable from "../../../../common/path/get-absolute-path.injectable";
|
||||||
|
|
||||||
const splashWindowInjectable = getInjectable({
|
const splashWindowInjectable = getInjectable({
|
||||||
id: "splash-window",
|
id: "splash-window",
|
||||||
|
|
||||||
instantiate: (di) => {
|
instantiate: (di) => {
|
||||||
const createLensWindow = di.inject(createLensWindowInjectable);
|
const createLensWindow = di.inject(createLensWindowInjectable);
|
||||||
|
const staticFilesDirectory = di.inject(staticFilesDirectoryInjectable);
|
||||||
|
const getAbsolutePath = di.inject(getAbsolutePathInjectable);
|
||||||
|
const splashWindowFile = getAbsolutePath(staticFilesDirectory, "splash.html");
|
||||||
|
|
||||||
return createLensWindow({
|
return createLensWindow({
|
||||||
id: "splash",
|
id: "splash",
|
||||||
title: "Loading",
|
title: "Loading",
|
||||||
getContentUrl: () => "static://splash.html",
|
getContentSource: () => ({
|
||||||
|
file: splashWindowFile,
|
||||||
|
}),
|
||||||
defaultWidth: 500,
|
defaultWidth: 500,
|
||||||
defaultHeight: 300,
|
defaultHeight: 300,
|
||||||
resizable: false,
|
resizable: false,
|
||||||
|
|||||||
@ -1,27 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
|
||||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
|
||||||
*/
|
|
||||||
import { getInjectable } from "@ogre-tools/injectable";
|
|
||||||
import registerFileProtocolInjectable from "../../electron-app/features/register-file-protocol.injectable";
|
|
||||||
import staticFilesDirectoryInjectable from "../../../common/vars/static-files-directory.injectable";
|
|
||||||
import { beforeApplicationIsLoadingInjectionToken } from "../runnable-tokens/before-application-is-loading-injection-token";
|
|
||||||
|
|
||||||
const setupFileProtocolInjectable = getInjectable({
|
|
||||||
id: "setup-file-protocol",
|
|
||||||
|
|
||||||
instantiate: (di) => {
|
|
||||||
const registerFileProtocol = di.inject(registerFileProtocolInjectable);
|
|
||||||
const staticFilesDirectory = di.inject(staticFilesDirectoryInjectable);
|
|
||||||
|
|
||||||
return {
|
|
||||||
run: () => {
|
|
||||||
registerFileProtocol("static", staticFilesDirectory);
|
|
||||||
},
|
|
||||||
};
|
|
||||||
},
|
|
||||||
|
|
||||||
injectionToken: beforeApplicationIsLoadingInjectionToken,
|
|
||||||
});
|
|
||||||
|
|
||||||
export default setupFileProtocolInjectable;
|
|
||||||
Loading…
Reference in New Issue
Block a user