From 0d41eabb64d5a515c4bdd2533c12beafa14396f3 Mon Sep 17 00:00:00 2001 From: Janne Savolainen Date: Thu, 28 Apr 2022 10:35:01 +0300 Subject: [PATCH] Extract tray icon path as injectable Co-authored-by: Mikko Aspiala Signed-off-by: Janne Savolainen --- src/main/tray/tray-icon-path.injectable.ts | 26 ++++++++++++++++++++++ src/main/tray/tray.injectable.ts | 3 +++ 2 files changed, 29 insertions(+) create mode 100644 src/main/tray/tray-icon-path.injectable.ts 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..5195b31395 --- /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 isDevelopmentInjectable from "../../common/vars/is-development.injectable"; +import staticFilesDirectoryInjectable from "../../common/vars/static-files-directory.injectable"; + +const trayIconPathInjectable = getInjectable({ + id: "tray-icon-path", + + instantiate: (di) => { + const getAbsolutePath = di.inject(getAbsolutePathInjectable); + const isDevelopment = di.inject(isDevelopmentInjectable); + const staticDir = di.inject(staticFilesDirectoryInjectable); + + return getAbsolutePath( + staticDir, + 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 89ffebe2c4..6e92437b24 100644 --- a/src/main/tray/tray.injectable.ts +++ b/src/main/tray/tray.injectable.ts @@ -10,6 +10,7 @@ import navigateToPreferencesInjectable from "../../common/front-end-routing/rout import stopServicesAndExitAppInjectable from "../stop-services-and-exit-app.injectable"; import { getStartableStoppable } from "../../common/utils/get-startable-stoppable"; import isAutoUpdateEnabledInjectable from "../is-auto-update-enabled.injectable"; +import trayIconPathInjectable from "./tray-icon-path.injectable"; const trayInjectable = getInjectable({ id: "tray", @@ -20,6 +21,7 @@ const trayInjectable = getInjectable({ const navigateToPreferences = di.inject(navigateToPreferencesInjectable); const stopServicesAndExitApp = di.inject(stopServicesAndExitAppInjectable); const isAutoUpdateEnabled = di.inject(isAutoUpdateEnabledInjectable); + const trayIconPath = di.inject(trayIconPathInjectable); return getStartableStoppable("build-of-tray", () => initTray( @@ -28,6 +30,7 @@ const trayInjectable = getInjectable({ navigateToPreferences, stopServicesAndExitApp, isAutoUpdateEnabled, + trayIconPath, ), ); },