diff --git a/src/main/tray/tray-icon-path.injectable.ts b/src/main/tray/tray-icon-path.injectable.ts new file mode 100644 index 0000000000..1eb4d13118 --- /dev/null +++ b/src/main/tray/tray-icon-path.injectable.ts @@ -0,0 +1,26 @@ +/** + * 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 getAbsolutePathInjectable from "../../common/path/get-absolute-path.injectable"; +import staticFilesDirectoryInjectable from "../../common/vars/static-files-directory.injectable"; +import isDevelopmentInjectable from "../../common/vars/is-development.injectable"; + +const trayIconPathInjectable = getInjectable({ + id: "tray-icon-path", + + instantiate: (di) => { + const getAbsolutePath = di.inject(getAbsolutePathInjectable); + const staticFilesDirectory = di.inject(staticFilesDirectoryInjectable); + const isDevelopment = di.inject(isDevelopmentInjectable); + + return getAbsolutePath( + staticFilesDirectory, + isDevelopment ? "../build/tray" : "icons", // copied within electron-builder extras + "trayIconTemplate.png", + ); + }, +}); + +export default trayIconPathInjectable; diff --git a/src/main/tray/tray.injectable.ts b/src/main/tray/tray.injectable.ts index e8a0aac131..0e61062d50 100644 --- a/src/main/tray/tray.injectable.ts +++ b/src/main/tray/tray.injectable.ts @@ -11,6 +11,7 @@ import { getStartableStoppable } from "../../common/utils/get-startable-stoppabl import isAutoUpdateEnabledInjectable from "../is-auto-update-enabled.injectable"; import showAboutInjectable from "../menu/show-about.injectable"; import showApplicationWindowInjectable from "../start-main-application/lens-window/show-application-window.injectable"; +import trayIconPathInjectable from "./tray-icon-path.injectable"; const trayInjectable = getInjectable({ id: "tray", @@ -22,6 +23,7 @@ const trayInjectable = getInjectable({ const isAutoUpdateEnabled = di.inject(isAutoUpdateEnabledInjectable); const showApplicationWindow = di.inject(showApplicationWindowInjectable); const showAboutPopup = di.inject(showAboutInjectable); + const trayIconPath = di.inject(trayIconPathInjectable); return getStartableStoppable("build-of-tray", () => initTray( @@ -31,6 +33,7 @@ const trayInjectable = getInjectable({ isAutoUpdateEnabled, showApplicationWindow, showAboutPopup, + trayIconPath, ), ); }, diff --git a/src/main/tray/tray.ts b/src/main/tray/tray.ts index e8eb542eb9..e8b56b55cc 100644 --- a/src/main/tray/tray.ts +++ b/src/main/tray/tray.ts @@ -9,25 +9,16 @@ import type { IComputedValue } from "mobx"; import { autorun } from "mobx"; import { checkForUpdates } from "../app-updater"; import logger from "../logger"; -import { isDevelopment, isWindows, productName, staticFilesDirectory } from "../../common/vars"; +import { isWindows, productName } from "../../common/vars"; import type { Disposer } from "../../common/utils"; import { disposer, toJS } from "../../common/utils"; import type { TrayMenuRegistration } from "./tray-menu-registration"; -import path from "path"; const TRAY_LOG_PREFIX = "[TRAY]"; // note: instance of Tray should be saved somewhere, otherwise it disappears export let tray: Tray; -function getTrayIconPath(): string { - return path.resolve( - staticFilesDirectory, - isDevelopment ? "../build/tray" : "icons", // copied within electron-builder extras - "trayIconTemplate.png", - ); -} - export function initTray( trayMenuItems: IComputedValue, navigateToPreferences: () => void, @@ -35,10 +26,9 @@ export function initTray( isAutoUpdateEnabled: () => boolean, showApplicationWindow: () => Promise, showAbout: () => void, + trayIconPath: string, ): Disposer { - const icon = getTrayIconPath(); - - tray = new Tray(icon); + tray = new Tray(trayIconPath); tray.setToolTip(packageInfo.description); tray.setIgnoreDoubleClickEvents(true);