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

Add a new setting to open links in a new window #5592

Draft
wants to merge 2 commits into
base: development
Choose a base branch
from
Draft
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
20 changes: 17 additions & 3 deletions src/main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,10 @@ function runApp() {
let mainWindow
let startupUrl

function isOpenLinkInNewWindow() {
return sessionStorage.getItem('openLinkInNewWindow') === 'true'
}

if (process.platform === 'linux') {
// Enable hardware acceleration via VA-API with OpenGL if no other feature flags are found
// https://chromium.googlesource.com/chromium/src/+/refs/heads/main/docs/gpu/vaapi.md
Expand Down Expand Up @@ -820,7 +824,11 @@ function runApp() {

ipcMain.once(IpcChannels.APP_READY, () => {
if (startupUrl) {
mainWindow.webContents.send(IpcChannels.OPEN_URL, startupUrl)
if (isOpenLinkInNewWindow()) {
Copy link
Author

@pakoito pakoito Aug 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably check if there's already content on the window too.

createWindow({ replaceMainWindow: false, windowStartupUrl: startupUrl, showWindowNow: true })
} else {
mainWindow.webContents.send(IpcChannels.OPEN_URL, startupUrl)
}
}
})

Expand Down Expand Up @@ -1369,10 +1377,16 @@ function runApp() {
app.on('open-url', (event, url) => {
event.preventDefault()

const startUrl = baseUrl(url)

if (mainWindow && mainWindow.webContents) {
mainWindow.webContents.send(IpcChannels.OPEN_URL, baseUrl(url))
if (isOpenLinkInNewWindow()) {
createWindow({ replaceMainWindow: false, windowStartupUrl: startUrl, showWindowNow: true })
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is probably an IPC to open a new window.

} else {
mainWindow.webContents.send(IpcChannels.OPEN_URL, startUrl)
}
} else {
startupUrl = baseUrl(url)
startupUrl = startUrl
}
})

Expand Down
5 changes: 5 additions & 0 deletions src/renderer/components/general-settings/general-settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,10 @@ export default defineComponent({
this.$t('Settings.General Settings.External Link Handling.Ask Before Opening Link'),
this.$t('Settings.General Settings.External Link Handling.No Action')
]
},

openLinkInNewWindow: function () {
return this.$store.getters.getEnableOpenLinkInNewWindow
}
},
created: function () {
Expand Down Expand Up @@ -274,6 +278,7 @@ export default defineComponent({
'updateCurrentLocale',
'updateExternalLinkHandling',
'updateGeneralAutoLoadMorePaginatedItemsEnabled',
'updateEnableOpenLinkInNewWindow',
])
}
})
6 changes: 6 additions & 0 deletions src/renderer/components/general-settings/general-settings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@
:compact="true"
@change="updateEnableSearchSuggestions"
/>
<ft-toggle-switch
:label="$t('Settings.General Settings.Enable Open Link In New Window')"

Check warning on line 42 in src/renderer/components/general-settings/general-settings.vue

View workflow job for this annotation

GitHub Actions / lint

'Settings["General Settings"]["Enable Open Link In New Window"]' does not exist in localization message resources
:default-value="enableOpenLinkInNewWindow"
:compact="true"
@change="updateEnableOpenLinkInNewWindow"
/>
</div>
</div>
<div class="switchGrid">
Expand Down
7 changes: 7 additions & 0 deletions src/renderer/store/modules/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,13 @@ const stateWithSideEffects = {
}
},

openLinkInNewWindow: {
defaultValue: false,
sideEffectsHandler: (_, value) => {
sessionStorage.setItem('openLinkInNewWindow', value)
}
},

uiScale: {
defaultValue: 100,
sideEffectsHandler: (_, value) => {
Expand Down
1 change: 1 addition & 0 deletions static/locales/en-US.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ Settings:
Fallback to Non-Preferred Backend on Failure: Fallback to Non-Preferred Backend
on Failure
Enable Search Suggestions: Enable Search Suggestions
Enable Link In New Window: Enable opening freetube:// links in a new window
Auto Load Next Page:
Label: Auto Load Next Page
Tooltip: Load additional pages and comments automatically.
Expand Down