diff --git a/src/features/cluster/sidebar-and-tab-navigation-for-core.test.tsx b/src/features/cluster/sidebar-and-tab-navigation-for-core.test.tsx index 26f0bb253b..a4995c38ae 100644 --- a/src/features/cluster/sidebar-and-tab-navigation-for-core.test.tsx +++ b/src/features/cluster/sidebar-and-tab-navigation-for-core.test.tsx @@ -7,7 +7,6 @@ import { getInjectable } from "@ogre-tools/injectable"; import React from "react"; import type { RenderResult } from "@testing-library/react"; import { fireEvent } from "@testing-library/react"; -import directoryForLensLocalStorageInjectable from "../../common/directory-for-lens-local-storage/directory-for-lens-local-storage.injectable"; import { routeSpecificComponentInjectionToken } from "../../renderer/routes/route-specific-component-injection-token"; import type { SidebarItemRegistration } from "../../renderer/components/layout/sidebar-items.injectable"; import { sidebarItemsInjectionToken } from "../../renderer/components/layout/sidebar-items.injectable"; @@ -38,11 +37,6 @@ describe("cluster - sidebar and tab navigation for core", () => { builder.beforeWindowStart((windowDi) => { windowDi.override(storageSaveDelayInjectable, () => 250); - - windowDi.override( - directoryForLensLocalStorageInjectable, - () => "/some-directory-for-lens-local-storage", - ); }); }); @@ -96,7 +90,7 @@ describe("cluster - sidebar and tab navigation for core", () => { const writeJsonFile = windowDi.inject(writeJsonFileInjectable); await writeJsonFile( - "/some-directory-for-lens-local-storage/some-cluster-id.json", + "/some-directory-for-app-data/some-product-name/lens-local-storage/some-cluster-id.json", { sidebar: { expanded: { "some-parent-id": true }, @@ -132,7 +126,7 @@ describe("cluster - sidebar and tab navigation for core", () => { const writeJsonFileFake = windowDi.inject(writeJsonFileInjectable); await writeJsonFileFake( - "/some-directory-for-lens-local-storage/some-hosted-cluster-id.json", + "/some-directory-for-app-data/some-product-name/lens-local-storage/some-hosted-cluster-id.json", { sidebar: { expanded: { "some-unknown-parent-id": true }, @@ -162,7 +156,7 @@ describe("cluster - sidebar and tab navigation for core", () => { const writeJsonFileFake = windowDi.inject(writeJsonFileInjectable); await writeJsonFileFake( - "/some-directory-for-lens-local-storage/some-hosted-cluster-id.json", + "/some-directory-for-app-data/some-product-name/lens-local-storage/some-hosted-cluster-id.json", { someThingButSidebar: {}, }, @@ -268,7 +262,7 @@ describe("cluster - sidebar and tab navigation for core", () => { const pathExistsFake = windowDi.inject(pathExistsInjectable); const actual = await pathExistsFake( - "/some-directory-for-lens-local-storage/some-hosted-cluster-id.json", + "/some-directory-for-app-data/some-product-name/lens-local-storage/some-hosted-cluster-id.json", ); expect(actual).toBe(false); @@ -282,7 +276,7 @@ describe("cluster - sidebar and tab navigation for core", () => { await flushPromises(); const actual = await readJsonFileFake( - "/some-directory-for-lens-local-storage/some-cluster-id.json", + "/some-directory-for-app-data/some-product-name/lens-local-storage/some-cluster-id.json", ); expect(actual).toEqual({ diff --git a/src/main/app-paths/get-electron-app-path/get-electron-app-path.injectable.ts b/src/main/app-paths/get-electron-app-path/get-electron-app-path.injectable.ts index 057c22c860..b4423f5367 100644 --- a/src/main/app-paths/get-electron-app-path/get-electron-app-path.injectable.ts +++ b/src/main/app-paths/get-electron-app-path/get-electron-app-path.injectable.ts @@ -3,15 +3,29 @@ * Licensed under MIT License. See LICENSE in root directory for more information. */ import { getInjectable } from "@ogre-tools/injectable"; +import type { PathName } from "../../../common/app-paths/app-path-names"; import electronAppInjectable from "../../electron-app/electron-app.injectable"; -import { getElectronAppPath } from "./get-electron-app-path"; + +export type GetElectronAppPath = (name: PathName | "currentApp") => string; const getElectronAppPathInjectable = getInjectable({ id: "get-electron-app-path", - instantiate: (di) => getElectronAppPath({ - app: di.inject(electronAppInjectable), - }), + instantiate: (di): GetElectronAppPath => { + const electronApp = di.inject(electronAppInjectable); + + return (name) => { + try { + if (name === "currentApp") { + return electronApp.getAppPath(); + } + + return electronApp.getPath(name); + } catch (e) { + return ""; + } + }; + }, }); export default getElectronAppPathInjectable; diff --git a/src/main/app-paths/get-electron-app-path/get-electron-app-path.ts b/src/main/app-paths/get-electron-app-path/get-electron-app-path.ts deleted file mode 100644 index 45a6058d61..0000000000 --- a/src/main/app-paths/get-electron-app-path/get-electron-app-path.ts +++ /dev/null @@ -1,28 +0,0 @@ -/** - * Copyright (c) OpenLens Authors. All rights reserved. - * Licensed under MIT License. See LICENSE in root directory for more information. - */ -import type { App } from "electron"; -import type { PathName } from "../../../common/app-paths/app-path-names"; - -interface Dependencies { - app: App; -} - -export type GetElectronAppPath = (name: PathName | "currentApp") => string; - -export const getElectronAppPath = ({ - app, -}: Dependencies): GetElectronAppPath => ( - (name) => { - try { - if (name === "currentApp") { - return app.getAppPath(); - } - - return app.getPath(name); - } catch (e) { - return ""; - } - } -); diff --git a/src/main/app-paths/set-electron-app-path/set-electron-app-path.injectable.ts b/src/main/app-paths/set-electron-app-path/set-electron-app-path.injectable.ts index 73090956d3..2a4bac2330 100644 --- a/src/main/app-paths/set-electron-app-path/set-electron-app-path.injectable.ts +++ b/src/main/app-paths/set-electron-app-path/set-electron-app-path.injectable.ts @@ -6,11 +6,16 @@ import { getInjectable } from "@ogre-tools/injectable"; import type { PathName } from "../../../common/app-paths/app-path-names"; import electronAppInjectable from "../../electron-app/electron-app.injectable"; +export type SetElectronAppPath = (name: PathName, path: string) => void; + const setElectronAppPathInjectable = getInjectable({ id: "set-electron-app-path", - instantiate: (di) => (name: PathName, path: string) : void => - di.inject(electronAppInjectable).setPath(name, path), + instantiate: (di): SetElectronAppPath => { + const electronApp = di.inject(electronAppInjectable); + + return (name, path) => electronApp.setPath(name, path); + }, }); export default setElectronAppPathInjectable; diff --git a/src/main/app-paths/setup-app-paths.injectable.ts b/src/main/app-paths/setup-app-paths.injectable.ts index c48b35fba9..0b3c67b60f 100644 --- a/src/main/app-paths/setup-app-paths.injectable.ts +++ b/src/main/app-paths/setup-app-paths.injectable.ts @@ -21,7 +21,7 @@ const setupAppPathsInjectable = getInjectable({ instantiate: (di) => { const setElectronAppPath = di.inject(setElectronAppPathInjectable); const appName = di.inject(appNameInjectable); - const getAppPath = di.inject(getElectronAppPathInjectable); + const getElectronAppPath = di.inject(getElectronAppPathInjectable); const appPathsState = di.inject(appPathsStateInjectable); const directoryForIntegrationTesting = di.inject(directoryForIntegrationTestingInjectable); const joinPaths = di.inject(joinPathsInjectable); @@ -33,13 +33,13 @@ const setupAppPathsInjectable = getInjectable({ setElectronAppPath("appData", directoryForIntegrationTesting); } - const appDataPath = getAppPath("appData"); + const appDataPath = getElectronAppPath("appData"); setElectronAppPath("userData", joinPaths(appDataPath, appName)); const appPaths = pipeline( pathNames, - map(name => [name, getAppPath(name)]), + map(name => [name, getElectronAppPath(name)]), fromPairs, ) as AppPaths; diff --git a/src/main/electron-app/electron-app.global-override-for-injectable.ts b/src/main/electron-app/electron-app.global-override-for-injectable.ts index 3d111cac57..5f81e8298b 100644 --- a/src/main/electron-app/electron-app.global-override-for-injectable.ts +++ b/src/main/electron-app/electron-app.global-override-for-injectable.ts @@ -3,21 +3,32 @@ * Licensed under MIT License. See LICENSE in root directory for more information. */ +import { kebabCase } from "lodash"; import { getGlobalOverride } from "../../common/test-utils/get-global-override"; import electronAppInjectable from "./electron-app.injectable"; export default getGlobalOverride(electronAppInjectable, () => { + const commandLineArgs: string[] = []; + const chromiumArgs = new Map(); + const appPaths = new Map(); + const app = ({ getVersion: () => "6.0.0", setLoginItemSettings: () => { }, on: () => app, + whenReady: async () => {}, + getPath: (name) => appPaths.get(name) ?? `/some-directory-for-${kebabCase(name)}`, + setPath: (name, value) => appPaths.set(name, value), + getAppPath: () => "/some-path-to-the-applcation-binary", + focus: () => {}, commandLine: { - appendArgument: () => {}, - appendSwitch: () => {}, - getSwitchValue: () => "", - hasSwitch: () => false, - removeSwitch: () => {}, + appendArgument: (value) => commandLineArgs.push(value), + appendSwitch: (key, value) => chromiumArgs.set(key, value), + getSwitchValue: (key) => chromiumArgs.get(key), + hasSwitch: (key) => chromiumArgs.has(key), + removeSwitch: (key) => chromiumArgs.delete(key), }, + exit: () => {}, } as Partial as Electron.App); return app; diff --git a/src/main/electron-app/features/focus-application.injectable.ts b/src/main/electron-app/features/focus-application.injectable.ts index 4d3afd146f..3e4c4c1b5c 100644 --- a/src/main/electron-app/features/focus-application.injectable.ts +++ b/src/main/electron-app/features/focus-application.injectable.ts @@ -15,8 +15,6 @@ const focusApplicationInjectable = getInjectable({ electronApp.focus({ steal: true }); }; }, - - causesSideEffects: true, }); export default focusApplicationInjectable; diff --git a/src/main/electron-app/features/native-theme.global-override-for-injectable.ts b/src/main/electron-app/features/native-theme.global-override-for-injectable.ts new file mode 100644 index 0000000000..47c957c722 --- /dev/null +++ b/src/main/electron-app/features/native-theme.global-override-for-injectable.ts @@ -0,0 +1,16 @@ +/** + * Copyright (c) OpenLens Authors. All rights reserved. + * Licensed under MIT License. See LICENSE in root directory for more information. + */ + +import EventEmitter from "events"; +import { getGlobalOverride } from "../../../common/test-utils/get-global-override"; +import nativeThemeInjectable from "./native-theme.injectable"; + +export default getGlobalOverride(nativeThemeInjectable, () => Object.assign(new EventEmitter(), { + shouldUseDarkColors: true, + inForcedColorsMode: true, + shouldUseHighContrastColors: false, + shouldUseInvertedColorScheme: false, + themeSource: "dark" as const, +})); diff --git a/src/main/getDiForUnitTesting.ts b/src/main/getDiForUnitTesting.ts index b3fd0918a1..a0f5bc7620 100644 --- a/src/main/getDiForUnitTesting.ts +++ b/src/main/getDiForUnitTesting.ts @@ -3,7 +3,7 @@ * Licensed under MIT License. See LICENSE in root directory for more information. */ -import { kebabCase, chunk } from "lodash/fp"; +import { chunk } from "lodash/fp"; import type { DiContainer, Injectable } from "@ogre-tools/injectable"; import { createContainer, isInjectable, getInjectable } from "@ogre-tools/injectable"; import { Environments, setLegacyGlobalDiForExtensionApi } from "../extensions/as-legacy-globals-for-extension-api/legacy-global-di-for-extension-api"; @@ -17,13 +17,9 @@ import setupLensProxyInjectable from "./start-main-application/runnables/setup-l import setupSyncingOfWeblinksInjectable from "./start-main-application/runnables/setup-syncing-of-weblinks.injectable"; import stopServicesAndExitAppInjectable from "./stop-services-and-exit-app.injectable"; import setupDeepLinkingInjectable from "./electron-app/runnables/setup-deep-linking.injectable"; -import exitAppInjectable from "./electron-app/features/exit-app.injectable"; -import getCommandLineSwitchInjectable from "./electron-app/features/get-command-line-switch.injectable"; import requestSingleInstanceLockInjectable from "./electron-app/features/request-single-instance-lock.injectable"; import disableHardwareAccelerationInjectable from "./electron-app/features/disable-hardware-acceleration.injectable"; import shouldStartHiddenInjectable from "./electron-app/features/should-start-hidden.injectable"; -import getElectronAppPathInjectable from "./app-paths/get-electron-app-path/get-electron-app-path.injectable"; -import setElectronAppPathInjectable from "./app-paths/set-electron-app-path/set-electron-app-path.injectable"; import setupMainWindowVisibilityAfterActivationInjectable from "./electron-app/runnables/setup-main-window-visibility-after-activation.injectable"; import setupDeviceShutdownInjectable from "./electron-app/runnables/setup-device-shutdown.injectable"; import setupApplicationNameInjectable from "./electron-app/runnables/setup-application-name.injectable"; @@ -32,10 +28,7 @@ import showMessagePopupInjectable from "./electron-app/features/show-message-pop import clusterFramesInjectable from "../common/cluster-frames.injectable"; import type { ClusterFrameInfo } from "../common/cluster-frames"; import { observable, runInAction } from "mobx"; -import waitForElectronToBeReadyInjectable from "./electron-app/features/wait-for-electron-to-be-ready.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"; import platformInjectable from "../common/vars/platform.injectable"; import electronQuitAndInstallUpdateInjectable from "./electron-app/features/electron-quit-and-install-update.injectable"; import electronUpdaterIsActiveInjectable from "./electron-app/features/electron-updater-is-active.injectable"; @@ -46,7 +39,6 @@ import normalizedPlatformArchitectureInjectable from "../common/vars/normalized- import waitUntilBundledExtensionsAreLoadedInjectable from "./start-main-application/lens-window/application-window/wait-until-bundled-extensions-are-loaded.injectable"; import { registerMobX } from "@ogre-tools/injectable-extension-for-mobx"; import electronInjectable from "./utils/resolve-system-proxy/electron.injectable"; -import focusApplicationInjectable from "./electron-app/features/focus-application.injectable"; import kubectlDownloadingNormalizedArchInjectable from "./kubectl/normalized-arch.injectable"; import initializeClusterManagerInjectable from "./cluster/initialize-manager.injectable"; import type { GlobalOverride } from "../common/test-utils/get-global-override"; @@ -163,24 +155,11 @@ const overrideElectronFeatures = (di: DiContainer) => { })); }); - di.override(exitAppInjectable, () => () => {}); - di.override(getCommandLineSwitchInjectable, () => () => "irrelevant"); di.override(requestSingleInstanceLockInjectable, () => () => true); di.override(disableHardwareAccelerationInjectable, () => () => {}); di.override(shouldStartHiddenInjectable, () => false); di.override(showMessagePopupInjectable, () => () => {}); - di.override(waitForElectronToBeReadyInjectable, () => () => Promise.resolve()); - di.override(getElectronThemeInjectable, () => () => "dark"); - di.override(syncThemeFromOperatingSystemInjectable, () => ({ start: () => {}, stop: () => {} })); di.override(electronQuitAndInstallUpdateInjectable, () => () => {}); di.override(setUpdateOnQuitInjectable, () => () => {}); - di.override(focusApplicationInjectable, () => () => {}); - - di.override( - getElectronAppPathInjectable, - () => (name: string) => `/some-electron-app-path-for-${kebabCase(name)}`, - ); - - di.override(setElectronAppPathInjectable, () => () => {}); di.override(electronUpdaterIsActiveInjectable, () => false); }; diff --git a/src/renderer/getDiForUnitTesting.tsx b/src/renderer/getDiForUnitTesting.tsx index c6572f365b..1c3dde2fe4 100644 --- a/src/renderer/getDiForUnitTesting.tsx +++ b/src/renderer/getDiForUnitTesting.tsx @@ -20,7 +20,6 @@ import startTopbarStateSyncInjectable from "./components/layout/top-bar/start-st import { registerMobX } from "@ogre-tools/injectable-extension-for-mobx"; import watchHistoryStateInjectable from "./remote-helpers/watch-history-state.injectable"; import legacyOnChannelListenInjectable from "./ipc/legacy-channel-listen.injectable"; -import storageSaveDelayInjectable from "./utils/create-storage/storage-save-delay.injectable"; import environmentVariablesInjectable from "../common/utils/environment-variables.injectable"; import type { GlobalOverride } from "../common/test-utils/get-global-override"; import applicationInformationInjectable from "../common/vars/application-information-injectable"; @@ -83,8 +82,6 @@ export const getDiForUnitTesting = ( di.override(legacyOnChannelListenInjectable, () => () => noop); - di.override(storageSaveDelayInjectable, () => 0); - di.override(requestAnimationFrameInjectable, () => (callback) => callback()); di.override(lensResourcesDirInjectable, () => "/irrelevant"); di.override(environmentVariablesInjectable, () => ({})); diff --git a/src/renderer/utils/create-storage/storage-save-delay.global-override-for-injectable.ts b/src/renderer/utils/create-storage/storage-save-delay.global-override-for-injectable.ts new file mode 100644 index 0000000000..f6bcc97ab0 --- /dev/null +++ b/src/renderer/utils/create-storage/storage-save-delay.global-override-for-injectable.ts @@ -0,0 +1,9 @@ +/** + * 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 storageSaveDelayInjectable from "./storage-save-delay.injectable"; + +export default getGlobalOverride(storageSaveDelayInjectable, () => 0);