1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Temporary add manual update notification to Lens 5 users

Signed-off-by: Lauri Nevala <lauri.nevala@gmail.com>
This commit is contained in:
Lauri Nevala 2021-06-30 11:32:03 +03:00
parent aa86e5a41e
commit 32e245aa9c
3 changed files with 47 additions and 4 deletions

View File

@ -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];

View File

@ -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) {

View File

@ -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(
(
<div className="flex column gaps">
<b>Update Available</b>
<p>Version {updateInfo.version} of Lens IDE is available. Manual update is required. </p>
<p>To update, please download the new version of Lens IDE and install it manually. Do you want to download it now and quit?</p>
<div className="flex gaps row align-left box grow">
<Button light label="Yes" onClick={() => { open(`https://api.k8slens.dev/binaries/${binary}`); remote.app.exit();}} />
<Button active outlined label="No" onClick={() => notificationsStore.remove(notificationId)} />
</div>
</div>
),
{
id: notificationId
}
);
}
const listNamespacesForbiddenHandlerDisplayedAt = new Map<string, number>();
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,