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

Change CREATE_NEW_WINDOW IPC call to accept a path and query #6595

Merged
merged 2 commits into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
49 changes: 35 additions & 14 deletions src/main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,8 @@ function runApp() {
}
}

const ROOT_APP_URL = process.env.NODE_ENV === 'development' ? 'http://localhost:9080' : 'app://bundle/index.html'

async function createWindow(
{
replaceMainWindow = true,
Expand Down Expand Up @@ -774,18 +776,10 @@ function runApp() {
}

// load root file/url
if (process.env.NODE_ENV === 'development') {
let devStartupURL = 'http://localhost:9080'
if (windowStartupUrl != null) {
devStartupURL = windowStartupUrl
}
newWindow.loadURL(devStartupURL)
if (windowStartupUrl != null) {
newWindow.loadURL(windowStartupUrl)
} else {
if (windowStartupUrl != null) {
newWindow.loadURL(windowStartupUrl)
} else {
newWindow.loadURL('app://bundle/index.html')
}
newWindow.loadURL(ROOT_APP_URL)
}

if (typeof searchQueryText === 'string' && searchQueryText.length > 0) {
Expand Down Expand Up @@ -1011,12 +1005,39 @@ function runApp() {
return powerSaveBlocker.start('prevent-display-sleep')
})

ipcMain.on(IpcChannels.CREATE_NEW_WINDOW, (_e, { windowStartupUrl = null, searchQueryText = null } = { }) => {
ipcMain.on(IpcChannels.CREATE_NEW_WINDOW, (event, path, query, searchQueryText) => {
if (!isFreeTubeUrl(event.senderFrame.url)) {
return
}

if (path == null && query == null && searchQueryText == null) {
createWindow({ replaceMainWindow: false, showWindowNow: true })
return
}

if (
typeof path !== 'string' ||
(query != null && typeof query !== 'object') ||
(searchQueryText != null && typeof searchQueryText !== 'string')
) {
return
}

if (path.charAt(0) !== '/') {
path = `/${path}`
}

let windowStartupUrl = `${ROOT_APP_URL}#${path}`

if (query) {
windowStartupUrl += '?' + new URLSearchParams(query).toString()
}

createWindow({
replaceMainWindow: false,
showWindowNow: true,
windowStartupUrl: windowStartupUrl,
searchQueryText: searchQueryText
windowStartupUrl,
searchQueryText
})
})

Expand Down
11 changes: 2 additions & 9 deletions src/renderer/helpers/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,18 +232,11 @@ export async function openExternalLink(url) {
* @param {object} params.query the query params to use (optional)
* @param {string} params.searchQueryText the text to show in the search bar in the new window (optional)
*/
export function openInternalPath({ path, query = {}, doCreateNewWindow, searchQueryText = null }) {
export function openInternalPath({ path, query = undefined, doCreateNewWindow, searchQueryText = null }) {
if (process.env.IS_ELECTRON && doCreateNewWindow) {
const { ipcRenderer } = require('electron')

// Combine current document path and new "hash" as new window startup URL
const newWindowStartupURL = new URL(window.location.href)
newWindowStartupURL.hash = `${path}?${(new URLSearchParams(query)).toString()}`

ipcRenderer.send(IpcChannels.CREATE_NEW_WINDOW, {
windowStartupUrl: newWindowStartupURL.toString(),
searchQueryText
})
ipcRenderer.send(IpcChannels.CREATE_NEW_WINDOW, path, query, searchQueryText)
} else {
router.push({
path,
Expand Down
Loading