mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Implement naive notifications for version updates
Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
This commit is contained in:
parent
52303b170b
commit
f939121ebf
@ -191,7 +191,7 @@ describe("installing update using tray", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("notifies the user that download is happening", () => {
|
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", () => {
|
it("user cannot check for updates again yet", () => {
|
||||||
|
|||||||
7
src/common/notification/notification-channel.ts
Normal file
7
src/common/notification/notification-channel.ts
Normal file
@ -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<string>("notification:message");
|
||||||
@ -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 electronUpdaterIsActiveInjectable from "./electron-app/features/electron-updater-is-active.injectable";
|
||||||
import publishIsConfiguredInjectable from "./update-app/publish-is-configured.injectable";
|
import publishIsConfiguredInjectable from "./update-app/publish-is-configured.injectable";
|
||||||
import checkForPlatformUpdatesInjectable from "./update-app/check-for-platform-updates.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 = {}) {
|
export function getDiForUnitTesting(opts: GetDiForUnitTestingOptions = {}) {
|
||||||
const {
|
const {
|
||||||
@ -222,6 +223,7 @@ const overrideElectronFeatures = (di: DiContainer) => {
|
|||||||
di.override(getElectronThemeInjectable, () => () => "dark");
|
di.override(getElectronThemeInjectable, () => () => "dark");
|
||||||
di.override(syncThemeFromOperatingSystemInjectable, () => ({ start: () => {}, stop: () => {} }));
|
di.override(syncThemeFromOperatingSystemInjectable, () => ({ start: () => {}, stop: () => {} }));
|
||||||
di.override(quitAndInstallUpdateInjectable, () => () => {});
|
di.override(quitAndInstallUpdateInjectable, () => () => {});
|
||||||
|
di.override(setUpdateOnQuitInjectable, () => () => {});
|
||||||
|
|
||||||
di.override(checkForPlatformUpdatesInjectable, () => () => {
|
di.override(checkForPlatformUpdatesInjectable, () => () => {
|
||||||
throw new Error("Tried to check for platform updates without explicit override.");
|
throw new Error("Tried to check for platform updates without explicit override.");
|
||||||
|
|||||||
@ -3,11 +3,19 @@
|
|||||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||||
*/
|
*/
|
||||||
import { getInjectable } from "@ogre-tools/injectable";
|
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({
|
const showNotificationInjectable = getInjectable({
|
||||||
id: "show-notification",
|
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;
|
export default showNotificationInjectable;
|
||||||
|
|||||||
@ -50,7 +50,7 @@ const checkForUpdatesTrayItemInjectable = getInjectable({
|
|||||||
const { updateWasDiscovered, version } = await versionUpdate.checkForUpdates();
|
const { updateWasDiscovered, version } = await versionUpdate.checkForUpdates();
|
||||||
|
|
||||||
if (updateWasDiscovered) {
|
if (updateWasDiscovered) {
|
||||||
showNotification(`Downloading update ${version}...`);
|
showNotification(`Download for version ${version} started...`);
|
||||||
|
|
||||||
// Note: intentional orphan promise to make download happen in the background
|
// Note: intentional orphan promise to make download happen in the background
|
||||||
versionUpdate.downloadUpdate().then(async () => {
|
versionUpdate.downloadUpdate().then(async () => {
|
||||||
|
|||||||
@ -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;
|
||||||
@ -44,6 +44,8 @@ import setupOnApiErrorListenersInjectable from "./api/setup-on-api-errors.inject
|
|||||||
import { observable } from "mobx";
|
import { observable } from "mobx";
|
||||||
import defaultShellInjectable from "./components/+preferences/default-shell.injectable";
|
import defaultShellInjectable from "./components/+preferences/default-shell.injectable";
|
||||||
import themeStoreInjectable from "./themes/store.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 = {}) => {
|
export const getDiForUnitTesting = (opts: GetDiForUnitTestingOptions = {}) => {
|
||||||
const {
|
const {
|
||||||
@ -120,6 +122,8 @@ export const getDiForUnitTesting = (opts: GetDiForUnitTestingOptions = {}) => {
|
|||||||
di.override(getValueFromRegisteredChannelInjectable, () => () => Promise.resolve(undefined as never));
|
di.override(getValueFromRegisteredChannelInjectable, () => () => Promise.resolve(undefined as never));
|
||||||
di.override(registerIpcChannelListenerInjectable, () => () => undefined);
|
di.override(registerIpcChannelListenerInjectable, () => () => undefined);
|
||||||
|
|
||||||
|
di.override(notificationListenerInjectable, () => ({ channel: notificationChannel, handle: () => {} }));
|
||||||
|
|
||||||
overrideFsWithFakes(di);
|
overrideFsWithFakes(di);
|
||||||
|
|
||||||
di.override(focusWindowInjectable, () => () => {});
|
di.override(focusWindowInjectable, () => () => {});
|
||||||
|
|||||||
@ -5,7 +5,6 @@
|
|||||||
import { getInjectionToken } from "@ogre-tools/injectable";
|
import { getInjectionToken } from "@ogre-tools/injectable";
|
||||||
import type { Channel } from "../../common/ipc-channel/channel";
|
import type { Channel } from "../../common/ipc-channel/channel";
|
||||||
|
|
||||||
|
|
||||||
export interface IpcChannelListener {
|
export interface IpcChannelListener {
|
||||||
channel: Channel<unknown>;
|
channel: Channel<unknown>;
|
||||||
handle: (value: any) => void;
|
handle: (value: any) => void;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user