From 41ca3cf8f698dfe419c2584c8b8e76eb61a06758 Mon Sep 17 00:00:00 2001 From: Monochromish Date: Tue, 26 Apr 2022 18:48:10 +1000 Subject: [PATCH 1/4] Added update keybind feature. --- src/i18n/en_US.json | 2 + src/i18n/source/en_US.json | 2 + src/main/base/store.ts | 47 +++ src/main/plugins/menubar.ts | 406 ++++++++++++++------------ src/renderer/main/events.js | 22 -- src/renderer/views/pages/settings.ejs | 155 +++++++--- 6 files changed, 388 insertions(+), 246 deletions(-) diff --git a/src/i18n/en_US.json b/src/i18n/en_US.json index 56cb0c9b..9b9a5608 100644 --- a/src/i18n/en_US.json +++ b/src/i18n/en_US.json @@ -280,6 +280,8 @@ "settings.option.general.customizeSidebar": "Customize Sidebar Items", "settings.option.general.customizeSidebar.customize": "Customize", "settings.option.general.keybindings": "Keybindings", + "settings.notyf.general.keybindings.update.success": "Keybind updated successfully", + "settings.prompt.general.keybindings.update.success": "Keybind updated successfully. Press OK to relaunch Cider", "settings.option.general.keybindings.open": "Open", "settings.description.search": "Search", "settings.description.albums": "Library Albums", diff --git a/src/i18n/source/en_US.json b/src/i18n/source/en_US.json index cb7cb1da..3851499a 100644 --- a/src/i18n/source/en_US.json +++ b/src/i18n/source/en_US.json @@ -280,6 +280,8 @@ "settings.option.general.customizeSidebar": "Customize Sidebar Items", "settings.option.general.customizeSidebar.customize": "Customize", "settings.option.general.keybindings": "Keybindings", + "settings.notyf.general.keybindings.update.success": "Keybind updated successfully", + "settings.prompt.general.keybindings.update.success": "Keybind updated successfully. Press OK to relaunch Cider", "settings.option.general.keybindings.open": "Open", "settings.description.search": "Search", "settings.description.albums": "Library Albums", diff --git a/src/main/base/store.ts b/src/main/base/store.ts index fe9cd36e..f71f0798 100644 --- a/src/main/base/store.ts +++ b/src/main/base/store.ts @@ -44,6 +44,53 @@ export class Store { "onStartup": { "enabled": false, "hidden": false, + }, + "keybind": { + "search": [ + process.platform == "darwin" ? "Command" : "Control", + "S" + ], + "albums": [ + process.platform == "darwin" ? "Command" : "Control", + "F" + ], + "artists": [ + process.platform == "darwin" ? "Command" : "Control", + "D" + ], + "browse": [ + process.platform == "darwin" ? "Command" : "Control", + "B" + ], + "togglePrivateSession": [ + process.platform == "darwin" ? "Command" : "Control", + "P" + ], + "webRemote": [ + process.platform == "darwin" ? "Command" : "Control", + "W" + ], + "audioSettings": [ + process.platform == "darwin" ? "Option" : "Shift", + "A" + ], + "pluginMenu": [ + process.platform == "darwin" ? "Option" : "Shift", + "P" + ], + "castToDevices": [ + process.platform == "darwin" ? "Option" : "Shift", + "C" + ], + "settings": [ + process.platform == "darwin" ? "Option" : "Shift", + "S" + ], + "openDeveloperTools": [ + process.platform == "darwin" ? "Command" : "Control", + process.platform == "darwin" ? "Option" : "Shift", + "I" + ] } }, "home": { diff --git a/src/main/plugins/menubar.ts b/src/main/plugins/menubar.ts index 04236d5a..38ac4886 100644 --- a/src/main/plugins/menubar.ts +++ b/src/main/plugins/menubar.ts @@ -35,196 +35,7 @@ export default class Thumbar { * @private */ private isMac: boolean = process.platform === 'darwin'; - private _menuTemplate: any = [ - { - label: app.getName(), - submenu: [ - { - label: 'About', - click: () => this._win.webContents.executeJavaScript(`app.appRoute('about')`) - }, - {type: 'separator'}, - { - label: 'Settings', - accelerator: 'CommandOrControl+,', - click: () => this._win.webContents.executeJavaScript(`app.appRoute('settings')`) - }, - {type: 'separator'}, - {role: 'services'}, - {type: 'separator'}, - {role: 'hide'}, - {role: 'hideOthers'}, - {role: 'unhide'}, - {type: 'separator'}, - {role: 'quit'} - ] - }, - { - label: 'View', - submenu: [ - {role: 'reload'}, - {role: 'forceReload'}, - {role: 'toggleDevTools'}, - {type: 'separator'}, - {role: 'resetZoom'}, - {role: 'zoomIn'}, - {role: 'zoomOut'}, - {type: 'separator'}, - {role: 'togglefullscreen'}, - ] - }, - { - label: 'Window', - submenu: [ - {role: 'minimize'}, - { - label: 'Show', - click: () => utils.getWindow().show() - }, - {role: 'zoom'}, - ...(this.isMac ? [ - {type: 'separator'}, - {role: 'front'}, - {role: 'close'}, - ] : [ - {role: 'close'}, - ]), - - { - label: 'Edit', - submenu: [ - {role: 'undo'}, - {role: 'redo'}, - {type: 'separator'}, - {role: 'cut'}, - {role: 'copy'}, - {role: 'paste'}, - ] - }, - {type: 'separator'}, - { - label: 'Toggle Private Session', - accelerator: 'CommandOrControl+P', - click: () => this._win.webContents.executeJavaScript(`app.cfg.general.privateEnabled = !app.cfg.general.privateEnabled`) - }, - {type: 'separator'}, - { - label: 'Web Remote', - accelerator: 'CommandOrControl+Shift+W', - sublabel: 'Opens in external window', - click: () => this._win.webContents.executeJavaScript(`app.appRoute('remote-pair')`) - }, - { - label: 'Audio Settings', - accelerator: 'CommandOrControl+Shift+A', - click: () => this._win.webContents.executeJavaScript(`app.modals.audioSettings = true`) - }, - { - label: 'Plug-in Menu', - accelerator: 'CommandOrControl+Shift+P', - click: () => this._win.webContents.executeJavaScript(`app.modals.pluginMenu = true`) - } - - ] - }, - { - label: 'Controls', - submenu: [ - { - label: 'Pause / Play', - accelerator: 'Space', - click: () => this._win.webContents.executeJavaScript(`app.SpacePause()`) - }, - { - label: 'Next', - accelerator: 'CommandOrControl+Right', - click: () => this._win.webContents.executeJavaScript(`MusicKitInterop.next()`) - }, - { - label: 'Previous', - accelerator: 'CommandOrControl+Left', - click: () => this._win.webContents.executeJavaScript(`MusicKitInterop.previous()`) - }, - {type: 'separator'}, - { - label: 'Volume Up', - accelerator: 'CommandOrControl+Up', - click: () => this._win.webContents.executeJavaScript(`app.volumeUp()`) - }, - { - label: 'Volume Down', - accelerator: 'CommandOrControl+Down', - click: () => this._win.webContents.executeJavaScript(`app.volumeDown()`) - }, - {type: 'separator'}, - { - label: 'Cast To Devices', - accelerator: 'CommandOrControl+Shift+C', - click: () => this._win.webContents.executeJavaScript(`app.modals.castMenu = true`) - } - ] - }, - { - label: 'Account', - submenu: [ - { - label: 'Account Settings', - click: () => this._win.webContents.executeJavaScript(`app.appRoute('apple-account-settings')`) - }, - { - label: 'Sign Out', - click: () => this._win.webContents.executeJavaScript(`app.unauthorize()`) - } - ] - }, - { - label: 'Support', - role: 'help', - submenu: [ - { - label: 'Discord', - click: () => shell.openExternal("https://discord.gg/AppleMusic").catch(console.error) - }, - { - label: 'GitHub Wiki', - click: () => shell.openExternal("https://github.com/ciderapp/Cider/wiki/Troubleshooting").catch(console.error) - }, - {type: 'separator'}, - { - label: 'Report a...', - submenu: [ - { - label: 'Bug', - click: () => shell.openExternal("https://github.com/ciderapp/Cider/issues/new?assignees=&labels=bug%2Ctriage&template=bug_report.yaml&title=%5BBug%5D%3A+").catch(console.error) - }, - { - label: 'Feature Request', - click: () => shell.openExternal("https://github.com/ciderapp/Cider/discussions/new?category=feature-request").catch(console.error) - }, - { - label: 'Translation Report/Request', - click: () => shell.openExternal("https://github.com/ciderapp/Cider/issues/new?assignees=&labels=%F0%9F%8C%90+Translations&template=translation.yaml&title=%5BTranslation%5D%3A+").catch(console.error) - }, - ] - }, - {type: 'separator'}, - { - label: 'View License', - click: () => shell.openExternal("https://github.com/ciderapp/Cider/blob/main/LICENSE").catch(console.error) - }, - {type: 'separator'}, - { - label: 'Toggle Developer Tools', - accelerator: 'Option+CommandOrControl+Shift+I', - click: () => this._win.webContents.openDevTools() - }, - { - label: 'Open Configuration File in Editor', - click: () => this._store.openInEditor() - } - ] - } - ] + private _menuTemplate: any; /******************************************************************************************* * Public Methods @@ -233,9 +44,222 @@ export default class Thumbar { /** * Runs on plugin load (Currently run on application start) */ - constructor(utils: { getApp: () => any; getStore: () => any; }) { + constructor(utils: { getApp: () => any; getStore: () => any; getWindow: () => any; }) { this._app = utils.getApp(); this._store = utils.getStore(); + + this._menuTemplate = [ + { + label: app.getName(), + submenu: [ + { + label: 'About', + click: () => this._win.webContents.executeJavaScript(`app.appRoute('about')`) + }, + {type: 'separator'}, + { + label: 'Settings', + accelerator: this._store.general.keybind.settings.join('+'), + click: () => this._win.webContents.executeJavaScript(`app.appRoute('settings')`) + }, + {type: 'separator'}, + {role: 'services'}, + {type: 'separator'}, + {role: 'hide'}, + {role: 'hideOthers'}, + {role: 'unhide'}, + {type: 'separator'}, + {role: 'quit'} + ] + }, + { + label: 'View', + submenu: [ + {role: 'reload'}, + {role: 'forceReload'}, + {role: 'toggleDevTools'}, + {type: 'separator'}, + {role: 'resetZoom'}, + {role: 'zoomIn'}, + {role: 'zoomOut'}, + {type: 'separator'}, + {role: 'togglefullscreen'}, + ] + }, + { + label: 'Window', + submenu: [ + {role: 'minimize'}, + { + label: 'Show', + click: () => utils.getWindow().show() + }, + {role: 'zoom'}, + ...(this.isMac ? [ + {type: 'separator'}, + {role: 'front'}, + {role: 'close'}, + ] : [ + {role: 'close'}, + ]), + + { + label: 'Edit', + submenu: [ + {role: 'undo'}, + {role: 'redo'}, + {type: 'separator'}, + {role: 'cut'}, + {role: 'copy'}, + {role: 'paste'}, + ] + }, + {type: 'separator'}, + { + label: 'Toggle Private Session', + accelerator: this._store.general.keybind.togglePrivateSession.join('+'), + click: () => this._win.webContents.executeJavaScript(`app.cfg.general.privateEnabled = !app.cfg.general.privateEnabled`) + }, + {type: 'separator'}, + { + label: 'Web Remote', + accelerator: this._store.general.keybind.webRemote.join('+'), + sublabel: 'Opens in external window', + click: () => this._win.webContents.executeJavaScript(`app.appRoute('remote-pair')`) + }, + { + label: 'Audio Settings', + accelerator: this._store.general.keybind.audioSettings.join('+'), + click: () => this._win.webContents.executeJavaScript(`app.modals.audioSettings = true`) + }, + { + label: 'Plug-in Menu', + accelerator: this._store.general.keybind.pluginMenu.join('+'), + click: () => this._win.webContents.executeJavaScript(`app.modals.pluginMenu = true`) + } + ] + }, + { + label: 'Controls', + submenu: [ + { + label: 'Pause / Play', + accelerator: 'Space', + click: () => this._win.webContents.executeJavaScript(`app.SpacePause()`) + }, + { + label: 'Next', + accelerator: 'CommandOrControl+Right', + click: () => this._win.webContents.executeJavaScript(`MusicKitInterop.next()`) + }, + { + label: 'Previous', + accelerator: 'CommandOrControl+Left', + click: () => this._win.webContents.executeJavaScript(`MusicKitInterop.previous()`) + }, + {type: 'separator'}, + { + label: 'Volume Up', + accelerator: 'CommandOrControl+Up', + click: () => this._win.webContents.executeJavaScript(`app.volumeUp()`) + }, + { + label: 'Volume Down', + accelerator: 'CommandOrControl+Down', + click: () => this._win.webContents.executeJavaScript(`app.volumeDown()`) + }, + { + label: 'Browse', + accelerator: this._store.general.keybind.browse.join('+'), + click: () => this._win.webContents.executeJavaScript(`app.appRoute('browse')`) + }, + {type: 'separator'}, + { + label: 'Artists', + accelerator: this._store.general.keybind.artists.join('+'), + click: () => this._win.webContents.executeJavaScript(`app.appRoute('library-artists')`) + }, + { + label: 'Search', + accelerator: this._store.general.keybind.search.join('+'), + click: () => this._win.webContents.executeJavaScript(`app.appRoute('search')`) + }, + {type: 'separator'}, + { + label: 'Album', + accelerator: this._store.general.keybind.albums.join('+'), + click: () => this._win.webContents.executeJavaScript(`app.appRoute('library-albums')`) + }, + {type: 'separator'}, + { + label: 'Cast To Devices', + accelerator: this._store.general.keybind.castToDevices.join('+'), + click: () => this._win.webContents.executeJavaScript(`app.modals.castMenu = true`) + } + ] + }, + { + label: 'Account', + submenu: [ + { + label: 'Account Settings', + click: () => this._win.webContents.executeJavaScript(`app.appRoute('apple-account-settings')`) + }, + { + label: 'Sign Out', + click: () => this._win.webContents.executeJavaScript(`app.unauthorize()`) + } + ] + }, + { + label: 'Support', + role: 'help', + submenu: [ + { + label: 'Discord', + click: () => shell.openExternal("https://discord.gg/AppleMusic").catch(console.error) + }, + { + label: 'GitHub Wiki', + click: () => shell.openExternal("https://github.com/ciderapp/Cider/wiki/Troubleshooting").catch(console.error) + }, + {type: 'separator'}, + { + label: 'Report a...', + submenu: [ + { + label: 'Bug', + click: () => shell.openExternal("https://github.com/ciderapp/Cider/issues/new?assignees=&labels=bug%2Ctriage&template=bug_report.yaml&title=%5BBug%5D%3A+").catch(console.error) + }, + { + label: 'Feature Request', + click: () => shell.openExternal("https://github.com/ciderapp/Cider/discussions/new?category=feature-request").catch(console.error) + }, + { + label: 'Translation Report/Request', + click: () => shell.openExternal("https://github.com/ciderapp/Cider/issues/new?assignees=&labels=%F0%9F%8C%90+Translations&template=translation.yaml&title=%5BTranslation%5D%3A+").catch(console.error) + }, + ] + }, + {type: 'separator'}, + { + label: 'View License', + click: () => shell.openExternal("https://github.com/ciderapp/Cider/blob/main/LICENSE").catch(console.error) + }, + {type: 'separator'}, + { + label: 'Toggle Developer Tools', + accelerator: this._store.general.keybind.openDeveloperTools.join('+'), + click: () => this._win.webContents.openDevTools() + }, + { + label: 'Open Configuration File in Editor', + click: () => this._store.openInEditor() + } + ] + } + ]; + console.debug(`[Plugin][${this.name}] Loading Complete.`); } diff --git a/src/renderer/main/events.js b/src/renderer/main/events.js index 00726985..0b2e13d3 100644 --- a/src/renderer/main/events.js +++ b/src/renderer/main/events.js @@ -18,12 +18,6 @@ const Events = { }); document.addEventListener('keydown', async function (event) { - // CTRL + F - if (event.keyCode === 70 && event.ctrlKey) { - app.appRoute('search') - app.$refs.searchInput.focus() - app.$refs.searchInput.select() - } // CTRL + R if (event.keyCode === 82 && event.ctrlKey) { event.preventDefault() @@ -38,22 +32,6 @@ const Events = { event.preventDefault() window.location.reload() } - // CTRL + S - if (event.keyCode === 83 && event.ctrlKey) { - app.appRoute("settings") - } - // CTRL + A - if (event.keyCode === 65 && event.ctrlKey) { - app.appRoute("library-albums") - } - // CTRL + B - if (event.keyCode === 66 && event.ctrlKey) { - app.appRoute("browse") - } - // CTRL + D - if (event.keyCode === 68 && event.ctrlKey) { - app.appRoute("library-artists") - } // CTRL + E if (event.keyCode === 69 && event.ctrlKey) { app.invokeDrawer('queue') diff --git a/src/renderer/views/pages/settings.ejs b/src/renderer/views/pages/settings.ejs index 1830333b..81b29251 100644 --- a/src/renderer/views/pages/settings.ejs +++ b/src/renderer/views/pages/settings.ejs @@ -138,90 +138,115 @@
{{$root.getLz('settings.description.search')}}
-
-

{{ getCommandOrControl() }} + F

-
+
+ +
{{$root.getLz('settings.description.albums')}}
-
-

{{ getCommandOrControl() }} + A

-
+
+ +
{{$root.getLz('settings.description.artists')}}
-
-

{{ getCommandOrControl() }} + D

-
+
+ +
{{$root.getLz('settings.description.browse')}}
-
-

{{ getCommandOrControl() }} + B

-
+
+ +
{{$root.getLz('settings.description.private')}}
-
-

{{ getCommandOrControl() }} + P

+
+
{{$root.getLz('settings.description.remote')}}
-
-

{{ getCommandOrControl() }} + Shift + W

+
+
{{$root.getLz('settings.description.audio')}}
-
-

{{ getCommandOrControl() }} + Shift + A

+
+
{{$root.getLz('settings.description.plugins')}}
-
-

{{ getCommandOrControl() }} + Shift + P

+
+
{{$root.getLz('settings.description.cast')}}
-
-

{{ getCommandOrControl() }} + Shift + C

+
+
{{$root.getLz('settings.description.settings')}}
-
-

{{ getCommandOrControl() }} + S

-
+
+ +
{{$root.getLz('settings.description.developer')}}
-
-

{{ getCommandOrControl() }} + {{ getOptionOrShift() }} + I

+
+
+
@@ -1294,12 +1319,6 @@ } }, methods: { - getCommandOrControl() { - return app.platform == "darwin" ? "⌘" : "Ctrl"; - }, - getOptionOrShift() { - return app.platform == "darwin" ? "⌥" : "Shift"; - }, windowBgStyleChange() { this.$root.getNowPlayingArtworkBG(undefined, true) if (this.$root.cfg.visual.window_background_style == "mica") { @@ -1313,6 +1332,76 @@ } }) }, + keyBindUpdate: function (action) { + var blur = document.createElement('div'); + blur.className = 'blur'; + blur.style.backgroundColor = 'rgba(0,0,0,0.25)'; + blur.style.position = 'fixed'; + blur.style.top = '0'; + blur.style.left = '0'; + blur.style.width = '100%'; + blur.style.height = '100%'; + blur.style.zIndex = '9999'; + blur.style.display = 'flex'; + blur.style.alignItems = 'center'; + blur.style.justifyContent = 'center'; + blur.style.fontSize = '2em'; + blur.style.color = 'white'; + blur.innerHTML = 'Press a combination of two keys to update keybind. Press Escape key to go back.' + document.body.appendChild(blur); + + var keyBind = []; + var keyBindTimeout = setTimeout(function () { + keyBind = []; + document.body.removeChild(blur); + }, 30000); + var keyBindUpdate = function (e) { + if (document.body.contains(blur)) { + if (e.key == 'Escape') { + document.body.removeChild(blur); + clearTimeout(keyBindTimeout); + return; + } else { + if (e.keyCode >= 65 && e.keyCode <= 90 && e.keyCode <= 97 && e.keyCode <= 122) { + keyBind.push(e.key.toUpperCase()); + } else { + keyBind.push(e.key); + } + if (keyBind.length == 2) { + if (keyBind[0] != keyBind[1]) { + app.cfg.general.keybind[action] = keyBind + document.body.removeChild(blur); + clearTimeout(keyBindTimeout); + notyf.success(app.getLz('settings.notyf.general.keybindings.update.success')); + bootbox.confirm(app.getLz("settings.prompt.general.keybindings.update.success"), (ok)=>{ + if(ok) ipcRenderer.invoke("relaunchApp") + }) + } else { + keyBind = []; + } + } + } + } else return; + } + document.addEventListener('keydown', keyBindUpdate); + }, + keyBindReset: function () { + app.cfg.general.keybind.search = [app.platform == "darwin" ? "Command" : "Control","S"]; + app.cfg.general.keybind.albums = [app.platform == "darwin" ? "Command" : "Control","F"]; + app.cfg.general.keybind.artists = [app.platform == "darwin" ? "Command" : "Control","D"]; + app.cfg.general.keybind.browse = [app.platform == "darwin" ? "Command" : "Control","B"]; + app.cfg.general.keybind.togglePrivateSession = [app.platform == "darwin" ? "Command" : "Control","P"]; + app.cfg.general.keybind.webRemote = [app.platform == "darwin" ? "Command" : "Control","W"]; + app.cfg.general.keybind.audioSettings = [app.platform == "darwin" ? "Option" : "Shift","A"]; + app.cfg.general.keybind.pluginMenu = [app.platform == "darwin" ? "Option" : "Shift","P"]; + app.cfg.general.keybind.castToDevices = [app.platform == "darwin" ? "Option" : "Shift","C"]; + app.cfg.general.keybind.settings = [app.platform == "darwin" ? "Option" : "Shift","S"]; + app.cfg.general.keybind.openDeveloperTools = [app.platform == "darwin" ? "Command" : "Control",app.platform == "darwin" ? "Option" : "Shift","I"]; + notyf.success(app.getLz('settings.notyf.general.keybindings.update.success')); + bootbox.confirm(app.getLz("settings.prompt.general.keybindings.update.success"), (ok)=>{ + if(ok) ipcRenderer.invoke("relaunchApp") + }) + }, gitHubExplore() { app.appRoute("themes-github") }, From 126e3ebd9f30d930247caed528fbc52c3c822d81 Mon Sep 17 00:00:00 2001 From: Monochromish Date: Wed, 27 Apr 2022 06:27:50 +1000 Subject: [PATCH 2/4] Fixed bugs --- src/renderer/views/pages/settings.ejs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/renderer/views/pages/settings.ejs b/src/renderer/views/pages/settings.ejs index 81b29251..dde9eed5 100644 --- a/src/renderer/views/pages/settings.ejs +++ b/src/renderer/views/pages/settings.ejs @@ -70,9 +70,9 @@ {{$root.getLz('settings.option.general.customizeSidebar.customize')}}
- +
-
+
w
{{ $root.getLz('term.recentlyAdded') }}
@@ -132,7 +132,7 @@ {{$root.getLz('settings.option.general.keybindings.open')}}
- +
From 429f09402c35c477bacda297ba40f12283b5f554 Mon Sep 17 00:00:00 2001 From: Amaru8 <52407090+Amaru8@users.noreply.github.com> Date: Tue, 26 Apr 2022 22:37:08 +0200 Subject: [PATCH 3/4] Use i18n string for Reset --- src/renderer/views/pages/settings.ejs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/renderer/views/pages/settings.ejs b/src/renderer/views/pages/settings.ejs index dde9eed5..d143dd04 100644 --- a/src/renderer/views/pages/settings.ejs +++ b/src/renderer/views/pages/settings.ejs @@ -245,7 +245,7 @@
From 260ee29d3bcd3dcaad97a470ba1015dcfa894674 Mon Sep 17 00:00:00 2001 From: Amaru8 <52407090+Amaru8@users.noreply.github.com> Date: Tue, 26 Apr 2022 22:38:29 +0200 Subject: [PATCH 4/4] Remove a random W character --- src/renderer/views/pages/settings.ejs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/renderer/views/pages/settings.ejs b/src/renderer/views/pages/settings.ejs index d143dd04..c3f06ae7 100644 --- a/src/renderer/views/pages/settings.ejs +++ b/src/renderer/views/pages/settings.ejs @@ -72,7 +72,7 @@
-
w +
{{ $root.getLz('term.recentlyAdded') }}