Skip to content

Commit

Permalink
Fix 'Object has been destroyed' when FreeTube is passed a URL with no…
Browse files Browse the repository at this point in the history
… windows open on macOS (#6278)

* fix 'Object has been destroyed' error
on macOS when attempting to open URL with no windows open

* add comment

* handle URLs passed via command line with no open windows on macOS

* refactor recent changes to URL handling

* fix regression
(trying to launch a second instance wouldn't have focused main window)
  • Loading branch information
OothecaPickle authored Dec 9, 2024
1 parent ef12854 commit 4a60974
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,13 +254,16 @@ 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 && mainWindow.webContents) {
if (mainWindow.isMinimized()) mainWindow.restore()
mainWindow.focus()

if (url) mainWindow.webContents.send(IpcChannels.OPEN_URL, url)
} else {
if (url) startupUrl = url
createWindow()
}
}
})
Expand Down Expand Up @@ -829,10 +832,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 @@ -1442,6 +1446,7 @@ function runApp() {
app.on('window-all-closed', () => {
// Clean up resources (datastores' compaction + Electron cache and storage data clearing)
cleanUpResources().finally(() => {
mainWindow = null
if (process.platform !== 'darwin') {
app.quit()
}
Expand Down Expand Up @@ -1511,6 +1516,7 @@ function runApp() {
mainWindow.webContents.send(IpcChannels.OPEN_URL, baseUrl(url))
} else {
startupUrl = baseUrl(url)
if (app.isReady()) createWindow()
}
})

Expand Down

0 comments on commit 4a60974

Please sign in to comment.