Replace static application window with ability to create many (#5979)

* Replace static application window with ability to create as many as you wish

Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>

* Adapt tests for replacing static application window with ability to create as many as you wish and separate starting of main and window in behaviours

Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>

* Make first render of application smaller in test that proves to be hard for CI

Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>

* Remove redundant code

Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>

* Simplify code

Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>

Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
This commit is contained in:
Janne Savolainen authored and GitHub committed 2022-08-16 15:55:42 +03:00
1 parent 299922c8a7
commit 63d5a34379
98 files changed
+3283 -2743

No files matched your search

-21
View File
@@ -17,9 +17,6 @@ import extensionsStoreInjectable from "../extensions/extensions-store/extensions
import type { ExtensionsStore } from "../extensions/extensions-store/extensions-store";
import fileSystemProvisionerStoreInjectable from "../extensions/extension-loader/file-system-provisioner-store/file-system-provisioner-store.injectable";
import type { FileSystemProvisionerStore } from "../extensions/extension-loader/file-system-provisioner-store/file-system-provisioner-store";
import clusterStoreInjectable from "../common/cluster-store/cluster-store.injectable";
import type { ClusterStore } from "../common/cluster-store/cluster-store";
import type { Cluster } from "../common/cluster/cluster";
import userStoreInjectable from "../common/user-store/user-store.injectable";
import type { UserStore } from "../common/user-store";
import getAbsolutePathInjectable from "../common/path/get-absolute-path.injectable";
@@ -62,9 +59,7 @@ import { observable } from "mobx";
import waitForElectronToBeReadyInjectable from "./electron-app/features/wait-for-electron-to-be-ready.injectable";
import setupListenerForCurrentClusterFrameInjectable from "./start-main-application/lens-window/current-cluster-frame/setup-listener-for-current-cluster-frame.injectable";
import ipcMainInjectable from "./utils/channel/ipc-main/ipc-main.injectable";
import createElectronWindowForInjectable from "./start-main-application/lens-window/application-window/create-electron-window.injectable";
import setupRunnablesAfterWindowIsOpenedInjectable from "./electron-app/runnables/setup-runnables-after-window-is-opened.injectable";
import sendToChannelInElectronBrowserWindowInjectable from "./start-main-application/lens-window/application-window/send-to-channel-in-electron-browser-window.injectable";
import broadcastMessageInjectable from "../common/ipc/broadcast-message.injectable";
import getElectronThemeInjectable from "./electron-app/features/get-electron-theme.injectable";
import syncThemeFromOperatingSystemInjectable from "./electron-app/features/sync-theme-from-operating-system.injectable";
@@ -144,7 +139,6 @@ export function getDiForUnitTesting(opts: { doGeneralOverrides?: boolean } = {})
di.override(userStoreInjectable, () => ({ startMainReactions: () => {}, extensionRegistryUrl: { customUrl: "some-custom-url" }}) as UserStore);
di.override(extensionsStoreInjectable, () => ({ isEnabled: (opts) => (void opts, false) }) as ExtensionsStore);
di.override(clusterStoreInjectable, () => ({ provideInitialFromMain: () => {}, getById: (id) => (void id, {}) as Cluster }) as ClusterStore);
di.override(fileSystemProvisionerStoreInjectable, () => ({}) as FileSystemProvisionerStore);
overrideOperatingSystem(di);
@@ -270,21 +264,6 @@ const overrideElectronFeatures = (di: DiContainer) => {
throw new Error("Tried to check for platform updates without explicit override.");
});
di.override(createElectronWindowForInjectable, () => () => ({
show: () => {},
close: () => {},
send: (arg) => {
const sendFake = di.inject(sendToChannelInElectronBrowserWindowInjectable) as any;
sendFake(null, arg);
},
loadFile: async () => {},
loadUrl: async () => {},
}));
di.override(
getElectronAppPathInjectable,
() => (name: string) => `some-electron-app-path-for-${kebabCase(name)}`,
+4 -1
View File
@@ -10,12 +10,15 @@ import * as LensExtensionsCommonApi from "../extensions/common-api";
import * as LensExtensionsMainApi from "../extensions/main-api";
import { getDi } from "./getDi";
import startMainApplicationInjectable from "./start-main-application/start-main-application.injectable";
import shouldStartHiddenInjectable from "./electron-app/features/should-start-hidden.injectable";
const di = getDi();
const shouldStartHidden = di.inject(shouldStartHiddenInjectable);
const startApplication = di.inject(startMainApplicationInjectable);
void startApplication();
void startApplication(!shouldStartHidden);
/**
* Exports for virtual package "@k8slens/extensions" for main-process.
@@ -20,8 +20,7 @@ import stopServicesAndExitAppInjectable from "../stop-services-and-exit-app.inje
import isMacInjectable from "../../common/vars/is-mac.injectable";
import { computed } from "mobx";
import showAboutInjectable from "./show-about.injectable";
import applicationWindowInjectable from "../start-main-application/lens-window/application-window/application-window.injectable";
import reloadWindowInjectable from "../start-main-application/lens-window/reload-window.injectable";
import reloadCurrentApplicationWindowInjectable from "../start-main-application/lens-window/reload-current-application-window.injectable";
import showApplicationWindowInjectable from "../start-main-application/lens-window/show-application-window.injectable";
import processCheckingForUpdatesInjectable from "../application-update/check-for-updates/process-checking-for-updates.injectable";
import openLinkInBrowserInjectable from "../../common/utils/open-link-in-browser.injectable";
@@ -44,9 +43,8 @@ const applicationMenuItemsInjectable = getInjectable({
const updatingIsEnabled = di.inject(updatingIsEnabledInjectable);
const electronMenuItems = di.inject(electronMenuItemsInjectable);
const showAbout = di.inject(showAboutInjectable);
const applicationWindow = di.inject(applicationWindowInjectable);
const showApplicationWindow = di.inject(showApplicationWindowInjectable);
const reloadApplicationWindow = di.inject(reloadWindowInjectable, applicationWindow);
const reloadApplicationWindow = di.inject(reloadCurrentApplicationWindowInjectable);
const navigateToPreferences = di.inject(navigateToPreferencesInjectable);
const navigateToExtensions = di.inject(navigateToExtensionsInjectable);
const navigateToCatalog = di.inject(navigateToCatalogInjectable);
@@ -0,0 +1,10 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectionToken } from "@ogre-tools/injectable";
import type { LensWindow } from "./create-lens-window.injectable";
export const applicationWindowInjectionToken = getInjectionToken<LensWindow>({
id: "application-window-injection-token",
});
@@ -1,53 +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 { lensWindowInjectionToken } from "./lens-window-injection-token";
import createLensWindowInjectable from "./create-lens-window.injectable";
import lensProxyPortInjectable from "../../../lens-proxy/lens-proxy-port.injectable";
import isMacInjectable from "../../../../common/vars/is-mac.injectable";
import appNameInjectable from "../../../app-paths/app-name/app-name.injectable";
import appEventBusInjectable from "../../../../common/app-event-bus/app-event-bus.injectable";
import waitUntilBundledExtensionsAreLoadedInjectable from "./wait-until-bundled-extensions-are-loaded.injectable";
const applicationWindowInjectable = getInjectable({
id: "application-window",
instantiate: (di) => {
const createLensWindow = di.inject(createLensWindowInjectable);
const isMac = di.inject(isMacInjectable);
const applicationName = di.inject(appNameInjectable);
const appEventBus = di.inject(appEventBusInjectable);
const waitUntilBundledExtensionsAreLoaded = di.inject(waitUntilBundledExtensionsAreLoadedInjectable);
const lensProxyPort = di.inject(lensProxyPortInjectable);
return createLensWindow({
id: "only-application-window",
title: applicationName,
defaultHeight: 900,
defaultWidth: 1440,
getContentSource: () => ({
url: `http://localhost:${lensProxyPort.get()}`,
}),
resizable: true,
windowFrameUtilitiesAreShown: isMac,
titleBarStyle: isMac ? "hiddenInset" : "hidden",
centered: false,
onFocus: () => {
appEventBus.emit({ name: "app", action: "focus" });
},
onBlur: () => {
appEventBus.emit({ name: "app", action: "blur" });
},
onDomReady: () => {
appEventBus.emit({ name: "app", action: "dom-ready" });
},
beforeOpen: waitUntilBundledExtensionsAreLoaded,
});
},
injectionToken: lensWindowInjectionToken,
});
export default applicationWindowInjectable;
@@ -0,0 +1,68 @@
/**
* 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 createLensWindowInjectable from "./create-lens-window.injectable";
import lensProxyPortInjectable from "../../../lens-proxy/lens-proxy-port.injectable";
import isMacInjectable from "../../../../common/vars/is-mac.injectable";
import appNameInjectable from "../../../app-paths/app-name/app-name.injectable";
import appEventBusInjectable from "../../../../common/app-event-bus/app-event-bus.injectable";
import waitUntilBundledExtensionsAreLoadedInjectable from "./wait-until-bundled-extensions-are-loaded.injectable";
import { applicationWindowInjectionToken } from "./application-window-injection-token";
const createApplicationWindowInjectable = getInjectable({
id: "create-application-window",
instantiate: (parentDi) => (id: string) => {
const windowInjectable = getInjectable({
id: `application-window-for-${id}`,
instantiate: (di) => {
const createLensWindow = di.inject(createLensWindowInjectable);
const isMac = di.inject(isMacInjectable);
const applicationName = di.inject(appNameInjectable);
const appEventBus = di.inject(appEventBusInjectable);
const waitUntilBundledExtensionsAreLoaded = di.inject(waitUntilBundledExtensionsAreLoadedInjectable);
const lensProxyPort = di.inject(lensProxyPortInjectable);
return createLensWindow({
id,
title: applicationName,
defaultHeight: 900,
defaultWidth: 1440,
getContentSource: () => ({
url: `http://localhost:${lensProxyPort.get()}`,
}),
resizable: true,
windowFrameUtilitiesAreShown: isMac,
titleBarStyle: isMac ? "hiddenInset" : "hidden",
centered: false,
onFocus: () => {
appEventBus.emit({ name: "app", action: "focus" });
},
onBlur: () => {
appEventBus.emit({ name: "app", action: "blur" });
},
onDomReady: () => {
appEventBus.emit({ name: "app", action: "dom-ready" });
},
onClose: () => {
parentDi.deregister(windowInjectable);
},
beforeOpen: waitUntilBundledExtensionsAreLoaded,
});
},
injectionToken: applicationWindowInjectionToken,
});
parentDi.register(windowInjectable);
return parentDi.inject(windowInjectable);
},
});
export default createApplicationWindowInjectable;
@@ -0,0 +1,15 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getGlobalOverride } from "../../../../common/test-utils/get-global-override";
import createElectronWindowInjectable from "./create-electron-window.injectable";
export default getGlobalOverride(createElectronWindowInjectable, () => () => ({
loadFile: async () => {},
loadUrl: async () => {},
show: () => {},
close: () => {},
send: () => {},
reload: () => {},
}));
@@ -140,7 +140,14 @@ const createElectronWindowInjectable = getInjectable({
show: () => browserWindow.show(),
close: () => browserWindow.close(),
send: (args) => sendToChannelInLensWindow(browserWindow, args),
send: (args) => sendToChannelInLensWindow(configuration.id, browserWindow, args),
reload: () => {
const wc = browserWindow.webContents;
wc.reload();
wc.clearHistory();
},
};
};
},
@@ -0,0 +1,19 @@
/**
* 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 createApplicationWindowInjectable from "./create-application-window.injectable";
// Note: Motivation is to create the window with same ID to use stored dimensions
const createFirstApplicationWindowInjectable = getInjectable({
id: "create-first-application-window",
instantiate: (di) => {
const createApplicationWindow = di.inject(createApplicationWindowInjectable);
return () => createApplicationWindow("first-application-window");
},
});
export default createFirstApplicationWindowInjectable;
@@ -3,10 +3,10 @@
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable } from "@ogre-tools/injectable";
import type { LensWindow, SendToViewArgs } from "./lens-window-injection-token";
import type { ContentSource, ElectronWindowTitleBarStyle } from "./create-electron-window.injectable";
import createElectronWindowForInjectable from "./create-electron-window.injectable";
import assert from "assert";
import type { ClusterFrameInfo } from "../../../../common/cluster-frames";
export interface ElectronWindow {
show: () => void;
@@ -14,6 +14,24 @@ export interface ElectronWindow {
send: (args: SendToViewArgs) => void;
loadFile: (filePath: string) => Promise<void>;
loadUrl: (url: string) => Promise<void>;
reload: () => void;
}
export interface SendToViewArgs {
channel: string;
frameInfo?: ClusterFrameInfo;
data?: unknown[];
}
export interface LensWindow {
id: string;
start: () => Promise<void>;
close: () => void;
show: () => void;
send: (args: SendToViewArgs) => void;
isVisible: boolean;
isStarting: boolean;
reload: () => void;
}
export interface LensWindowConfiguration {
@@ -30,6 +48,7 @@ export interface LensWindowConfiguration {
onFocus?: () => void;
onBlur?: () => void;
onDomReady?: () => void;
onClose?: () => void;
}
const createLensWindowInjectable = getInjectable({
@@ -97,6 +116,7 @@ const createLensWindowInjectable = getInjectable({
browserWindow?.close();
browserWindow = undefined;
windowIsShown = false;
configuration.onClose?.();
},
send: (args: SendToViewArgs) => {
@@ -106,6 +126,14 @@ const createLensWindowInjectable = getInjectable({
return browserWindow.send(args);
},
reload: () => {
if (!browserWindow) {
throw new Error(`Tried to reload window "${configuration.id}" but the window was closed`);
}
return browserWindow.reload();
},
};
};
},
@@ -0,0 +1,16 @@
/**
* 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 { first } from "lodash/fp";
import { applicationWindowInjectionToken } from "./application-window-injection-token";
const getCurrentApplicationWindowInjectable = getInjectable({
id: "get-current-application-window",
instantiate: (di) => () =>
first(di.injectMany(applicationWindowInjectionToken)),
});
export default getCurrentApplicationWindowInjectable;
@@ -1,26 +0,0 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectionToken } from "@ogre-tools/injectable";
import type { ClusterFrameInfo } from "../../../../common/cluster-frames";
export interface SendToViewArgs {
channel: string;
frameInfo?: ClusterFrameInfo;
data?: unknown[];
}
export interface LensWindow {
id: string;
start: () => Promise<void>;
close: () => void;
show: () => void;
send: (args: SendToViewArgs) => void;
isVisible: boolean;
isStarting: boolean;
}
export const lensWindowInjectionToken = getInjectionToken<LensWindow>({
id: "lens-window",
});
@@ -4,7 +4,7 @@
*/
import { getInjectable } from "@ogre-tools/injectable";
import type { BrowserWindow } from "electron";
import type { SendToViewArgs } from "./lens-window-injection-token";
import type { SendToViewArgs } from "./create-lens-window.injectable";
const sendToChannelInElectronBrowserWindowInjectable = getInjectable({
id: "send-to-channel-in-electron-browser-window",
@@ -12,6 +12,7 @@ const sendToChannelInElectronBrowserWindowInjectable = getInjectable({
instantiate:
() =>
(
windowId: string,
browserWindow: BrowserWindow,
{ channel, frameInfo, data = [] }: SendToViewArgs,
) => {
@@ -5,13 +5,13 @@
import { pipeline } from "@ogre-tools/fp";
import { getInjectable } from "@ogre-tools/injectable";
import { filter } from "lodash/fp";
import { lensWindowInjectionToken } from "./application-window/lens-window-injection-token";
import { applicationWindowInjectionToken } from "./application-window/application-window-injection-token";
const getVisibleWindowsInjectable = getInjectable({
id: "get-visible-windows",
instantiate: (di) => {
const getAllLensWindows = () => di.injectMany(lensWindowInjectionToken);
const getAllLensWindows = () => di.injectMany(applicationWindowInjectionToken);
return () =>
pipeline(
@@ -3,13 +3,13 @@
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable } from "@ogre-tools/injectable";
import { lensWindowInjectionToken } from "../application-window/lens-window-injection-token";
import { applicationWindowInjectionToken } from "../application-window/application-window-injection-token";
const closeAllWindowsInjectable = getInjectable({
id: "close-all-windows",
instantiate: (di) => () => {
const lensWindows = di.injectMany(lensWindowInjectionToken);
const lensWindows = di.injectMany(applicationWindowInjectionToken);
lensWindows.forEach((lensWindow) => {
lensWindow.close();
@@ -6,7 +6,8 @@ import { getInjectable } from "@ogre-tools/injectable";
import { iter } from "../../../common/utils";
import clusterFramesInjectable from "../../../common/cluster-frames.injectable";
import showApplicationWindowInjectable from "./show-application-window.injectable";
import applicationWindowInjectable from "./application-window/application-window.injectable";
import getCurrentApplicationWindowInjectable from "./application-window/get-current-application-window.injectable";
import assert from "assert";
export type NavigateForExtension = (
extId: string,
@@ -19,7 +20,7 @@ const navigateForExtensionInjectable = getInjectable({
id: "navigate-for-extension",
instantiate: (di): NavigateForExtension => {
const applicationWindow = di.inject(applicationWindowInjectable);
const getApplicationWindow = di.inject(getCurrentApplicationWindowInjectable);
const clusterFrames = di.inject(clusterFramesInjectable);
const showApplicationWindow = di.inject(showApplicationWindowInjectable);
@@ -31,6 +32,10 @@ const navigateForExtensionInjectable = getInjectable({
) => {
await showApplicationWindow();
const applicationWindow = getApplicationWindow();
assert(applicationWindow);
const frameInfo = iter.find(
clusterFrames.values(),
(frameInfo) => frameInfo.frameId === frameId,
@@ -4,22 +4,27 @@
*/
import { getInjectable } from "@ogre-tools/injectable";
import { iter } from "../../../common/utils";
import applicationWindowInjectable from "./application-window/application-window.injectable";
import clusterFramesInjectable from "../../../common/cluster-frames.injectable";
import { IpcRendererNavigationEvents } from "../../../renderer/navigation/events";
import showApplicationWindowInjectable from "./show-application-window.injectable";
import getCurrentApplicationWindowInjectable from "./application-window/get-current-application-window.injectable";
import assert from "assert";
const navigateInjectable = getInjectable({
id: "navigate",
instantiate: (di) => {
const applicationWindow = di.inject(applicationWindowInjectable);
const getApplicationWindow = di.inject(getCurrentApplicationWindowInjectable);
const showApplicationWindow = di.inject(showApplicationWindowInjectable);
const clusterFrames = di.inject(clusterFramesInjectable);
return async (url: string, frameId?: number) => {
await showApplicationWindow();
const applicationWindow = getApplicationWindow();
assert(applicationWindow);
const frameInfo = iter.find(
clusterFrames.values(),
(frameInfo) => frameInfo.frameId === frameId,
@@ -1,24 +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 { webContents } from "electron";
const reloadAllWindowsInjectable = getInjectable({
id: "reload-all-windows",
instantiate: () => () => {
webContents
.getAllWebContents()
.filter((wc) => wc.getType() === "window")
.forEach((wc) => {
wc.reload();
wc.clearHistory();
});
},
causesSideEffects: true,
});
export default reloadAllWindowsInjectable;
@@ -0,0 +1,38 @@
/**
* 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 { IpcRendererNavigationEvents } from "../../../renderer/navigation/events";
import currentClusterFrameInjectable from "./current-cluster-frame/current-cluster-frame.injectable";
import getCurrentApplicationWindowInjectable from "./application-window/get-current-application-window.injectable";
const reloadCurrentApplicationWindowInjectable = getInjectable({
id: "reload-current-application-window",
instantiate: (di) => {
const getCurrentApplicationWindow = di.inject(getCurrentApplicationWindowInjectable);
const currentClusterIframe = di.inject(currentClusterFrameInjectable);
return () => {
const lensWindow = getCurrentApplicationWindow();
if (!lensWindow) {
return;
}
const frameInfo = currentClusterIframe.get();
if (frameInfo) {
lensWindow.send({
channel: IpcRendererNavigationEvents.RELOAD_PAGE,
frameInfo,
});
} else {
lensWindow.reload();
}
};
},
});
export default reloadCurrentApplicationWindowInjectable;
@@ -1,33 +0,0 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable, lifecycleEnum } from "@ogre-tools/injectable";
import type { LensWindow } from "./application-window/lens-window-injection-token";
import { IpcRendererNavigationEvents } from "../../../renderer/navigation/events";
import currentClusterFrameInjectable from "./current-cluster-frame/current-cluster-frame.injectable";
import reloadAllWindowsInjectable from "./reload-all-windows.injectable";
const reloadWindowInjectable = getInjectable({
id: "reload-window",
instantiate: (di, lensWindow: LensWindow) => () => {
const currentClusterIframe = di.inject(currentClusterFrameInjectable);
const reloadAllWindows = di.inject(reloadAllWindowsInjectable);
const frameInfo = currentClusterIframe.get();
if (frameInfo) {
lensWindow.send({
channel: IpcRendererNavigationEvents.RELOAD_PAGE,
frameInfo,
});
} else {
reloadAllWindows();
}
},
lifecycle: lifecycleEnum.transient,
});
export default reloadWindowInjectable;
@@ -4,22 +4,26 @@
*/
import { getInjectable } from "@ogre-tools/injectable";
import splashWindowInjectable from "./splash-window/splash-window.injectable";
import applicationWindowInjectable from "./application-window/application-window.injectable";
import { identity, some } from "lodash/fp";
import focusApplicationInjectable from "../../electron-app/features/focus-application.injectable";
import getCurrentApplicationWindowInjectable from "./application-window/get-current-application-window.injectable";
import createFirstApplicationWindowInjectable from "./application-window/create-first-application-window.injectable";
const someIsTruthy = some(identity);
const showApplicationWindowInjectable = getInjectable({
id: "show-application-window",
instantiate: (di) => {
const applicationWindow = di.inject(applicationWindowInjectable);
const getApplicationWindow = di.inject(getCurrentApplicationWindowInjectable);
const createFirstApplicationWindow = di.inject(createFirstApplicationWindowInjectable);
const splashWindow = di.inject(splashWindowInjectable);
const focusApplication = di.inject(focusApplicationInjectable);
return async () => {
focusApplication();
const applicationWindow = getApplicationWindow() ?? createFirstApplicationWindow();
if (applicationWindow.isStarting) {
applicationWindow.show();
splashWindow.close();
@@ -3,7 +3,6 @@
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable } from "@ogre-tools/injectable";
import { lensWindowInjectionToken } from "../application-window/lens-window-injection-token";
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";
@@ -30,8 +29,6 @@ const splashWindowInjectable = getInjectable({
centered: true,
});
},
injectionToken: lensWindowInjectionToken,
});
export default splashWindowInjectable;
@@ -12,13 +12,12 @@ import { onLoadOfApplicationInjectionToken } from "./runnable-tokens/on-load-of-
import { afterApplicationIsLoadedInjectionToken } from "./runnable-tokens/after-application-is-loaded-injection-token";
import splashWindowInjectable from "./lens-window/splash-window/splash-window.injectable";
import applicationWindowInjectable from "./lens-window/application-window/application-window.injectable";
import shouldStartHiddenInjectable from "../electron-app/features/should-start-hidden.injectable";
import openDeepLinkInjectable from "../protocol-handler/lens-protocol-router-main/open-deep-link-for-url/open-deep-link.injectable";
import { pipeline } from "@ogre-tools/fp";
import { find, map, startsWith, toLower } from "lodash/fp";
import commandLineArgumentsInjectable from "../utils/command-line-arguments.injectable";
import waitForElectronToBeReadyInjectable from "../electron-app/features/wait-for-electron-to-be-ready.injectable";
import createFirstApplicationWindowInjectable from "./lens-window/application-window/create-first-application-window.injectable";
const startMainApplicationInjectable = getInjectable({
id: "start-main-application",
@@ -27,9 +26,8 @@ const startMainApplicationInjectable = getInjectable({
const runMany = runManyFor(di);
const runManySync = runManySyncFor(di);
const waitForElectronToBeReady = di.inject(waitForElectronToBeReadyInjectable);
const applicationWindow = di.inject(applicationWindowInjectable);
const createFirstApplicationWindow = di.inject(createFirstApplicationWindowInjectable);
const splashWindow = di.inject(splashWindowInjectable);
const shouldStartHidden = di.inject(shouldStartHiddenInjectable);
const openDeepLink = di.inject(openDeepLinkInjectable);
const commandLineArguments = di.inject(commandLineArgumentsInjectable);
@@ -38,7 +36,7 @@ const startMainApplicationInjectable = getInjectable({
const onLoadOfApplication = runMany(onLoadOfApplicationInjectionToken);
const afterApplicationIsLoaded = runMany(afterApplicationIsLoadedInjectionToken);
return () => {
return (shouldStartWindow: boolean) => {
// Stuff happening before application is ready needs to be synchronous because of
// https://github.com/electron/electron/issues/21370
beforeElectronIsReady();
@@ -48,18 +46,20 @@ const startMainApplicationInjectable = getInjectable({
await beforeApplicationIsLoading();
if (!shouldStartHidden) {
if (shouldStartWindow) {
await splashWindow.start();
}
await onLoadOfApplication();
if (!shouldStartHidden) {
if (shouldStartWindow) {
const deepLinkUrl = getDeepLinkUrl(commandLineArguments);
if (deepLinkUrl) {
await openDeepLink(deepLinkUrl);
} else {
const applicationWindow = createFirstApplicationWindow();
await applicationWindow.start();
}
@@ -5,15 +5,10 @@
import type { MessageToChannel } from "../../../common/utils/channel/message-to-channel-injection-token";
import { messageToChannelInjectionToken } from "../../../common/utils/channel/message-to-channel-injection-token";
import closeAllWindowsInjectable from "../../start-main-application/lens-window/hide-all-windows/close-all-windows.injectable";
import type { MessageChannel } from "../../../common/utils/channel/message-channel-injection-token";
import { getDiForUnitTesting } from "../../getDiForUnitTesting";
import createLensWindowInjectable from "../../start-main-application/lens-window/application-window/create-lens-window.injectable";
import type { LensWindow } from "../../start-main-application/lens-window/application-window/lens-window-injection-token";
import { lensWindowInjectionToken } from "../../start-main-application/lens-window/application-window/lens-window-injection-token";
import type { DiContainer } from "@ogre-tools/injectable";
import { getInjectable } from "@ogre-tools/injectable";
import type { LensWindow } from "../../start-main-application/lens-window/application-window/create-lens-window.injectable";
import sendToChannelInElectronBrowserWindowInjectable from "../../start-main-application/lens-window/application-window/send-to-channel-in-electron-browser-window.injectable";
import { getApplicationBuilder } from "../../../renderer/components/test-utils/get-application-builder";
describe("message to channel from main", () => {
let messageToChannel: MessageToChannel;
@@ -21,20 +16,21 @@ describe("message to channel from main", () => {
let someOtherTestWindow: LensWindow;
let sendToChannelInBrowserMock: jest.Mock;
beforeEach(() => {
const di = getDiForUnitTesting({ doGeneralOverrides: true });
beforeEach(async () => {
const builder = getApplicationBuilder();
sendToChannelInBrowserMock = jest.fn();
di.override(sendToChannelInElectronBrowserWindowInjectable, () => sendToChannelInBrowserMock);
someTestWindow = createTestWindow(di, "some-test-window-id");
someOtherTestWindow = createTestWindow(di, "some-other-test-window-id");
builder.beforeApplicationStart(mainDi => {
mainDi.override(sendToChannelInElectronBrowserWindowInjectable, () => sendToChannelInBrowserMock);
});
messageToChannel = di.inject(messageToChannelInjectionToken);
await builder.startHidden();
const closeAllWindows = di.inject(closeAllWindowsInjectable);
someTestWindow = builder.applicationWindow.create("some-test-window-id");
someOtherTestWindow = builder.applicationWindow.create("some-other-test-window-id");
closeAllWindows();
messageToChannel = builder.mainDi.inject(messageToChannelInjectionToken);
});
it("given no visible windows, when messaging to channel, does not message to any window", () => {
@@ -53,6 +49,8 @@ describe("message to channel from main", () => {
expect(sendToChannelInBrowserMock.mock.calls).toEqual([
[
"some-test-window-id",
null,
{
@@ -68,6 +66,8 @@ describe("message to channel from main", () => {
expect(sendToChannelInBrowserMock.mock.calls).toEqual([
[
"some-test-window-id",
null,
{
@@ -83,6 +83,8 @@ describe("message to channel from main", () => {
expect(sendToChannelInBrowserMock.mock.calls).toEqual([
[
"some-test-window-id",
null,
{
@@ -98,6 +100,8 @@ describe("message to channel from main", () => {
expect(sendToChannelInBrowserMock.mock.calls).toEqual([
[
"some-test-window-id",
null,
{
@@ -117,6 +121,8 @@ describe("message to channel from main", () => {
expect(sendToChannelInBrowserMock.mock.calls).toEqual([
[
"some-test-window-id",
null,
{
@@ -126,6 +132,8 @@ describe("message to channel from main", () => {
],
[
"some-other-test-window-id",
null,
{
@@ -138,30 +146,3 @@ describe("message to channel from main", () => {
});
const someChannel: MessageChannel<any> = { id: "some-channel" };
const createTestWindow = (di: DiContainer, id: string) => {
const testWindowInjectable = getInjectable({
id,
instantiate: (di) => {
const createLensWindow = di.inject(createLensWindowInjectable);
return createLensWindow({
id,
title: "Some test window",
defaultHeight: 42,
defaultWidth: 42,
getContentSource: () => ({ url: "some-content-url" }),
resizable: true,
windowFrameUtilitiesAreShown: false,
centered: false,
});
},
injectionToken: lensWindowInjectionToken,
});
di.register(testWindowInjectable);
return di.inject(testWindowInjectable);
};