Skip to content

Commit

Permalink
handle URLs passed via command line with no open windows on macOS
Browse files Browse the repository at this point in the history
  • Loading branch information
OothecaPickle committed Dec 4, 2024
1 parent b6bf702 commit c20e226
Showing 1 changed file with 21 additions and 13 deletions.
34 changes: 21 additions & 13 deletions src/main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
})
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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
*
Expand Down

0 comments on commit c20e226

Please sign in to comment.