From c20e226ec027e036c5124aad492974d8b0a7f82e Mon Sep 17 00:00:00 2001 From: covidisahoax Date: Wed, 4 Dec 2024 13:42:09 -0800 Subject: [PATCH] handle URLs passed via command line with no open windows on macOS --- src/main/index.js | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/src/main/index.js b/src/main/index.js index 3feb30bdb3fe3..35f7fdee48fde 100644 --- a/src/main/index.js +++ b/src/main/index.js @@ -254,13 +254,18 @@ function runApp() { app.on('second-instance', (_, commandLine, __) => { // Someone tried to run a second instance, we should focus our window - if (mainWindow && typeof commandLine !== 'undefined') { - if (mainWindow.isMinimized()) mainWindow.restore() - mainWindow.focus() - + if (typeof commandLine !== 'undefined') { const url = getLinkUrl(commandLine) - if (url) { - mainWindow.webContents.send(IpcChannels.OPEN_URL, url) + if (mainWindow === 'all-windows-closed') { + if (url) macOSnewURLWindow(url) + createWindow() + } else if (mainWindow && mainWindow.webContents) { + if (mainWindow.isMinimized()) mainWindow.restore() + mainWindow.focus() + + if (url) { + mainWindow.webContents.send(IpcChannels.OPEN_URL, url) + } } } }) @@ -1489,13 +1494,7 @@ function runApp() { event.preventDefault() if (mainWindow === 'all-windows-closed') { - app.once('browser-window-created', (_, mainWindow) => { - mainWindow.webContents.once('did-finish-load', () => { - // A timeout here is necessary or the new window won't receive the URL - setTimeout(function() { mainWindow.webContents.send( - IpcChannels.OPEN_URL, baseUrl(url), { isLaunchLink: true }) }, 1000) - }) - }) + macOSnewURLWindow(baseUrl(url)) createWindow() } else if (mainWindow && mainWindow.webContents) { mainWindow.webContents.send(IpcChannels.OPEN_URL, baseUrl(url)) @@ -1540,6 +1539,15 @@ function runApp() { } } + function macOSnewURLWindow(url) { + app.once('browser-window-created', (_, mainWindow) => { + mainWindow.webContents.once('did-finish-load', () => { + // A timeout here is necessary or the new window won't receive the URL + setTimeout(function() { mainWindow.webContents.send(IpcChannels.OPEN_URL, url, { isLaunchLink: true }) }, 1000) + }) + }) + } + /* * Auto Updater *