Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
OothecaPickle committed Dec 4, 2024
1 parent c20e226 commit fe771a7
Showing 1 changed file with 11 additions and 23 deletions.
34 changes: 11 additions & 23 deletions src/main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,15 +256,14 @@ function runApp() {
// Someone tried to run a second instance, we should focus our window
if (typeof commandLine !== 'undefined') {
const url = getLinkUrl(commandLine)
if (mainWindow === 'all-windows-closed') {
if (url) macOSnewURLWindow(url)
createWindow()
} else if (mainWindow && mainWindow.webContents) {
if (mainWindow.isMinimized()) mainWindow.restore()
mainWindow.focus()

if (url) {
if (url) {
if (mainWindow && mainWindow.webContents) {
if (mainWindow.isMinimized()) mainWindow.restore()
mainWindow.focus()

mainWindow.webContents.send(IpcChannels.OPEN_URL, url)
} else {
startupUrl = url
}
}
}
Expand Down Expand Up @@ -834,10 +833,11 @@ function runApp() {
})
}

ipcMain.once(IpcChannels.APP_READY, () => {
ipcMain.on(IpcChannels.APP_READY, () => {
if (startupUrl) {
mainWindow.webContents.send(IpcChannels.OPEN_URL, startupUrl, { isLaunchLink: true })
}
startupUrl = null
})

function relaunch() {
Expand Down Expand Up @@ -1427,7 +1427,7 @@ function runApp() {
app.on('window-all-closed', () => {
// Clean up resources (datastores' compaction + Electron cache and storage data clearing)
cleanUpResources().finally(() => {
mainWindow = 'all-windows-closed'
mainWindow = null
if (process.platform !== 'darwin') {
app.quit()
}
Expand Down Expand Up @@ -1493,10 +1493,7 @@ function runApp() {
app.on('open-url', (event, url) => {
event.preventDefault()

if (mainWindow === 'all-windows-closed') {
macOSnewURLWindow(baseUrl(url))
createWindow()
} else if (mainWindow && mainWindow.webContents) {
if (mainWindow && mainWindow.webContents) {
mainWindow.webContents.send(IpcChannels.OPEN_URL, baseUrl(url))
} else {
startupUrl = baseUrl(url)
Expand Down Expand Up @@ -1539,15 +1536,6 @@ 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 fe771a7

Please sign in to comment.