Skip to content

Instantly share code, notes, and snippets.

@codebytere
Last active June 16, 2020 16:20
Show Gist options
  • Save codebytere/a7e33c6f03a84dbcc2878859237422dd to your computer and use it in GitHub Desktop.
Save codebytere/a7e33c6f03a84dbcc2878859237422dd to your computer and use it in GitHub Desktop.
Electron Fiddle Gist
<!-- Empty -->
const {
app,
BrowserWindow,
globalShortcut,
systemPreferences
} = require('electron')
function createWindow () {
const mainWindow = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
nodeIntegration: true
}
})
mainWindow.loadURL('https://www.youtube.com/watch?v=Z5EpiaH155k')
registerMediaKeys()
}
app.on('ready', createWindow)
app.on('window-all-closed', function () {
if (process.platform !== 'darwin') {
app.quit()
}
})
app.on('activate', function () {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow()
}
})
const mediaKeys = {
'MediaPlayPause': () => {
console.log('PlayPause')
},
'MediaNextTrack': () => {
console.log('Next')
},
'MediaPreviousTrack': () => {
console.log('Prev')
},
'MediaStop': () => {
console.log('Stop')
}
}
function registerMediaKeys() {
systemPreferences.isTrustedAccessibilityClient(true)
for (let [accelerator, cb] of Object.entries(mediaKeys)) {
let registerSuccess = globalShortcut.register(accelerator, cb)
console.log('Was media key registered?', registerSuccess)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment