Skip to content
This repository has been archived by the owner on Nov 22, 2021. It is now read-only.

Commit

Permalink
Avoid triggering shortcuts while typing text input
Browse files Browse the repository at this point in the history
  • Loading branch information
salomvary committed Feb 25, 2018
1 parent 8fea8f6 commit 0e560e0
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions app/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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', () => {
Expand Down

0 comments on commit 0e560e0

Please sign in to comment.