-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathel-media-keys.html
56 lines (43 loc) · 1.25 KB
/
el-media-keys.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<link rel="import" href="../polymer/polymer.html">
<dom-module id="el-media-keys">
<script>
(function() {
'use strict';
const KEYS = {
NEXT: 'MediaNextTrack',
PREV: 'MediaPreviousTrack',
PLAY_PAUSE: 'MediaPlayPause'
};
Polymer({
is: 'el-media-keys',
ready() {
let remote = require('remote');
this._shortcut = remote.require('global-shortcut');
this._electron = remote.require('electron');
this._bind();
},
register(eventName, callback) {
this._shortcut.register(eventName, callback);
},
unregister(eventName) {
this._shortcut.unregister(eventName);
},
_bind() {
this.register(KEYS.NEXT, this._fire('next-track'));
this.register(KEYS.PREV, this._fire('previous-track'));
this.register(KEYS.PLAY_PAUSE, this._fire('play-pause'));
// When the app quits next, unbind these properly.
this._electron.app.on('quit', this._unbind);
},
_unbind() {
this.unregister(KEYS.NEXT);
this.unregister(KEYS.PREV);
this.unregister(KEYS.PLAY_PAUSE);
},
_fire(eventName) {
return () => this.fire(eventName);
}
});
}());
</script>
</dom-module>