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

Resolving comments

- removed console.log

- move to RenderButtons as function component

- explicitly only send notifications to main view

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton 2020-12-22 13:30:58 -05:00
parent 7f2ff980f8
commit 1d47de190d
4 changed files with 11 additions and 19 deletions

View File

@ -5,6 +5,7 @@ import { ipcMain } from "electron";
import { isDevelopment } from "../common/vars";
import { SemVer } from "semver";
import moment from "moment";
import { WindowManager } from "./window-manager";
function delay(duration: number): Promise<void> {
return new Promise(resolve => setTimeout(resolve, duration));
@ -20,7 +21,7 @@ class NotificationBackchannel {
const title = "Lens Updater";
async function autoUpdateCheck(args: UpdateInfo): Promise<void> {
async function autoUpdateCheck(windowManager: WindowManager): Promise<void> {
return new Promise(async resolve => {
const body = "Install and restart Lens?";
const yesNowChannel = NotificationBackchannel.nextId();
@ -55,8 +56,7 @@ async function autoUpdateCheck(args: UpdateInfo): Promise<void> {
resolve();
});
broadcastIpc({
channel: NotificationChannelAdd,
windowManager.mainView.webContents.send(NotificationChannelAdd, {
args: [{
title,
body,
@ -88,7 +88,7 @@ async function autoUpdateCheck(args: UpdateInfo): Promise<void> {
* starts the automatic update checking
* @param interval milliseconds between interval to check on, defaulkts to 24h
*/
export function startUpdateChecking(interval = 1000 * 60 * 60 * 24): void {
export function startUpdateChecking(windowManager: WindowManager, interval = 1000 * 60 * 60 * 24): void {
if (isDevelopment) {
return;
}
@ -100,8 +100,7 @@ export function startUpdateChecking(interval = 1000 * 60 * 60 * 24): void {
try {
const releaseDate = moment(args.releaseDate);
const body = `Version ${args.version} was release on ${releaseDate.format("dddd, mmmm dS, yyyy")}.`;
broadcastIpc({
channel: NotificationChannelAdd,
windowManager.mainView.webContents.send(NotificationChannelAdd, {
args: [{
title,
body,
@ -110,7 +109,7 @@ export function startUpdateChecking(interval = 1000 * 60 * 60 * 24): void {
}]
});
await autoUpdateCheck(args);
await autoUpdateCheck(windowManager);
} catch (error) {
logger.error("[UPDATE CHECKER]: notification failed", { error: String(error) })
}
@ -120,8 +119,7 @@ export function startUpdateChecking(interval = 1000 * 60 * 60 * 24): void {
const version = new SemVer(args.version);
const stream = version.prerelease === null ? "stable" : "prerelease";
const body = `Lens is running the latest ${stream} version.`;
broadcastIpc({
channel: NotificationChannelAdd,
windowManager.mainView.webContents.send(NotificationChannelAdd, {
args: [{
title,
body,

View File

@ -74,11 +74,7 @@ async function main() {
// create window manager and open app
windowManager = new WindowManager(proxyPort);
/**
* This depends on:
* 1. windowManager: it will send IPC to the main window for notifications
*/
startUpdateChecking();
startUpdateChecking(windowManager);
}
app.on("ready", main);

View File

@ -7,7 +7,7 @@ import { initMenu } from "./menu";
import { tracker } from "../common/tracker";
export class WindowManager {
protected mainView: BrowserWindow;
public readonly mainView: BrowserWindow;
protected splashWindow: BrowserWindow;
protected windowState: windowStateKeeper.State;

View File

@ -37,7 +37,7 @@ export interface MainNotification {
closeChannel?: IpcChannel;
}
function renderButtons(id: IpcChannel, buttons?: MainNotification["buttons"]): React.ReactNode {
function RenderButtons({ id, buttons }: { id: IpcChannel, buttons?: MainNotification["buttons"] }) {
if (!buttons) {
return null;
}
@ -48,7 +48,6 @@ function renderButtons(id: IpcChannel, buttons?: MainNotification["buttons"]): R
<div className="flex row align-right box grow">
{buttons.map(({ backchannel, ...props}) => (
<Button {...props} onClick={() => {
console.log(`sending to ${backchannel}`)
ipcRenderer.send(backchannel);
notificationsStore.remove(id);
}} />
@ -67,14 +66,13 @@ export class NotificationsStore {
registerIpcListener(): void {
logger.info(`[NOTIFICATION-STORE] start to listen for notifications requests from main`);
ipcRenderer.on(NotificationChannelAdd, (event, model: MainNotification) => {
console.log(model);
const id = uniqueId("notification_");
this.add({
message: (
<>
<b>{model.title}</b>
<p>{model.body}</p>
{renderButtons(id, model.buttons)}
<RenderButtons id={id} buttons={model.buttons}/>
</>
),
id,