mirror of
https://github.com/FreeTubeApp/FreeTube
synced 2024-11-17 23:46:41 +01:00
Update app menu to add items for side nav items (#2965)
* * Update app menu to add items for side nav items * * Show app menu items accoridng to user settings * * Update app menu on setting update * ! Fix setting values reading when db entry(s) absent * $ Use `?.` instead of try/catch Suggested by absidue Co-authored-by: absidue <48293849+absidue@users.noreply.github.com> Co-authored-by: absidue <48293849+absidue@users.noreply.github.com>
This commit is contained in:
parent
b77455ec81
commit
72a839fc1c
@ -31,6 +31,14 @@ class Settings {
|
||||
return db.settings.findOne({ _id: 'baseTheme' })
|
||||
}
|
||||
|
||||
static _findSidenavSettings() {
|
||||
return {
|
||||
hideTrendingVideos: db.settings.findOne({ _id: 'hideTrendingVideos' }),
|
||||
hidePopularVideos: db.settings.findOne({ _id: 'hidePopularVideos' }),
|
||||
hidePlaylists: db.settings.findOne({ _id: 'hidePlaylists' }),
|
||||
}
|
||||
}
|
||||
|
||||
static _updateBounds(value) {
|
||||
return db.settings.update({ _id: 'bounds' }, { _id: 'bounds', value }, { upsert: true })
|
||||
}
|
||||
|
@ -740,6 +740,17 @@ function runApp() {
|
||||
event,
|
||||
{ event: SyncEvents.GENERAL.UPSERT, data }
|
||||
)
|
||||
switch (data._id) {
|
||||
// Update app menu on related setting update
|
||||
case 'hideTrendingVideos':
|
||||
case 'hidePopularVideos':
|
||||
case 'hidePlaylists':
|
||||
await setMenu()
|
||||
break
|
||||
|
||||
default:
|
||||
// Do nothing for unmatched settings
|
||||
}
|
||||
return null
|
||||
|
||||
default:
|
||||
@ -1041,7 +1052,12 @@ function runApp() {
|
||||
mainWindow.webContents.send('change-view', data)
|
||||
}
|
||||
|
||||
function setMenu() {
|
||||
async function setMenu() {
|
||||
const sidenavSettings = baseHandlers.settings._findSidenavSettings()
|
||||
const hideTrendingVideos = (await sidenavSettings.hideTrendingVideos)?.value
|
||||
const hidePopularVideos = (await sidenavSettings.hidePopularVideos)?.value
|
||||
const hidePlaylists = (await sidenavSettings.hidePlaylists)?.value
|
||||
|
||||
const template = [
|
||||
{
|
||||
label: 'File',
|
||||
@ -1129,22 +1145,6 @@ function runApp() {
|
||||
{ type: 'separator' },
|
||||
{ role: 'togglefullscreen' },
|
||||
{ type: 'separator' },
|
||||
{
|
||||
label: 'History',
|
||||
// MacOS: Command + Y
|
||||
// Other OS: Ctrl + H
|
||||
accelerator: process.platform === 'darwin' ? 'Cmd+Y' : 'Ctrl+H',
|
||||
click: (_menuItem, browserWindow, _event) => {
|
||||
if (browserWindow == null) { return }
|
||||
|
||||
browserWindow.webContents.send(
|
||||
'change-view',
|
||||
{ route: '/history' }
|
||||
)
|
||||
},
|
||||
type: 'normal'
|
||||
},
|
||||
{ type: 'separator' },
|
||||
{
|
||||
label: 'Back',
|
||||
accelerator: 'Alt+Left',
|
||||
@ -1171,6 +1171,96 @@ function runApp() {
|
||||
},
|
||||
]
|
||||
},
|
||||
{
|
||||
label: 'Navigate',
|
||||
submenu: [
|
||||
{
|
||||
label: 'Subscriptions',
|
||||
click: (_menuItem, browserWindow, _event) => {
|
||||
if (browserWindow == null) {
|
||||
return
|
||||
}
|
||||
|
||||
browserWindow.webContents.send(
|
||||
'change-view',
|
||||
{ route: '/subscriptions' }
|
||||
)
|
||||
},
|
||||
type: 'normal'
|
||||
},
|
||||
{
|
||||
label: 'Channels',
|
||||
click: (_menuItem, browserWindow, _event) => {
|
||||
if (browserWindow == null) {
|
||||
return
|
||||
}
|
||||
|
||||
browserWindow.webContents.send(
|
||||
'change-view',
|
||||
{ route: '/subscribedchannels' }
|
||||
)
|
||||
},
|
||||
type: 'normal'
|
||||
},
|
||||
!hideTrendingVideos && {
|
||||
label: 'Trending',
|
||||
click: (_menuItem, browserWindow, _event) => {
|
||||
if (browserWindow == null) {
|
||||
return
|
||||
}
|
||||
|
||||
browserWindow.webContents.send(
|
||||
'change-view',
|
||||
{ route: '/trending' }
|
||||
)
|
||||
},
|
||||
type: 'normal'
|
||||
},
|
||||
!hidePopularVideos && {
|
||||
label: 'Most Popular',
|
||||
click: (_menuItem, browserWindow, _event) => {
|
||||
if (browserWindow == null) {
|
||||
return
|
||||
}
|
||||
|
||||
browserWindow.webContents.send(
|
||||
'change-view',
|
||||
{ route: '/popular' }
|
||||
)
|
||||
},
|
||||
type: 'normal'
|
||||
},
|
||||
!hidePlaylists && {
|
||||
label: 'Playlists',
|
||||
click: (_menuItem, browserWindow, _event) => {
|
||||
if (browserWindow == null) {
|
||||
return
|
||||
}
|
||||
|
||||
browserWindow.webContents.send(
|
||||
'change-view',
|
||||
{ route: '/userplaylists' }
|
||||
)
|
||||
},
|
||||
type: 'normal'
|
||||
},
|
||||
{
|
||||
label: 'History',
|
||||
// MacOS: Command + Y
|
||||
// Other OS: Ctrl + H
|
||||
accelerator: process.platform === 'darwin' ? 'Cmd+Y' : 'Ctrl+H',
|
||||
click: (_menuItem, browserWindow, _event) => {
|
||||
if (browserWindow == null) { return }
|
||||
|
||||
browserWindow.webContents.send(
|
||||
'change-view',
|
||||
{ route: '/history' }
|
||||
)
|
||||
},
|
||||
type: 'normal'
|
||||
},
|
||||
].filter((v) => v !== false),
|
||||
},
|
||||
{
|
||||
role: 'window',
|
||||
submenu: [
|
||||
|
Loading…
Reference in New Issue
Block a user