Skip to content

Commit

Permalink
Configure keyboard shortcuts
Browse files Browse the repository at this point in the history
  • Loading branch information
themagiulio committed Jul 30, 2021
1 parent 8d45ea8 commit 817fcfd
Show file tree
Hide file tree
Showing 4 changed files with 159 additions and 26 deletions.
111 changes: 111 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand All @@ -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",
Expand Down
12 changes: 12 additions & 0 deletions src/default-shortcuts.json
Original file line number Diff line number Diff line change
@@ -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"
}
59 changes: 34 additions & 25 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(){
Expand Down Expand Up @@ -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 <[email protected]>\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 <[email protected]>\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){
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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',
Expand All @@ -371,7 +377,7 @@ function createWindow(){
},
{
label: 'Library',
accelerator: process.platform == 'darwin' ? 'Command+L' : 'Ctrl+L',
accelerator: shortcuts['Library'],
click(){
shell.openPath(downloadFolder)
}
Expand All @@ -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(){
Expand All @@ -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:
Expand All @@ -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())
}
Expand Down Expand Up @@ -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()
}
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 817fcfd

Please sign in to comment.