-
-
Save codebytere/a7e33c6f03a84dbcc2878859237422dd to your computer and use it in GitHub Desktop.
Electron Fiddle Gist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- Empty --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Empty |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Empty |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Empty */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment