From 6115d3a64cc1419e4399e731ded18680870a7ab7 Mon Sep 17 00:00:00 2001 From: PikachuEXE Date: Thu, 15 Dec 2022 10:28:30 +0800 Subject: [PATCH 1/5] * Update app menu to add items for side nav items --- src/main/index.js | 106 +++++++++++++++++++++++++++++++++++++++------- 1 file changed, 90 insertions(+), 16 deletions(-) diff --git a/src/main/index.js b/src/main/index.js index e6c3e1f647306..3d71f0d32ce6c 100644 --- a/src/main/index.js +++ b/src/main/index.js @@ -1131,22 +1131,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 +1157,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' + }, + { + label: 'Trending', + click: (_menuItem, browserWindow, _event) => { + if (browserWindow == null) { + return + } + + browserWindow.webContents.send( + 'change-view', + { route: '/trending' } + ) + }, + type: 'normal' + }, + { + label: 'Most Popular', + click: (_menuItem, browserWindow, _event) => { + if (browserWindow == null) { + return + } + + browserWindow.webContents.send( + 'change-view', + { route: '/popular' } + ) + }, + type: 'normal' + }, + { + 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' + }, + ], + }, { role: 'window', submenu: [ From 55230c7c7382f1941796047ba1e47fff9b4ff6f1 Mon Sep 17 00:00:00 2001 From: PikachuEXE Date: Fri, 16 Dec 2022 11:03:03 +0800 Subject: [PATCH 2/5] * Show app menu items accoridng to user settings --- src/datastores/handlers/base.js | 8 ++++++++ src/main/index.js | 15 ++++++++++----- 2 files changed, 18 insertions(+), 5 deletions(-) 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 3d71f0d32ce6c..c3306bbaa290e 100644 --- a/src/main/index.js +++ b/src/main/index.js @@ -1043,7 +1043,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', @@ -1188,7 +1193,7 @@ function runApp() { }, type: 'normal' }, - { + !hideTrendingVideos && { label: 'Trending', click: (_menuItem, browserWindow, _event) => { if (browserWindow == null) { @@ -1202,7 +1207,7 @@ function runApp() { }, type: 'normal' }, - { + !hidePopularVideos && { label: 'Most Popular', click: (_menuItem, browserWindow, _event) => { if (browserWindow == null) { @@ -1216,7 +1221,7 @@ function runApp() { }, type: 'normal' }, - { + !hidePlaylists && { label: 'Playlists', click: (_menuItem, browserWindow, _event) => { if (browserWindow == null) { @@ -1245,7 +1250,7 @@ function runApp() { }, type: 'normal' }, - ], + ].filter((v) => v !== false), }, { role: 'window', From af454be6cdebb605c7dc6818b95a62e10f8dcb40 Mon Sep 17 00:00:00 2001 From: PikachuEXE Date: Tue, 20 Dec 2022 09:59:10 +0800 Subject: [PATCH 3/5] * Update app menu on setting update --- src/main/index.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/main/index.js b/src/main/index.js index c3306bbaa290e..339c55f2d8136 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: From 80955d97dc6ea41538375b575f1f63c4760c4d71 Mon Sep 17 00:00:00 2001 From: PikachuEXE Date: Sun, 25 Dec 2022 10:27:14 +0800 Subject: [PATCH 4/5] ! Fix setting values reading when db entry(s) absent --- src/main/index.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/main/index.js b/src/main/index.js index 339c55f2d8136..3d7532d824bf2 100644 --- a/src/main/index.js +++ b/src/main/index.js @@ -1056,9 +1056,18 @@ function runApp() { 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 + let hideTrendingVideos = false + try { + hideTrendingVideos = (await sidenavSettings.hideTrendingVideos).value + } catch {} + let hidePopularVideos = false + try { + hidePopularVideos = (await sidenavSettings.hidePopularVideos).value + } catch {} + let hidePlaylists = false + try { + hidePlaylists = (await sidenavSettings.hidePlaylists).value + } catch {} const template = [ { From da746cec6c9d8c95a7b51bbc50d82e56354d9162 Mon Sep 17 00:00:00 2001 From: PikachuEXE Date: Mon, 26 Dec 2022 11:17:04 +0800 Subject: [PATCH 5/5] $ Use `?.` instead of try/catch Suggested by absidue Co-authored-by: absidue <48293849+absidue@users.noreply.github.com> --- src/main/index.js | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/src/main/index.js b/src/main/index.js index 3d7532d824bf2..782ec56ede11c 100644 --- a/src/main/index.js +++ b/src/main/index.js @@ -1056,18 +1056,9 @@ function runApp() { async function setMenu() { const sidenavSettings = baseHandlers.settings._findSidenavSettings() - let hideTrendingVideos = false - try { - hideTrendingVideos = (await sidenavSettings.hideTrendingVideos).value - } catch {} - let hidePopularVideos = false - try { - hidePopularVideos = (await sidenavSettings.hidePopularVideos).value - } catch {} - let hidePlaylists = false - try { - hidePlaylists = (await sidenavSettings.hidePlaylists).value - } catch {} + const hideTrendingVideos = (await sidenavSettings.hideTrendingVideos)?.value + const hidePopularVideos = (await sidenavSettings.hidePopularVideos)?.value + const hidePlaylists = (await sidenavSettings.hidePlaylists)?.value const template = [ {