From 817fcfd0c21413b7041ecb95e1d53c906241d2bc Mon Sep 17 00:00:00 2001 From: Giulio De Matteis Date: Fri, 30 Jul 2021 16:38:46 +0200 Subject: [PATCH] Configure keyboard shortcuts --- package-lock.json | 111 +++++++++++++++++++++++++++++++++++++ package.json | 3 +- src/default-shortcuts.json | 12 ++++ src/main.js | 59 +++++++++++--------- 4 files changed, 159 insertions(+), 26 deletions(-) create mode 100644 src/default-shortcuts.json diff --git a/package-lock.json b/package-lock.json index 4b1e5f6..35e88d5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -127,6 +127,15 @@ "color-convert": "^1.9.0" } }, + "anymatch": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/anymatch/-/anymatch-3.1.2.tgz", + "integrity": "sha512-P43ePfOAIupkguHUycrc4qJ9kz8ZiuOUijaETwX7THt0Y/GNK7v0aa8rY816xWjZ7rJdA5XdMcpVFTKMq+RvWg==", + "requires": { + "normalize-path": "^3.0.0", + "picomatch": "^2.0.4" + } + }, "app-builder-bin": { "version": "3.4.3", "resolved": "https://registry.npmjs.org/app-builder-bin/-/app-builder-bin-3.4.3.tgz", @@ -284,6 +293,11 @@ "chainsaw": "~0.1.0" } }, + "binary-extensions": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/binary-extensions/-/binary-extensions-2.2.0.tgz", + "integrity": "sha512-jDctJ/IVQbZoJykoeHbhXpOlNBqGNcwXJKJog42E5HDPUwQTSdjCHdihjj0DlnheQ7blbT6dHOafNAiS8ooQKA==" + }, "bluebird": { "version": "3.7.2", "resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.7.2.tgz", @@ -344,6 +358,14 @@ "concat-map": "0.0.1" } }, + "braces": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.2.tgz", + "integrity": "sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==", + "requires": { + "fill-range": "^7.0.1" + } + }, "buffer-crc32": { "version": "0.2.13", "resolved": "https://registry.npmjs.org/buffer-crc32/-/buffer-crc32-0.2.13.tgz", @@ -505,6 +527,21 @@ "parse5": "^3.0.1" } }, + "chokidar": { + "version": "3.5.2", + "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-3.5.2.tgz", + "integrity": "sha512-ekGhOnNVPgT77r4K/U3GDhu+FQ2S8TnK/s2KbIGXi0SZWuwkZ2QNyfWdZW+TVfn84DpEP7rLeCt2UI6bJ8GwbQ==", + "requires": { + "anymatch": "~3.1.2", + "braces": "~3.0.2", + "fsevents": "~2.3.2", + "glob-parent": "~5.1.2", + "is-binary-path": "~2.1.0", + "is-glob": "~4.0.1", + "normalize-path": "~3.0.0", + "readdirp": "~3.6.0" + } + }, "chromium-pickle-js": { "version": "0.2.0", "resolved": "https://registry.npmjs.org/chromium-pickle-js/-/chromium-pickle-js-0.2.0.tgz", @@ -1194,6 +1231,14 @@ "pend": "~1.2.0" } }, + "fill-range": { + "version": "7.0.1", + "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz", + "integrity": "sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ==", + "requires": { + "to-regex-range": "^5.0.1" + } + }, "find-up": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/find-up/-/find-up-3.0.0.tgz", @@ -1233,6 +1278,12 @@ "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=" }, + "fsevents": { + "version": "2.3.2", + "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz", + "integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==", + "optional": true + }, "fstream": { "version": "1.0.12", "resolved": "https://registry.npmjs.org/fstream/-/fstream-1.0.12.tgz", @@ -1279,6 +1330,14 @@ "path-is-absolute": "^1.0.0" } }, + "glob-parent": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.2.tgz", + "integrity": "sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==", + "requires": { + "is-glob": "^4.0.1" + } + }, "global-agent": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/global-agent/-/global-agent-2.2.0.tgz", @@ -1478,6 +1537,14 @@ "resolved": "https://registry.npmjs.org/ip-regex/-/ip-regex-4.1.0.tgz", "integrity": "sha512-pKnZpbgCTfH/1NLIlOduP/V+WRXzC2MOz3Qo8xmxk8C5GudJLgK5QyLVXOSWy3ParAH7Eemurl3xjv/WXYFvMA==" }, + "is-binary-path": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/is-binary-path/-/is-binary-path-2.1.0.tgz", + "integrity": "sha512-ZMERYes6pDydyuGidse7OsHxtbI7WVeUEozgR/g7rd0xUimYNlvZRE/K2MgZTjWy725IfelLeVcEM97mmtRGXw==", + "requires": { + "binary-extensions": "^2.0.0" + } + }, "is-ci": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/is-ci/-/is-ci-2.0.0.tgz", @@ -1487,12 +1554,25 @@ "ci-info": "^2.0.0" } }, + "is-extglob": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/is-extglob/-/is-extglob-2.1.1.tgz", + "integrity": "sha1-qIwCU1eR8C7TfHahueqXc8gz+MI=" + }, "is-fullwidth-code-point": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-2.0.0.tgz", "integrity": "sha1-o7MKXE8ZkYMWeqq5O+764937ZU8=", "dev": true }, + "is-glob": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/is-glob/-/is-glob-4.0.1.tgz", + "integrity": "sha512-5G0tKtBTFImOqDnLB2hG6Bp2qcKEFduo4tZu9MT/H6NQv/ghhy30o55ufafxJ/LdH79LLs2Kfrn85TLKyA7BUg==", + "requires": { + "is-extglob": "^2.1.1" + } + }, "is-installed-globally": { "version": "0.1.0", "resolved": "https://registry.npmjs.org/is-installed-globally/-/is-installed-globally-0.1.0.tgz", @@ -1517,6 +1597,11 @@ "integrity": "sha512-wsigDr1Kkschp2opC4G3yA6r9EgVA6NjRpWzIi9axXqeIaAATPRJc4uLujXe3Nd9uO8KoDyA4MD6aZSeXTADhA==", "dev": true }, + "is-number": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz", + "integrity": "sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==" + }, "is-obj": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/is-obj/-/is-obj-1.0.1.tgz", @@ -1798,6 +1883,11 @@ } } }, + "normalize-path": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-3.0.0.tgz", + "integrity": "sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==" + }, "normalize-url": { "version": "4.5.1", "resolved": "https://registry.npmjs.org/normalize-url/-/normalize-url-4.5.1.tgz", @@ -1995,6 +2085,11 @@ "resolved": "https://registry.npmjs.org/performance-now/-/performance-now-2.1.0.tgz", "integrity": "sha1-Ywn04OX6kT7BxpMHrjZLSzd8nns=" }, + "picomatch": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.3.0.tgz", + "integrity": "sha512-lY1Q/PiJGC2zOv/z391WOTD+Z02bCgsFfvxoXXf6h7kv9o+WmsmzYqrAwY63sNgOxE4xEdq0WyUnXfKeBrSvYw==" + }, "pify": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/pify/-/pify-3.0.0.tgz", @@ -2136,6 +2231,14 @@ "util-deprecate": "~1.0.1" } }, + "readdirp": { + "version": "3.6.0", + "resolved": "https://registry.npmjs.org/readdirp/-/readdirp-3.6.0.tgz", + "integrity": "sha512-hOS089on8RduqdbhvQ5Z37A0ESjsqz6qnRcffsMU3495FuTdqSm+7bhJ29JvIOsBDEEnan5DPu9t3To9VRlMzA==", + "requires": { + "picomatch": "^2.2.1" + } + }, "registry-auth-token": { "version": "4.2.0", "resolved": "https://registry.npmjs.org/registry-auth-token/-/registry-auth-token-4.2.0.tgz", @@ -2570,6 +2673,14 @@ "resolved": "https://registry.npmjs.org/to-readable-stream/-/to-readable-stream-1.0.0.tgz", "integrity": "sha1-zgqgwvPfat+FLvtASng+d8BHV3E=" }, + "to-regex-range": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz", + "integrity": "sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==", + "requires": { + "is-number": "^7.0.0" + } + }, "tough-cookie": { "version": "2.5.0", "resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-2.5.0.tgz", diff --git a/package.json b/package.json index 6f7489b..cd8fef7 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "bandcamp-desktop", "productName": "Bandcamp Desktop", - "version": "2.3.8", + "version": "2.3.9", "description": "Bandcamp Desktop is a crossplatform desktop application. It allows you to use bandcamp.com in an easy and quick way. Keep listening to music while you explore the website.", "main": "src/main.js", "scripts": { @@ -21,6 +21,7 @@ "homepage": "https://github.com/themagiulio/bandcamp-desktop#readme", "dependencies": { "cheerio": "^1.0.0-rc.3", + "chokidar": "^3.5.2", "electron-download-manager": "^2.1.2", "electron-progressbar": "^1.2.0", "electron-store": "^6.0.1", diff --git a/src/default-shortcuts.json b/src/default-shortcuts.json new file mode 100644 index 0000000..115d8e9 --- /dev/null +++ b/src/default-shortcuts.json @@ -0,0 +1,12 @@ +{ + "Mini Player": "CmdOrCtrl+Space", + "Filters": "CmdOrCtrl+F", + "Library": "CmdOrCtrl+L", + "Bandcamp Desktop Player": "Shift+B", + "Change Library Folder Location": "Shift+L", + "Open in Browser Window": "CmdOrCtrl+O", + "Back": "CmdOrCtrl+Left", + "Forward": "CmdOrCtrl+Right", + "Minimize": "CmdOrCtrl+M", + "Close": "CmdOrCtrl+W" +} \ No newline at end of file diff --git a/src/main.js b/src/main.js index 94a7678..1dade37 100644 --- a/src/main.js +++ b/src/main.js @@ -16,15 +16,29 @@ const windowStateKeeper = require('electron-window-state'); let mainWindow; const store = new electonStore(); let downloadFolder = store.get('downloadFolder') === undefined ? app.getPath('downloads') + '/bandcamp-desktop/' : store.get('downloadFolder'); +let shortcutsPath = path.join(downloadFolder, '.shortcuts.json'); -if(!fs.existsSync(downloadFolder)){ - fs.mkdirSync(downloadFolder); +function openDialog(title, message){ + dialog.showMessageBoxSync(mainWindow, { + title: title, + message: message + }); +} + +if(!fs.existsSync(downloadFolder)) fs.mkdirSync(downloadFolder); + +if(!fs.existsSync(shortcutsPath)) { + fs.copyFileSync(path.join(__dirname, 'default-shortcuts.json'), shortcutsPath); } -downloadManager.register({ - downloadFolder: downloadFolder +const shortcuts = require(shortcutsPath); + +fs.watchFile(shortcutsPath, () => { + openDialog('Bandcamp Desktop', 'You need to restart the app in order to apply the changes.'); }); +downloadManager.register({ downloadFolder: downloadFolder }); + app.setName('Bandcamp Desktop'); app.allowRendererProcessReuse = true; app.on('ready', function(){ @@ -68,16 +82,8 @@ function createWindow(){ autoUpdater.checkForUpdatesAndNotify(); - function openDialog(title, message){ - const response = dialog.showMessageBox(mainWindow, - { - title: title, - message: message - }); - } - function about(){ - openDialog('Bandcamp Desktop - About', 'Bandcamp Desktop is a crossplatform desktop application which allows you to use bandcamp.com in an easy and quick way.\n\nVersion: v' + app.getVersion() + '\nDeveloped by: Giulio De Matteis \n\nBuilt using cheerio, electron framework, electron-builder, electron-download-manager, electron-progressbar, electron-store, electron-updater, electron-window-state, fs, is-online, request, unzipper and url packages with their dependecies.'); + openDialog('Bandcamp Desktop - About', 'Bandcamp Desktop is a crossplatform desktop application which allows you to use bandcamp.com in an easy and quick way.\n\nVersion: v' + app.getVersion() + '\nDeveloped by: Giulio De Matteis \n\nBuilt using cheerio, electron framework, electron-builder, electron-download-manager, electron-progressbar, electron-store, electron-updater, electron-window-state, is-online, request, unzipper and url packages with their dependecies.'); } function tag(tag){ @@ -115,7 +121,7 @@ function createWindow(){ submenu: [ { label: 'Mini Player', - accelerator: process.platform == 'darwin' ? 'Command+Space' : 'Ctrl+Space', + accelerator: shortcuts['Mini Player'], click(){ let webPageUrl = mainWindow.webContents.getURL(); var subdomain = webPageUrl.split('.')[1].replace('https://','') ? webPageUrl.split('.')[0].replace('https://','') : false; @@ -357,7 +363,7 @@ function createWindow(){ }, { label: 'Filters', - accelerator: process.platform == 'darwin' ? 'Command+F' : 'Ctrl+F', + accelerator: shortcuts['Filters'], click(){ mainWindow.loadURL(require('url').format({ pathname: 'bandcamp.com', @@ -371,7 +377,7 @@ function createWindow(){ }, { label: 'Library', - accelerator: process.platform == 'darwin' ? 'Command+L' : 'Ctrl+L', + accelerator: shortcuts['Library'], click(){ shell.openPath(downloadFolder) } @@ -382,7 +388,7 @@ function createWindow(){ submenu: [ { label: 'Bandcamp Desktop Player', - accelerator: 'Shift+B', + accelerator: shortcuts['Bandcamp Desktop Player'], type: 'checkbox', checked: store.get('bandCampDesktopPlayer') === undefined ? true : store.get('bandCampDesktopPlayer'), click(){ @@ -395,7 +401,7 @@ function createWindow(){ }, { label: 'Change Library Folder Location', - accelerator: 'Shift+L', + accelerator: shortcuts['Change Library Folder Location'], click(){ dialog.showOpenDialog(mainWindow, { properties: @@ -410,13 +416,19 @@ function createWindow(){ } }) } + }, + { + label: 'Change Keyboard Shortcuts', + click(){ + shell.openPath(shortcutsPath); + } } ] }, { type: 'separator' }, { label: 'Open in Browser Window', - accelerator: process.platform == 'darwin' ? 'Command+O' : 'Ctrl+O', + accelerator: shortcuts['Open in Browser Window'], click: async () => { await shell.openExternal(mainWindow.webContents.getURL()) } @@ -459,14 +471,14 @@ function createWindow(){ { role: 'forcereload' }, { label: 'Back', - accelerator: 'CmdOrCtrl+Left', + accelerator: shortcuts['Back'], click() { mainWindow.webContents.goBack() } }, { label: 'Forward', - accelerator: 'CmdOrCtrl+Right', + accelerator: shortcuts['Forward'], click() { mainWindow.webContents.goForward() } @@ -510,10 +522,7 @@ function createWindow(){ } ] - -const menu = Menu.buildFromTemplate(template) - Menu.setApplicationMenu(menu) - + Menu.setApplicationMenu(Menu.buildFromTemplate(template)); mainWindow.webContents.on('new-window', (event, url) => { event.preventDefault()