From d2c7cdd49b86c8659f55bd3e6c8c747623ad5651 Mon Sep 17 00:00:00 2001 From: absidue <48293849+absidue@users.noreply.github.com> Date: Mon, 10 Feb 2025 22:48:44 +0100 Subject: [PATCH] Set process.platform at build time --- _scripts/webpack.main.config.js | 1 + _scripts/webpack.renderer.config.js | 1 + _scripts/webpack.web.config.js | 1 + src/main/index.js | 50 ++++++++++--------- .../player-settings/player-settings.js | 31 ++++++------ src/renderer/components/top-nav/top-nav.js | 24 ++++++--- 6 files changed, 61 insertions(+), 47 deletions(-) diff --git a/_scripts/webpack.main.config.js b/_scripts/webpack.main.config.js index d0c9effe02219..30ea1494b85d5 100644 --- a/_scripts/webpack.main.config.js +++ b/_scripts/webpack.main.config.js @@ -40,6 +40,7 @@ const config = { }, plugins: [ new webpack.DefinePlugin({ + 'process.platform': `'${process.platform}'`, 'process.env.IS_ELECTRON_MAIN': true }) ], diff --git a/_scripts/webpack.renderer.config.js b/_scripts/webpack.renderer.config.js index 11f1cf828711c..f01c6e59dc587 100644 --- a/_scripts/webpack.renderer.config.js +++ b/_scripts/webpack.renderer.config.js @@ -122,6 +122,7 @@ const config = { plugins: [ processLocalesPlugin, new webpack.DefinePlugin({ + 'process.platform': `'${process.platform}'`, 'process.env.IS_ELECTRON': true, 'process.env.IS_ELECTRON_MAIN': false, 'process.env.SUPPORTS_LOCAL_API': true, diff --git a/_scripts/webpack.web.config.js b/_scripts/webpack.web.config.js index 0df7ff510f550..e0923e098a2db 100644 --- a/_scripts/webpack.web.config.js +++ b/_scripts/webpack.web.config.js @@ -118,6 +118,7 @@ const config = { }, plugins: [ new webpack.DefinePlugin({ + 'process.platform': 'undefined', 'process.env.IS_ELECTRON': false, 'process.env.IS_ELECTRON_MAIN': false, 'process.env.SUPPORTS_LOCAL_API': false, diff --git a/src/main/index.js b/src/main/index.js index 57b9a9fb5f4fd..4c0709c1611a7 100644 --- a/src/main/index.js +++ b/src/main/index.js @@ -1738,6 +1738,24 @@ function runApp() { const hidePlaylists = (await sidenavSettings.hidePlaylists)?.value const template = [ + ...process.platform === 'darwin' + ? [ + { + label: app.getName(), + submenu: [ + { role: 'about' }, + { type: 'separator' }, + { role: 'services' }, + { type: 'separator' }, + { role: 'hide' }, + { role: 'hideothers' }, + { role: 'unhide' }, + { type: 'separator' }, + { role: 'quit' } + ] + } + ] + : [], { label: 'File', submenu: [ @@ -1945,32 +1963,16 @@ function runApp() { { role: 'minimize' }, { role: 'close' } ] - } + }, + ...process.platform === 'darwin' + ? [ + { role: 'window' }, + { role: 'help' }, + { role: 'services' } + ] + : [] ] - if (process.platform === 'darwin') { - template.unshift({ - label: app.getName(), - submenu: [ - { role: 'about' }, - { type: 'separator' }, - { role: 'services' }, - { type: 'separator' }, - { role: 'hide' }, - { role: 'hideothers' }, - { role: 'unhide' }, - { type: 'separator' }, - { role: 'quit' } - ] - }) - - template.push( - { role: 'window' }, - { role: 'help' }, - { role: 'services' } - ) - } - const menu = Menu.buildFromTemplate(template) Menu.setApplicationMenu(menu) } diff --git a/src/renderer/components/player-settings/player-settings.js b/src/renderer/components/player-settings/player-settings.js index f04864d992b69..71b866b43df15 100644 --- a/src/renderer/components/player-settings/player-settings.js +++ b/src/renderer/components/player-settings/player-settings.js @@ -198,18 +198,19 @@ export default defineComponent({ this.$t('Settings.General Settings.Thumbnail Preference.Default'), this.$t('Settings.Player Settings.Default Viewing Mode.Theater'), this.$t('Video.Player.Full Window'), + + ...process.env.IS_ELECTRON + ? [ + this.$t('Settings.Player Settings.Default Viewing Mode.Full Screen'), + this.$t('Settings.Player Settings.Default Viewing Mode.Picture in Picture') + ] + : [] ] - if (process.env.IS_ELECTRON) { + if (process.env.IS_ELECTRON && this.externalPlayer !== '') { viewingModeNames.push( - this.$t('Settings.Player Settings.Default Viewing Mode.Full Screen'), - this.$t('Settings.Player Settings.Default Viewing Mode.Picture in Picture') + this.$t('Settings.Player Settings.Default Viewing Mode.External Player', { externalPlayerName: this.externalPlayer }) ) - if (this.externalPlayer !== '') { - viewingModeNames.push( - this.$t('Settings.Player Settings.Default Viewing Mode.External Player', { externalPlayerName: this.externalPlayer }) - ) - } } return viewingModeNames @@ -219,15 +220,15 @@ export default defineComponent({ const viewingModeValues = [ 'default', 'theatre', - 'fullwindow' - ] + 'fullwindow', - if (process.env.IS_ELECTRON) { - viewingModeValues.push('fullscreen', 'pip') + ...process.env.IS_ELECTRON + ? ['fullscreen', 'pip'] + : [] + ] - if (this.externalPlayer !== '') { - viewingModeValues.push('external_player') - } + if (process.env.IS_ELECTRON && this.externalPlayer !== '') { + viewingModeValues.push('external_player') } return viewingModeValues diff --git a/src/renderer/components/top-nav/top-nav.js b/src/renderer/components/top-nav/top-nav.js index b807048f2904a..298b040dcab47 100644 --- a/src/renderer/components/top-nav/top-nav.js +++ b/src/renderer/components/top-nav/top-nav.js @@ -100,10 +100,14 @@ export default defineComponent({ }, forwardText: function () { - const shortcuts = [KeyboardShortcuts.APP.GENERAL.HISTORY_FORWARD] - if (process.platform === 'darwin') { - shortcuts.push(KeyboardShortcuts.APP.GENERAL.HISTORY_FORWARD_ALT_MAC) - } + const shortcuts = process.platform === 'darwin' + ? [ + KeyboardShortcuts.APP.GENERAL.HISTORY_FORWARD, + KeyboardShortcuts.APP.GENERAL.HISTORY_FORWARD_ALT_MAC + ] + : [ + KeyboardShortcuts.APP.GENERAL.HISTORY_FORWARD + ] return localizeAndAddKeyboardShortcutToActionTitle( this.$t('Forward'), @@ -112,10 +116,14 @@ export default defineComponent({ }, backwardText: function () { - const shortcuts = [KeyboardShortcuts.APP.GENERAL.HISTORY_BACKWARD] - if (process.platform === 'darwin') { - shortcuts.push(KeyboardShortcuts.APP.GENERAL.HISTORY_BACKWARD_ALT_MAC) - } + const shortcuts = process.platform === 'darwin' + ? [ + KeyboardShortcuts.APP.GENERAL.HISTORY_BACKWARD, + KeyboardShortcuts.APP.GENERAL.HISTORY_BACKWARD_ALT_MAC + ] + : [ + KeyboardShortcuts.APP.GENERAL.HISTORY_BACKWARD + ] return localizeAndAddKeyboardShortcutToActionTitle( this.$t('Back'),