SystemTray.js
3.26 KB
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/*
* Ext JS Library 0.30
* Copyright(c) 2006-2009, Ext JS, LLC.
* licensing@extjs.com
*
* http://extjs.com/license
*/
/**
* @class Ext.air.SystemTray
* @singleton
*
*
*
*/
Ext.air.SystemTray = function(){
var app = air.NativeApplication.nativeApplication;
var icon, isWindows = false, bitmaps;
// windows
if(air.NativeApplication.supportsSystemTrayIcon) {
icon = app.icon;
isWindows = true;
}
// mac
if(air.NativeApplication.supportsDockIcon) {
icon = app.icon;
}
return {
/**
* Sets the Icon and tooltip for the currently running application in the
* SystemTray or Dock depending on the operating system.
* @param {String} icon Icon to load with a URLRequest
* @param {String} tooltip Tooltip to use when mousing over the icon
* @param {Boolean} initWithIcon Boolean to initialize with icon immediately
*/
setIcon : function(icon, tooltip, initWithIcon){
if(!icon){ // not supported OS
return;
}
var loader = new air.Loader();
loader.contentLoaderInfo.addEventListener(air.Event.COMPLETE, function(e){
bitmaps = new runtime.Array(e.target.content.bitmapData);
if (initWithIcon) {
icon.bitmaps = bitmaps;
}
});
loader.load(new air.URLRequest(icon));
if(tooltip && air.NativeApplication.supportsSystemTrayIcon) {
app.icon.tooltip = tooltip;
}
},
/**
* Bounce the OS X dock icon. Accepts a priority to notify the user
* whether the event which has just occurred is informational (single bounce)
* or critcal (continual bounce).
* @param priority {air.NotificationType} The priorities are air.NotificationType.INFORMATIONAL and air.NotificationType.CRITICAL.
*/
bounce : function(priority){
icon.bounce(priority);
},
on : function(eventName, fn, scope){
icon.addEventListener(eventName, function(){
fn.apply(scope || this, arguments);
});
},
/**
* Hide the custom icon
*/
hideIcon : function(){
if(!icon){ // not supported OS
return;
}
icon.bitmaps = [];
},
/**
* Show the custom icon
*/
showIcon : function(){
if(!icon){ // not supported OS
return;
}
icon.bitmaps = bitmaps;
},
/**
* Sets a menu for the icon
* @param {Array} actions Configurations for Ext.air.MenuItem's
*/
setMenu: function(actions, _parentMenu){
if(!icon){ // not supported OS
return;
}
var menu = new air.NativeMenu();
for (var i = 0, len = actions.length; i < len; i++) {
var a = actions[i];
if(a == '-'){
menu.addItem(new air.NativeMenuItem("", true));
}else{
var item = menu.addItem(Ext.air.MenuItem(a));
if(a.menu || (a.initialConfig && a.initialConfig.menu)){
item.submenu = Ext.air.SystemTray.setMenu(a.menu || a.initialConfig.menu, menu);
}
}
if(!_parentMenu){
icon.menu = menu;
}
}
return menu;
}
};
}();