diff --git a/src/main/app-updater.ts b/src/main/app-updater.ts index 328e7ea8a0..7a3b6caac6 100644 --- a/src/main/app-updater.ts +++ b/src/main/app-updater.ts @@ -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 { return new Promise(resolve => setTimeout(resolve, duration)); @@ -20,7 +21,7 @@ class NotificationBackchannel { const title = "Lens Updater"; -async function autoUpdateCheck(args: UpdateInfo): Promise { +async function autoUpdateCheck(windowManager: WindowManager): Promise { 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 { resolve(); }); - broadcastIpc({ - channel: NotificationChannelAdd, + windowManager.mainView.webContents.send(NotificationChannelAdd, { args: [{ title, body, @@ -88,7 +88,7 @@ async function autoUpdateCheck(args: UpdateInfo): Promise { * 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, diff --git a/src/main/index.ts b/src/main/index.ts index 44e232adc3..31202314c5 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -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); diff --git a/src/main/window-manager.ts b/src/main/window-manager.ts index 74aeb010ea..ca5a312e8b 100644 --- a/src/main/window-manager.ts +++ b/src/main/window-manager.ts @@ -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; diff --git a/src/renderer/components/notifications/notifications.store.tsx b/src/renderer/components/notifications/notifications.store.tsx index fff996e954..b34d08a3aa 100644 --- a/src/renderer/components/notifications/notifications.store.tsx +++ b/src/renderer/components/notifications/notifications.store.tsx @@ -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
{buttons.map(({ backchannel, ...props}) => (