Last active
November 20, 2019 13:07
-
-
Save twolfson/0a03820e27583cc9ad6e to your computer and use it in GitHub Desktop.
Proof of concept media key binding with atom-shell
This file contains hidden or 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
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Hello World!</title> | |
</head> | |
<body> | |
<h1>Hello World!</h1> | |
We are using node.js <script>document.write(process.version)</script> | |
and atom-shell <script>document.write(process.versions['atom-shell'])</script>. | |
</body> | |
</html> |
This file contains hidden or 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
var app = require('app'); // Module to control application life. | |
var BrowserWindow = require('browser-window'); // Module to create native browser window. | |
var globalShortcut = require('global-shortcut'); | |
// Report crashes to our server. | |
require('crash-reporter').start(); | |
// Keep a global reference of the window object, if you don't, the window will | |
// be closed automatically when the javascript object is GCed. | |
var mainWindow = null; | |
// Quit when all windows are closed. | |
app.on('window-all-closed', function() { | |
if (process.platform != 'darwin') | |
app.quit(); | |
}); | |
// This method will be called when atom-shell has done everything | |
// initialization and ready for creating browser windows. | |
app.on('ready', function() { | |
// Create the browser window. | |
mainWindow = new BrowserWindow({width: 800, height: 600}); | |
// and load the index.html of the app. | |
mainWindow.loadUrl('https://play.google.com/music'); | |
var registered = globalShortcut.register('medianexttrack', function () { | |
console.log('medianexttrack pressed'); | |
mainWindow.setSkipTaskbar(true); | |
}); | |
if (!registered) { | |
console.log('medianexttrack registration failed'); | |
} else { | |
console.log('medianexttrack registration bound!'); | |
} | |
var registered = globalShortcut.register('mediaplaypause', function () { | |
console.log('mediaplaypause pressed'); | |
mainWindow.setSkipTaskbar(false); | |
}); | |
if (!registered) { | |
console.log('mediaplaypause registration failed'); | |
} else { | |
console.log('mediaplaypause registration bound!'); | |
} | |
var registered = globalShortcut.register('mediaprevioustrack', function () { | |
console.log('mediaprevioustrack pressed'); | |
}); | |
if (!registered) { | |
console.log('mediaprevioustrack registration failed'); | |
} else { | |
console.log('mediaprevioustrack registration bound!'); | |
} | |
var registered = globalShortcut.register('mediastop', function () { | |
console.log('mediastop pressed'); | |
}); | |
if (!registered) { | |
console.log('mediastop registration failed'); | |
} else { | |
console.log('mediastop registration bound!'); | |
} | |
// Emitted when the window is closed. | |
mainWindow.on('closed', function() { | |
// Dereference the window object, usually you would store windows | |
// in an array if your app supports multi windows, this is the time | |
// when you should delete the corresponding element. | |
mainWindow = null; | |
}); | |
}); |
This file contains hidden or 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
{ | |
"name" : "your-app", | |
"version" : "0.1.0", | |
"main" : "main.js" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment