diff --git a/src/behaviours/update-app/installing-update-using-tray.test.ts b/src/behaviours/update-app/installing-update-using-tray.test.ts index 5f025eb4d7..ffdb22ecfd 100644 --- a/src/behaviours/update-app/installing-update-using-tray.test.ts +++ b/src/behaviours/update-app/installing-update-using-tray.test.ts @@ -191,7 +191,7 @@ describe("installing update using tray", () => { }); it("notifies the user that download is happening", () => { - expect(showNotificationMock).toHaveBeenCalledWith("Downloading update some-version..."); + expect(showNotificationMock).toHaveBeenCalledWith("Download for version some-version started..."); }); it("user cannot check for updates again yet", () => { diff --git a/src/common/notification/notification-channel.ts b/src/common/notification/notification-channel.ts new file mode 100644 index 0000000000..f09b7bf1f2 --- /dev/null +++ b/src/common/notification/notification-channel.ts @@ -0,0 +1,7 @@ +/** + * Copyright (c) OpenLens Authors. All rights reserved. + * Licensed under MIT License. See LICENSE in root directory for more information. + */ +import { createChannel } from "../ipc-channel/create-channel/create-channel"; + +export const notificationChannel = createChannel("notification:message"); diff --git a/src/main/getDiForUnitTesting.ts b/src/main/getDiForUnitTesting.ts index ef0ce97274..74e00db084 100644 --- a/src/main/getDiForUnitTesting.ts +++ b/src/main/getDiForUnitTesting.ts @@ -80,6 +80,7 @@ import quitAndInstallUpdateInjectable from "./electron-app/features/quit-and-ins import electronUpdaterIsActiveInjectable from "./electron-app/features/electron-updater-is-active.injectable"; import publishIsConfiguredInjectable from "./update-app/publish-is-configured.injectable"; import checkForPlatformUpdatesInjectable from "./update-app/check-for-platform-updates.injectable"; +import setUpdateOnQuitInjectable from "./electron-app/features/set-update-on-quit.injectable"; export function getDiForUnitTesting(opts: GetDiForUnitTestingOptions = {}) { const { @@ -222,6 +223,7 @@ const overrideElectronFeatures = (di: DiContainer) => { di.override(getElectronThemeInjectable, () => () => "dark"); di.override(syncThemeFromOperatingSystemInjectable, () => ({ start: () => {}, stop: () => {} })); di.override(quitAndInstallUpdateInjectable, () => () => {}); + di.override(setUpdateOnQuitInjectable, () => () => {}); di.override(checkForPlatformUpdatesInjectable, () => () => { throw new Error("Tried to check for platform updates without explicit override."); diff --git a/src/main/show-notification/show-notification.injectable.ts b/src/main/show-notification/show-notification.injectable.ts index e2bebdac4f..323323e184 100644 --- a/src/main/show-notification/show-notification.injectable.ts +++ b/src/main/show-notification/show-notification.injectable.ts @@ -3,11 +3,19 @@ * Licensed under MIT License. See LICENSE in root directory for more information. */ import { getInjectable } from "@ogre-tools/injectable"; +import applicationWindowInjectable from "../start-main-application/lens-window/application-window/application-window.injectable"; +import { notificationChannel } from "../../common/notification/notification-channel"; const showNotificationInjectable = getInjectable({ id: "show-notification", - instantiate: (di) => (message: string) => {}, + instantiate: (di) => { + const applicationWindow = di.inject(applicationWindowInjectable); + + return (message: string) => { + applicationWindow.send({ channel: notificationChannel.name, data: [message] }); + }; + }, }); export default showNotificationInjectable; diff --git a/src/main/update-app/check-for-updates-tray-item.injectable.ts b/src/main/update-app/check-for-updates-tray-item.injectable.ts index 2a8e4514fe..5a58a3026c 100644 --- a/src/main/update-app/check-for-updates-tray-item.injectable.ts +++ b/src/main/update-app/check-for-updates-tray-item.injectable.ts @@ -50,7 +50,7 @@ const checkForUpdatesTrayItemInjectable = getInjectable({ const { updateWasDiscovered, version } = await versionUpdate.checkForUpdates(); if (updateWasDiscovered) { - showNotification(`Downloading update ${version}...`); + showNotification(`Download for version ${version} started...`); // Note: intentional orphan promise to make download happen in the background versionUpdate.downloadUpdate().then(async () => { diff --git a/src/renderer/components/notifications/notification-listener.injectable.ts b/src/renderer/components/notifications/notification-listener.injectable.ts new file mode 100644 index 0000000000..bc606682d9 --- /dev/null +++ b/src/renderer/components/notifications/notification-listener.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 { ipcChannelListenerInjectionToken } from "../../ipc-channel-listeners/ipc-channel-listener-injection-token"; +import { notificationChannel } from "../../../common/notification/notification-channel"; +import { Notifications } from "./index"; + +const notificationListenerInjectable = getInjectable({ + id: "notification-listener", + + instantiate: () => ({ + channel: notificationChannel, + + handle: (message: string) => { + Notifications.shortInfo(message); + }, + }), + + causesSideEffects: true, + + injectionToken: ipcChannelListenerInjectionToken, +}); + +export default notificationListenerInjectable; diff --git a/src/renderer/getDiForUnitTesting.tsx b/src/renderer/getDiForUnitTesting.tsx index 77cb55c638..0208dec95f 100644 --- a/src/renderer/getDiForUnitTesting.tsx +++ b/src/renderer/getDiForUnitTesting.tsx @@ -44,6 +44,8 @@ import setupOnApiErrorListenersInjectable from "./api/setup-on-api-errors.inject import { observable } from "mobx"; import defaultShellInjectable from "./components/+preferences/default-shell.injectable"; import themeStoreInjectable from "./themes/store.injectable"; +import notificationListenerInjectable from "./components/notifications/notification-listener.injectable"; +import { notificationChannel } from "../common/notification/notification-channel"; export const getDiForUnitTesting = (opts: GetDiForUnitTestingOptions = {}) => { const { @@ -120,6 +122,8 @@ export const getDiForUnitTesting = (opts: GetDiForUnitTestingOptions = {}) => { di.override(getValueFromRegisteredChannelInjectable, () => () => Promise.resolve(undefined as never)); di.override(registerIpcChannelListenerInjectable, () => () => undefined); + di.override(notificationListenerInjectable, () => ({ channel: notificationChannel, handle: () => {} })); + overrideFsWithFakes(di); di.override(focusWindowInjectable, () => () => {}); diff --git a/src/renderer/ipc-channel-listeners/ipc-channel-listener-injection-token.ts b/src/renderer/ipc-channel-listeners/ipc-channel-listener-injection-token.ts index 235b90873c..ba14b38861 100644 --- a/src/renderer/ipc-channel-listeners/ipc-channel-listener-injection-token.ts +++ b/src/renderer/ipc-channel-listeners/ipc-channel-listener-injection-token.ts @@ -5,7 +5,6 @@ import { getInjectionToken } from "@ogre-tools/injectable"; import type { Channel } from "../../common/ipc-channel/channel"; - export interface IpcChannelListener { channel: Channel; handle: (value: any) => void;