diff --git a/src/datastores/handlers/base.js b/src/datastores/handlers/base.js index 1250052510cb1..285307017abf9 100644 --- a/src/datastores/handlers/base.js +++ b/src/datastores/handlers/base.js @@ -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 }) } diff --git a/src/main/index.js b/src/main/index.js index e6c3e1f647306..782ec56ede11c 100644 --- a/src/main/index.js +++ b/src/main/index.js @@ -742,6 +742,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: @@ -1043,7 +1054,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', @@ -1131,22 +1147,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', @@ -1173,6 +1173,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: [