From 02b57d790ac25c0ea7e5380d4385b2ef11d7247e Mon Sep 17 00:00:00 2001 From: Garrett Date: Wed, 13 Sep 2023 11:28:56 -0700 Subject: [PATCH] Update main.ts --- src/main/main.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/main.ts b/src/main/main.ts index 39001a2e4..5e0b68347 100755 --- a/src/main/main.ts +++ b/src/main/main.ts @@ -70,6 +70,7 @@ let globals: { }, set mainWindowReady(v) { + if (globals.mainWindow) throw new Error('Main window cannot be ready. It does not exist...') mainWindowReady = v if (v) readyQueue.forEach(f => onWindowReady(f)) readyQueue = [] @@ -80,7 +81,7 @@ function send(this: BrowserWindow, ...args: any[]) { return this.webContents.send(...args) } -const onWindowReady = (f: (win: BrowserWindow) => any) => (mainWindowReady) ? f(globals.mainWindow) : readyQueue.push(f) +const onWindowReady = (f: (win: BrowserWindow) => any) => (globals.mainWindowReady) ? f(globals.mainWindow) : readyQueue.push(f) // Pass all important log functions to the application @@ -361,7 +362,7 @@ function isValidFile(filepath: string) { function onFileOpened(_, filepath: string) { restoreWindow() || initialize(); // Ensure the application is properly visible - onWindowReady((win) => win.webContents.send('fileOpened', filepath)) + onWindowReady((win) => send.call(win, 'fileOpened', filepath)) } if (isWindows && process.argv.length >= 2) {