diff --git a/src/main/app-updater.ts b/src/main/app-updater.ts index 0b7a5609b8..5d2147923c 100644 --- a/src/main/app-updater.ts +++ b/src/main/app-updater.ts @@ -44,9 +44,8 @@ autoUpdater.logger = { /** * starts the automatic update checking - * @param interval milliseconds between interval to check on, defaults to 24h */ -export const startUpdateChecking = once(function (interval = 1000 * 60 * 60 * 24): void { +export const startUpdateChecking = (isAutoUpdateEnabled : () => boolean) => once(function (interval = 1000 * 60 * 60 * 24): void { if (!isAutoUpdateEnabled() || isTestEnv) { return; } diff --git a/src/main/electron-app/get-command-line-switch.injectable.ts b/src/main/electron-app/get-command-line-switch.injectable.ts new file mode 100644 index 0000000000..f39adb624e --- /dev/null +++ b/src/main/electron-app/get-command-line-switch.injectable.ts @@ -0,0 +1,18 @@ +/** + * 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 electronAppInjectable from "./electron-app.injectable"; + +const getCommandLineSwitchInjectable = getInjectable({ + id: "get-command-line-switch", + + instantiate: (di) => { + const app = di.inject(electronAppInjectable); + + return (name: string) => app.commandLine.getSwitchValue(name); + }, +}); + +export default getCommandLineSwitchInjectable; diff --git a/src/main/getDiForUnitTesting.ts b/src/main/getDiForUnitTesting.ts index 8ac51beb51..514e4eeb7c 100644 --- a/src/main/getDiForUnitTesting.ts +++ b/src/main/getDiForUnitTesting.ts @@ -42,6 +42,8 @@ import whenSecondInstanceInjectable from "./electron-app/when-second-instance.in import whenSystemShutdownInjectable from "./electron-app/when-system-shutdown.injectable"; import exitAppInjectable from "./electron-app/exit-app.injectable"; import setApplicationNameInjectable from "./electron-app/set-application-name.injectable"; +import getCommandLineSwitchInjectable from "./electron-app/get-command-line-switch.injectable"; +import isAutoUpdateEnabledInjectable from "./is-auto-update-enabled.injectable"; export const getDiForUnitTesting = ( { doGeneralOverrides } = { doGeneralOverrides: false }, @@ -77,6 +79,8 @@ export const getDiForUnitTesting = ( di.override(whenSystemShutdownInjectable, () => () => {}); di.override(exitAppInjectable, () => () => {}); di.override(setApplicationNameInjectable, () => () => {}); + di.override(getCommandLineSwitchInjectable, () => () => "irrelevant"); + di.override(isAutoUpdateEnabledInjectable, () => () => false); // eslint-disable-next-line unused-imports/no-unused-vars-ts di.override(extensionsStoreInjectable, () => ({ isEnabled: ({ id, isBundled }) => false }) as ExtensionsStore); diff --git a/src/main/is-auto-update-enabled.injectable.ts b/src/main/is-auto-update-enabled.injectable.ts index 4a61318e46..c76bd27e45 100644 --- a/src/main/is-auto-update-enabled.injectable.ts +++ b/src/main/is-auto-update-enabled.injectable.ts @@ -3,11 +3,16 @@ * Licensed under MIT License. See LICENSE in root directory for more information. */ import { getInjectable } from "@ogre-tools/injectable"; -import { isAutoUpdateEnabled } from "./app-updater"; +import { isPublishConfigured } from "../common/vars"; +import { autoUpdater } from "electron-updater"; const isAutoUpdateEnabledInjectable = getInjectable({ id: "is-auto-update-enabled", - instantiate: () => isAutoUpdateEnabled, + + instantiate: () => () => { + return autoUpdater.isUpdaterActive() && isPublishConfigured; + }, + causesSideEffects: true, }); diff --git a/src/main/proxy-env.ts b/src/main/proxy-env.ts deleted file mode 100644 index b02044a30c..0000000000 --- a/src/main/proxy-env.ts +++ /dev/null @@ -1,27 +0,0 @@ -/** - * Copyright (c) OpenLens Authors. All rights reserved. - * Licensed under MIT License. See LICENSE in root directory for more information. - */ - -import { app } from "electron"; - -export function mangleProxyEnv() { - const switchValue = app.commandLine.getSwitchValue("proxy-server"); - - let httpsProxy = process.env.HTTPS_PROXY || process.env.HTTP_PROXY || ""; - - delete process.env.HTTPS_PROXY; - delete process.env.HTTP_PROXY; - - if (switchValue !== "") { - httpsProxy = switchValue; - } - - if (httpsProxy !== "") { - process.env.APP_HTTPS_PROXY = httpsProxy; - } - - if (app.commandLine.getSwitchValue("proxy-server") !== "") { - process.env.HTTPS_PROXY = app.commandLine.getSwitchValue("proxy-server"); - } -} diff --git a/src/main/start-main-application/before-application-is-ready/implementations/setup-proxy-env.injectable.ts b/src/main/start-main-application/before-application-is-ready/implementations/setup-proxy-env.injectable.ts index 05149366d8..608510b8e7 100644 --- a/src/main/start-main-application/before-application-is-ready/implementations/setup-proxy-env.injectable.ts +++ b/src/main/start-main-application/before-application-is-ready/implementations/setup-proxy-env.injectable.ts @@ -3,17 +3,39 @@ * Licensed under MIT License. See LICENSE in root directory for more information. */ import { getInjectable } from "@ogre-tools/injectable"; -import { mangleProxyEnv } from "../../../proxy-env"; import { beforeApplicationIsReadyInjectionToken } from "../before-application-is-ready-injection-token"; +import getCommandLineSwitchInjectable from "../../../electron-app/get-command-line-switch.injectable"; const setupProxyEnvInjectable = getInjectable({ id: "setup-proxy-env", - instantiate: () => ({ - run: () => { - mangleProxyEnv(); - }, - }), + instantiate: (di) => { + const getCommandLineSwitch = di.inject(getCommandLineSwitchInjectable); + + return { + run: () => { + const switchValue = getCommandLineSwitch("proxy-server"); + + let httpsProxy = + process.env.HTTPS_PROXY || process.env.HTTP_PROXY || ""; + + delete process.env.HTTPS_PROXY; + delete process.env.HTTP_PROXY; + + if (switchValue !== "") { + httpsProxy = switchValue; + } + + if (httpsProxy !== "") { + process.env.APP_HTTPS_PROXY = httpsProxy; + } + + if (getCommandLineSwitch("proxy-server") !== "") { + process.env.HTTPS_PROXY = getCommandLineSwitch("proxy-server"); + } + }, + }; + }, injectionToken: beforeApplicationIsReadyInjectionToken, }); diff --git a/src/main/start-main-application/on-root-frame-render/implementations/start-update-checking.injectable.ts b/src/main/start-main-application/on-root-frame-render/implementations/start-update-checking.injectable.ts index f305f36638..fbe53bba29 100644 --- a/src/main/start-main-application/on-root-frame-render/implementations/start-update-checking.injectable.ts +++ b/src/main/start-main-application/on-root-frame-render/implementations/start-update-checking.injectable.ts @@ -5,15 +5,21 @@ import { getInjectable } from "@ogre-tools/injectable"; import { onRootFrameRenderInjectionToken } from "../on-root-frame-render-injection-token"; import { startUpdateChecking } from "../../../app-updater"; +import isAutoUpdateEnabledInjectable from "../../../is-auto-update-enabled.injectable"; const startUpdateCheckingInjectable = getInjectable({ id: "start-update-checking", - instantiate: () => ({ - run: () => { - startUpdateChecking(); - }, - }), + instantiate: (di) => { + const isAutoUpdateEnabled = di.inject(isAutoUpdateEnabledInjectable); + + + return { + run: () => { + startUpdateChecking(isAutoUpdateEnabled)(); + }, + }; + }, causesSideEffects: true, diff --git a/src/main/tray/tray.injectable.ts b/src/main/tray/tray.injectable.ts index 175150d4da..185044cbf5 100644 --- a/src/main/tray/tray.injectable.ts +++ b/src/main/tray/tray.injectable.ts @@ -9,6 +9,7 @@ import trayMenuItemsInjectable from "./tray-menu-items.injectable"; import navigateToPreferencesInjectable from "../../common/front-end-routing/routes/preferences/navigate-to-preferences.injectable"; 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"; const trayInjectable = getInjectable({ id: "tray", @@ -18,6 +19,7 @@ const trayInjectable = getInjectable({ const trayMenuItems = di.inject(trayMenuItemsInjectable); const navigateToPreferences = di.inject(navigateToPreferencesInjectable); const stopServicesAndExitApp = di.inject(stopServicesAndExitAppInjectable); + const isAutoUpdateEnabled = di.inject(isAutoUpdateEnabledInjectable); return getStartableStoppable(() => initTray( @@ -25,6 +27,7 @@ const trayInjectable = getInjectable({ trayMenuItems, navigateToPreferences, stopServicesAndExitApp, + isAutoUpdateEnabled, ), ); }, diff --git a/src/main/tray/tray.ts b/src/main/tray/tray.ts index 6638c82cdc..631624e0fb 100644 --- a/src/main/tray/tray.ts +++ b/src/main/tray/tray.ts @@ -8,7 +8,7 @@ import { Menu, Tray } from "electron"; import type { IComputedValue } from "mobx"; import { autorun } from "mobx"; import { showAbout } from "../menu/menu"; -import { checkForUpdates, isAutoUpdateEnabled } from "../app-updater"; +import { checkForUpdates } from "../app-updater"; import type { WindowManager } from "../window-manager"; import logger from "../logger"; import { isDevelopment, isWindows, productName, staticFilesDirectory } from "../../common/vars"; @@ -35,6 +35,7 @@ export function initTray( trayMenuItems: IComputedValue, navigateToPreferences: () => void, stopServicesAndExitApp: () => void, + isAutoUpdateEnabled: () => boolean, ): Disposer { const icon = getTrayIconPath(); @@ -53,7 +54,7 @@ export function initTray( return disposer( autorun(() => { try { - const menu = createTrayMenu(windowManager, toJS(trayMenuItems.get()), navigateToPreferences, stopServicesAndExitApp); + const menu = createTrayMenu(windowManager, toJS(trayMenuItems.get()), navigateToPreferences, stopServicesAndExitApp, isAutoUpdateEnabled); tray.setContextMenu(menu); } catch (error) { @@ -82,6 +83,7 @@ function createTrayMenu( extensionTrayItems: TrayMenuRegistration[], navigateToPreferences: () => void, stopServicesAndExitApp: () => void, + isAutoUpdateEnabled: () => boolean, ): Menu { let template: Electron.MenuItemConstructorOptions[] = [ {