From 32e245aa9c1381cfd6eb0489e2766dcc762fd2c9 Mon Sep 17 00:00:00 2001 From: Lauri Nevala Date: Wed, 30 Jun 2021 11:32:03 +0300 Subject: [PATCH] Temporary add manual update notification to Lens 5 users Signed-off-by: Lauri Nevala --- src/common/ipc/update-available.ipc.ts | 1 + src/main/app-updater.ts | 7 ++++- src/renderer/ipc/index.tsx | 43 ++++++++++++++++++++++++-- 3 files changed, 47 insertions(+), 4 deletions(-) diff --git a/src/common/ipc/update-available.ipc.ts b/src/common/ipc/update-available.ipc.ts index 87ec740f44..d2f6cf0603 100644 --- a/src/common/ipc/update-available.ipc.ts +++ b/src/common/ipc/update-available.ipc.ts @@ -22,6 +22,7 @@ import type { UpdateInfo } from "electron-updater"; export const UpdateAvailableChannel = "update-available"; +export const ManualUpdateAvailableChannel = "manual-update-available"; export const AutoUpdateLogPrefix = "[UPDATE-CHECKER]"; export type UpdateAvailableFromMain = [backChannel: string, updateInfo: UpdateInfo]; diff --git a/src/main/app-updater.ts b/src/main/app-updater.ts index 81dad52d02..bade034690 100644 --- a/src/main/app-updater.ts +++ b/src/main/app-updater.ts @@ -23,7 +23,7 @@ import { autoUpdater, UpdateInfo } from "electron-updater"; import logger from "./logger"; import { isDevelopment, isPublishConfigured, isTestEnv } from "../common/vars"; import { delay } from "../common/utils"; -import { areArgsUpdateAvailableToBackchannel, AutoUpdateLogPrefix, broadcastMessage, onceCorrect, UpdateAvailableChannel, UpdateAvailableToBackchannel } from "../common/ipc"; +import { areArgsUpdateAvailableToBackchannel, AutoUpdateLogPrefix, broadcastMessage, ManualUpdateAvailableChannel, onceCorrect, UpdateAvailableChannel, UpdateAvailableToBackchannel } from "../common/ipc"; import { once } from "lodash"; import { ipcMain } from "electron"; @@ -62,6 +62,11 @@ export const startUpdateChecking = once(function (interval = 1000 * 60 * 60 * 24 autoUpdater .on("update-available", (info: UpdateInfo) => { + // TODO remove this line and return on next version + broadcastMessage(ManualUpdateAvailableChannel, "", info); + + return; + if (autoUpdater.autoInstallOnAppQuit) { // a previous auto-update loop was completed with YES+LATER, check if same version if (installVersion === info.version) { diff --git a/src/renderer/ipc/index.tsx b/src/renderer/ipc/index.tsx index 338f71c38d..6e5aa727c8 100644 --- a/src/renderer/ipc/index.tsx +++ b/src/renderer/ipc/index.tsx @@ -20,14 +20,15 @@ */ import React from "react"; -import { ipcRenderer, IpcRendererEvent } from "electron"; -import { areArgsUpdateAvailableFromMain, UpdateAvailableChannel, onCorrect, UpdateAvailableFromMain, BackchannelArg, ClusterListNamespaceForbiddenChannel, isListNamespaceForbiddenArgs, ListNamespaceForbiddenArgs } from "../../common/ipc"; +import { ipcRenderer, IpcRendererEvent, remote } from "electron"; +import { areArgsUpdateAvailableFromMain, UpdateAvailableChannel, onCorrect, UpdateAvailableFromMain, BackchannelArg, ClusterListNamespaceForbiddenChannel, isListNamespaceForbiddenArgs, ListNamespaceForbiddenArgs, ManualUpdateAvailableChannel } from "../../common/ipc"; import { Notifications, notificationsStore } from "../components/notifications"; import { Button } from "../components/button"; -import { isMac } from "../../common/vars"; +import { isLinux, isMac, isWindows } from "../../common/vars"; import { ClusterStore } from "../../common/cluster-store"; import { navigate } from "../navigation"; import { entitySettingsURL } from "../../common/routes"; +import type { UpdateInfo } from "electron-updater"; function sendToBackchannel(backchannel: string, notificationId: string, data: BackchannelArg): void { notificationsStore.remove(notificationId); @@ -76,6 +77,36 @@ function UpdateAvailableHandler(event: IpcRendererEvent, ...[backchannel, update ); } +// eslint-disable-next-line unused-imports/no-unused-vars-ts +function ManualUpdateAvailableHandler(event: IpcRendererEvent, ...[_backchannel, updateInfo]: UpdateAvailableFromMain): void { + const notificationId = `manual-update-available:${updateInfo.version}`; + + let binary = "latest.dmg"; + + if (isWindows) { + binary = "latest.exe"; + } else if (isLinux) { + binary = "latest.x86_64.AppImage"; + } + + Notifications.info( + ( +
+ Update Available +

Version {updateInfo.version} of Lens IDE is available. Manual update is required.

+

To update, please download the new version of Lens IDE and install it manually. Do you want to download it now and quit?

+
+
+
+ ), + { + id: notificationId + } + ); +} + const listNamespacesForbiddenHandlerDisplayedAt = new Map(); const intervalBetweenNotifications = 1000 * 60; // 60s @@ -119,6 +150,12 @@ export function registerIpcHandlers() { listener: UpdateAvailableHandler, verifier: areArgsUpdateAvailableFromMain, }); + onCorrect({ + source: ipcRenderer, + channel: ManualUpdateAvailableChannel, + listener: ManualUpdateAvailableHandler, + verifier: (args: unknown[]): args is [backChannel: string, updateInfo: UpdateInfo] => true, + }); onCorrect({ source: ipcRenderer, channel: ClusterListNamespaceForbiddenChannel,