From 0e560e0812ff1b9b8f0eeee514fc244179ebcba1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1rton=20Salomv=C3=A1ry?= Date: Sun, 25 Feb 2018 22:15:11 +0100 Subject: [PATCH] Avoid triggering shortcuts while typing text input --- app/main.js | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/app/main.js b/app/main.js index 5135088..5938653 100644 --- a/app/main.js +++ b/app/main.js @@ -111,6 +111,13 @@ app.on('ready', () => { } }) + // Only send commands from menu accelerators when the app is not focused. + // This avoids double-triggering actions and triggering actions during text + // is entered into the search input or in other places. + function isNotFocused() { + return !mainWindow || !mainWindow.isFocused() + } + mainWindow.on('closed', () => { if (process.platform !== 'darwin') app.quit() @@ -130,35 +137,35 @@ app.on('ready', () => { }) menu.events.on('playPause', () => { - soundcloud.playPause() + if (isNotFocused()) soundcloud.playPause() }) menu.events.on('likeUnlike', () => { - soundcloud.likeUnlike() + if (isNotFocused()) soundcloud.likeUnlike() }) menu.events.on('repost', () => { - soundcloud.repost() + if (isNotFocused()) soundcloud.repost() }) menu.events.on('nextTrack', () => { - soundcloud.nextTrack() + if (isNotFocused()) soundcloud.nextTrack() }) menu.events.on('previousTrack', () => { - soundcloud.previousTrack() + if (isNotFocused()) soundcloud.previousTrack() }) menu.events.on('home', () => { - soundcloud.goHome() + if (isNotFocused()) soundcloud.goHome() }) menu.events.on('back', () => { - soundcloud.goBack() + if (isNotFocused()) soundcloud.goBack() }) menu.events.on('forward', () => { - soundcloud.goForward() + if (isNotFocused()) soundcloud.goForward() }) menu.events.on('main-window', () => {