Skip to content

Commit

Permalink
fix: media shortcut
Browse files Browse the repository at this point in the history
  • Loading branch information
zenghongtu committed May 16, 2019
1 parent d3d81be commit 324d978
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
9 changes: 6 additions & 3 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@ export const THEME_URL = 'settings/theme_url';

export const DEFAULT_GLOBAL_SHORTCUT = {
'CommandOrControl+Alt+Right': 'nextTrack',
'MediaNextTrack': 'nextTrack',
'CommandOrControl+Alt+Left': 'prevTrack',
'MediaPreviousTrack': 'prevTrack',
'CommandOrControl+Alt+Up': 'volumeUp',
'CommandOrControl+Alt+Down': 'volumeDown',
'CommandOrControl+Alt+S': 'changePlayState',
'MediaPlayPause': 'changePlayState',
};

export const DEFAULT_MEDIA_SHORTCUT = {
MediaPreviousTrack: 'prevTrack',
MediaNextTrack: 'nextTrack',
MediaPlayPause: 'changePlayState',
};
7 changes: 5 additions & 2 deletions src/main/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
BACKGROUND_IMAGE_URL,
UPDATE_THEME,
THEME_URL,
DEFAULT_MEDIA_SHORTCUT,
} from '../constants';
import { settings } from './db';
import {
Expand Down Expand Up @@ -239,9 +240,11 @@ function createWindow() {
}

const registerHotkeys = (shortcuts) => {
Object.keys(shortcuts).forEach((key) => {
const newShortcuts = { ...DEFAULT_MEDIA_SHORTCUT, ...shortcuts };
globalShortcut.unregisterAll();
Object.keys(newShortcuts).forEach((key) => {
globalShortcut.register(key, () => {
mainWindow.webContents.send(TRIGGER_HOTKEY, shortcuts[key]);
mainWindow.webContents.send(TRIGGER_HOTKEY, newShortcuts[key]);
});
});
};
Expand Down

0 comments on commit 324d978

Please sign in to comment.