Skip to content

Commit

Permalink
Fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
scriptspry committed Jul 18, 2020
1 parent d3db647 commit de4c1de
Show file tree
Hide file tree
Showing 3 changed files with 744 additions and 1,148 deletions.
26 changes: 17 additions & 9 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,23 +108,31 @@ function createWindow() {
// client side code listened to these keys along with KEY_NEXT, KEY_SPACE etc.
// For now trigger functionality by remapping the keys
globalShortcut.register('MediaPlayPause', function () {
webView.sendInputEvent({
type: 'keyDown',
keyCode: 'Space'
webView.executeJavaScript(`(() => {
let isPlaying = document.querySelector('.c-player__btn > .o-icon-pause') != null;
if (isPlaying)
document.querySelector('.c-player__btn > .o-icon-pause').click();
else
document.querySelector('.c-player__btn > .o-icon-play').click();
})();
`, true).catch((e) => {
console.error('Something went wrong', e)
})
})

globalShortcut.register('MediaNextTrack', function () {
webView.sendInputEvent({
type: 'keyDown',
keyCode: 'Right'
webView.executeJavaScript(`
document.querySelector('.o-icon-next').click();
`, true).catch((e) => {
console.error('Something went wrong', e)
})
})

globalShortcut.register('MediaPreviousTrack', function () {
webView.sendInputEvent({
type: 'keyDown',
keyCode: 'Left'
webView.executeJavaScript(`
document.querySelector('.o-icon-previous').click();
`, true).catch((e) => {
console.error('Something went wrong', e)
})
})

Expand Down
Loading

0 comments on commit de4c1de

Please sign in to comment.