-
-
Notifications
You must be signed in to change notification settings - Fork 201
/
tray.js
77 lines (60 loc) · 1.34 KB
/
tray.js
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
define( [ "nwGui", "nwWindow", "ember" ], function( nwGui, nwWindow, Ember ) {
var get = Ember.get;
var isOSX = process.platform === "darwin";
return Ember.Object.extend({
init: function( name, icon ) {
this.setProperties({
name: name,
icon: icon,
tray: null,
menu: this._buildMenu()
});
},
remove: function() {
if ( this.tray ) {
this.tray.remove();
this.tray = null;
}
},
add: function( click ) {
this.tray = this._buildTray();
this.tray.on( "click", click );
},
iconRes: function() {
var dpr = window.devicePixelRatio;
var res = !isOSX || dpr > 2
? 48
: dpr > 1
? 32
: 16;
if ( isOSX ) {
res = "osx-" + res;
}
return get( this, "icon" ).replace( "{res}", res );
}.property( "icon" ),
_buildTray: function() {
var tray = new nwGui.Tray({
icon : get( this, "iconRes" ),
tooltip: get( this, "name" )
});
tray.menu = get( this, "menu" );
return tray;
},
_buildMenu: function() {
var menu = new nwGui.Menu();
menu.append( new nwGui.MenuItem({
label: "Toggle visibility",
click: function() {
this.tray.emit( "click" );
}.bind( this )
}) );
menu.append( new nwGui.MenuItem({
label: "Close application",
click: function() {
nwWindow.close();
}
}) );
return menu;
}
}).create();
});