Skip to content

Commit

Permalink
fix: Make keyboard shortcuts local to the app
Browse files Browse the repository at this point in the history
This fixes #40, where the keyboard shortcuts were triggering even when
the application wasn't in focus.

Issues: #40
  • Loading branch information
bryankennedy committed Dec 19, 2018
1 parent aab4564 commit 63ee22f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 58 deletions.
6 changes: 1 addition & 5 deletions src/main.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import path from 'path';
import { createLogger, format } from 'winston';
import DailyRotateFile from 'winston-daily-rotate-file';
import MenuBuilder from './menu';
import registerKeyboardShortcuts from './registerKeyboardShortcuts';

// Setup global timer container
global.delayTimer = null;
Expand Down Expand Up @@ -263,11 +262,8 @@ app.on('ready', async () => {
event.returnValue = store.get('kiosk');
});

// Setup keyboard shortcuts
registerKeyboardShortcuts(mainWindow, reactHome);

// Setup application menu
const menuBuilder = new MenuBuilder(mainWindow);
const menuBuilder = new MenuBuilder(mainWindow, reactHome);
menuBuilder.buildMenu();

//
Expand Down
22 changes: 20 additions & 2 deletions src/menu.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { app, Menu, shell } from 'electron';
import { app, Menu, ipcMain, shell } from 'electron';
import log from 'electron-log';

export default class MenuBuilder {
constructor(mainWindow) {
constructor(mainWindow, reactHome) {
this.mainWindow = mainWindow;
this.reactHome = reactHome;
}

//
Expand Down Expand Up @@ -94,6 +96,22 @@ export default class MenuBuilder {
selector: 'orderFrontStandardAboutPanel:'
},
{ type: 'separator' },
{
label: 'Preferences...',
accelerator: 'Command+,',
click: (() => {
// Navigate to delay message during delay period
log.info('Window - Navigating to Settings with keyboard shortcut');
// TODO: Make this a function
// Make this little bit a function that you can import and reuse
this.mainWindow.loadURL(this.reactHome);
ipcMain.on('routerMounted', () => {
clearTimeout(global.delayTimer);
this.mainWindow.webContents.send('navigate', '/settings');
});
})
},
{ type: 'separator' },
{
label: 'Hide Stele',
accelerator: 'Command+H',
Expand Down
51 changes: 0 additions & 51 deletions src/registerKeyboardShortcuts.js

This file was deleted.

0 comments on commit 63ee22f

Please sign in to comment.