Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 'Object has been destroyed' when FreeTube is passed a URL with no windows open on macOS #6278

Merged
merged 5 commits into from
Dec 9, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refactor recent changes to URL handling
OothecaPickle committed Dec 5, 2024
commit 6910e51a8008f0d1b97e8504697306ee65dc95b9
36 changes: 13 additions & 23 deletions src/main/index.js
Original file line number Diff line number Diff line change
@@ -256,15 +256,15 @@ 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
createWindow()
}
}
}
@@ -834,10 +834,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() {
@@ -1447,7 +1448,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()
}
@@ -1513,13 +1514,11 @@ 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)
if (app.isReady()) createWindow()
}
})

@@ -1559,15 +1558,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
*