From cf8dbad569e7aea92c9e143301c75e78ec8b686a Mon Sep 17 00:00:00 2001 From: Janne Savolainen Date: Fri, 1 Jul 2022 15:41:33 +0300 Subject: [PATCH] Start showing different tray icon when checking for updates Signed-off-by: Janne Savolainen --- .../installing-update-using-tray.test.ts | 28 ------------ .../installing-update.test.ts | 43 ++++++++++++++++++- ...ecking-for-updates-tray-icon.injectable.ts | 34 +++++++++++++++ 3 files changed, 76 insertions(+), 29 deletions(-) create mode 100644 src/main/application-update/tray-icons/checking-for-updates-tray-icon.injectable.ts diff --git a/src/behaviours/application-update/installing-update-using-tray.test.ts b/src/behaviours/application-update/installing-update-using-tray.test.ts index f0e46b448f..251cae45c8 100644 --- a/src/behaviours/application-update/installing-update-using-tray.test.ts +++ b/src/behaviours/application-update/installing-update-using-tray.test.ts @@ -14,15 +14,12 @@ import asyncFn from "@async-fn/jest"; import type { DownloadPlatformUpdate } from "../../main/application-update/download-platform-update/download-platform-update.injectable"; import downloadPlatformUpdateInjectable from "../../main/application-update/download-platform-update/download-platform-update.injectable"; import showApplicationWindowInjectable from "../../main/start-main-application/lens-window/show-application-window.injectable"; -import type { TrayIconPaths } from "../../main/tray/tray-icon-path.injectable"; -import trayIconPathsInjectable from "../../main/tray/tray-icon-path.injectable"; describe("installing update using tray", () => { let applicationBuilder: ApplicationBuilder; let checkForPlatformUpdatesMock: AsyncFnMock; let downloadPlatformUpdateMock: AsyncFnMock; let showApplicationWindowMock: jest.Mock; - let trayIconPaths: TrayIconPaths; beforeEach(() => { applicationBuilder = getApplicationBuilder(); @@ -46,7 +43,6 @@ describe("installing update using tray", () => { mainDi.override(electronUpdaterIsActiveInjectable, () => true); mainDi.override(publishIsConfiguredInjectable, () => true); - trayIconPaths = mainDi.inject(trayIconPathsInjectable); }); }); @@ -61,10 +57,6 @@ describe("installing update using tray", () => { expect(rendered.baseElement).toMatchSnapshot(); }); - it("should use the normal tray icon", () => { - expect(applicationBuilder.tray.getIconPath()).toBe(trayIconPaths.normal); - }); - it("user cannot install update yet", () => { expect(applicationBuilder.tray.get("install-update")).toBeNull(); }); @@ -80,10 +72,6 @@ describe("installing update using tray", () => { expect(showApplicationWindowMock).not.toHaveBeenCalled(); }); - it("should still use the normal tray icon", () => { - expect(applicationBuilder.tray.getIconPath()).toBe(trayIconPaths.normal); - }); - it("user cannot check for updates again", () => { expect( applicationBuilder.tray.get("check-for-updates")?.enabled, @@ -117,10 +105,6 @@ describe("installing update using tray", () => { expect(showApplicationWindowMock).toHaveBeenCalled(); }); - it("should still use the normal tray icon", () => { - expect(applicationBuilder.tray.getIconPath()).toBe(trayIconPaths.normal); - }); - it("user cannot install update", () => { expect(applicationBuilder.tray.get("install-update")).toBeNull(); }); @@ -156,10 +140,6 @@ describe("installing update using tray", () => { expect(showApplicationWindowMock).toHaveBeenCalled(); }); - it("should use the update available icon", () => { - expect(applicationBuilder.tray.getIconPath()).toBe(trayIconPaths.updateAvailable); - }); - it("user cannot check for updates again yet", () => { expect( applicationBuilder.tray.get("check-for-updates")?.enabled, @@ -199,10 +179,6 @@ describe("installing update using tray", () => { ).toBeNull(); }); - it("should revert to use the normal tray icon", () => { - expect(applicationBuilder.tray.getIconPath()).toBe(trayIconPaths.normal); - }); - it("user can check for updates again", () => { expect( applicationBuilder.tray.get("check-for-updates")?.enabled, @@ -231,10 +207,6 @@ describe("installing update using tray", () => { ).toBe("Install update some-version"); }); - it("should use the update available icon", () => { - expect(applicationBuilder.tray.getIconPath()).toBe(trayIconPaths.updateAvailable); - }); - it("user can check for updates again", () => { expect( applicationBuilder.tray.get("check-for-updates")?.enabled, diff --git a/src/behaviours/application-update/installing-update.test.ts b/src/behaviours/application-update/installing-update.test.ts index 46fe9aa1dc..2e10403ed8 100644 --- a/src/behaviours/application-update/installing-update.test.ts +++ b/src/behaviours/application-update/installing-update.test.ts @@ -17,6 +17,7 @@ import downloadPlatformUpdateInjectable from "../../main/application-update/down import setUpdateOnQuitInjectable from "../../main/electron-app/features/set-update-on-quit.injectable"; import processCheckingForUpdatesInjectable from "../../main/application-update/check-for-updates/process-checking-for-updates.injectable"; import { useFakeTime } from "../../common/test-utils/use-fake-time"; +import staticFilesDirectoryInjectable from "../../common/vars/static-files-directory.injectable"; describe("installing update", () => { let applicationBuilder: ApplicationBuilder; @@ -36,6 +37,8 @@ describe("installing update", () => { downloadPlatformUpdateMock = asyncFn(); setUpdateOnQuitMock = jest.fn(); + mainDi.override(staticFilesDirectoryInjectable, () => "/some-static-files-directory"); + mainDi.override(setUpdateOnQuitInjectable, () => setUpdateOnQuitMock); mainDi.override( @@ -65,13 +68,21 @@ describe("installing update", () => { beforeEach(async () => { rendered = await applicationBuilder.render(); - processCheckingForUpdates = applicationBuilder.dis.mainDi.inject(processCheckingForUpdatesInjectable); + processCheckingForUpdates = applicationBuilder.dis.mainDi.inject( + processCheckingForUpdatesInjectable, + ); }); it("renders", () => { expect(rendered.baseElement).toMatchSnapshot(); }); + it("shows normal tray icon", () => { + expect(applicationBuilder.tray.getIconPath()).toBe( + "/some-static-files-directory/icons/trayIconTemplate.png", + ); + }); + describe("when user checks for updates", () => { let processCheckingForUpdatesPromise: Promise; @@ -86,6 +97,12 @@ describe("installing update", () => { ); }); + it("shows tray icon for checking for updates", () => { + expect(applicationBuilder.tray.getIconPath()).toBe( + "/some-static-files-directory/icons/trayIconCheckingForUpdatesTemplate.png", + ); + }); + it("renders", () => { expect(rendered.baseElement).toMatchSnapshot(); }); @@ -99,6 +116,12 @@ describe("installing update", () => { await processCheckingForUpdatesPromise; }); + it("shows tray icon for normal", () => { + expect(applicationBuilder.tray.getIconPath()).toBe( + "/some-static-files-directory/icons/trayIconTemplate.png", + ); + }); + it("does not start downloading update", () => { expect(downloadPlatformUpdateMock).not.toHaveBeenCalled(); }); @@ -122,6 +145,12 @@ describe("installing update", () => { expect(downloadPlatformUpdateMock).toHaveBeenCalled(); }); + it("still shows tray icon for downloading", () => { + expect(applicationBuilder.tray.getIconPath()).toBe( + "/some-static-files-directory/icons/trayIconCheckingForUpdatesTemplate.png", + ); + }); + it("renders", () => { expect(rendered.baseElement).toMatchSnapshot(); }); @@ -135,6 +164,12 @@ describe("installing update", () => { expect(quitAndInstallUpdateMock).not.toHaveBeenCalled(); }); + it("still shows normal tray icon", () => { + expect(applicationBuilder.tray.getIconPath()).toBe( + "/some-static-files-directory/icons/trayIconTemplate.png", + ); + }); + it("renders", () => { expect(rendered.baseElement).toMatchSnapshot(); }); @@ -149,6 +184,12 @@ describe("installing update", () => { expect(quitAndInstallUpdateMock).not.toHaveBeenCalled(); }); + it("shows tray icon for update being available", () => { + expect(applicationBuilder.tray.getIconPath()).toBe( + "/some-static-files-directory/icons/trayIconUpdateAvailableTemplate.png", + ); + }); + it("renders", () => { expect(rendered.baseElement).toMatchSnapshot(); }); diff --git a/src/main/application-update/tray-icons/checking-for-updates-tray-icon.injectable.ts b/src/main/application-update/tray-icons/checking-for-updates-tray-icon.injectable.ts new file mode 100644 index 0000000000..5d22c98bba --- /dev/null +++ b/src/main/application-update/tray-icons/checking-for-updates-tray-icon.injectable.ts @@ -0,0 +1,34 @@ +/** + * 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 { computed } from "mobx"; +import getTrayIconPathInjectable from "../../tray/menu-icon/get-tray-icon-path.injectable"; +import { trayIconInjectionToken } from "../../tray/menu-icon/tray-icon-injection-token"; +import updatesAreBeingDiscoveredInjectable from "../../../common/application-update/updates-are-being-discovered/updates-are-being-discovered.injectable"; +import updateIsBeingDownloadedInjectable from "../../../common/application-update/update-is-being-downloaded/update-is-being-downloaded.injectable"; + +const checkingForUpdatesTrayIconInjectable = getInjectable({ + id: "checking-for-updates-tray-icon", + + instantiate: (di) => { + const getTrayIconPath = di.inject(getTrayIconPathInjectable); + const updatesAreBeingDiscovered = di.inject(updatesAreBeingDiscoveredInjectable); + const updateIsBeingDownloaded = di.inject(updateIsBeingDownloadedInjectable); + + return { + iconPath: getTrayIconPath("checking-for-updates"), + priority: 1, + shouldBeShown: computed( + () => + updatesAreBeingDiscovered.value.get() || + updateIsBeingDownloaded.value.get(), + ), + }; + }, + + injectionToken: trayIconInjectionToken, +}); + +export default checkingForUpdatesTrayIconInjectable;