1 | /* |
---|
2 | * Ext JS Library 0.30 |
---|
3 | * Copyright(c) 2006-2009, Ext JS, LLC. |
---|
4 | * licensing@extjs.com |
---|
5 | * |
---|
6 | * http://extjs.com/license |
---|
7 | */ |
---|
8 | |
---|
9 | /** |
---|
10 | * @class Ext.air.SystemTray |
---|
11 | * @singleton |
---|
12 | * |
---|
13 | * |
---|
14 | * |
---|
15 | */ |
---|
16 | Ext.air.SystemTray = function(){ |
---|
17 | var app = air.NativeApplication.nativeApplication; |
---|
18 | var icon, isWindows = false, bitmaps; |
---|
19 | |
---|
20 | // windows |
---|
21 | if(air.NativeApplication.supportsSystemTrayIcon) { |
---|
22 | icon = app.icon; |
---|
23 | isWindows = true; |
---|
24 | } |
---|
25 | |
---|
26 | // mac |
---|
27 | if(air.NativeApplication.supportsDockIcon) { |
---|
28 | icon = app.icon; |
---|
29 | } |
---|
30 | |
---|
31 | return { |
---|
32 | /** |
---|
33 | * Sets the Icon and tooltip for the currently running application in the |
---|
34 | * SystemTray or Dock depending on the operating system. |
---|
35 | * @param {String} icon Icon to load with a URLRequest |
---|
36 | * @param {String} tooltip Tooltip to use when mousing over the icon |
---|
37 | * @param {Boolean} initWithIcon Boolean to initialize with icon immediately |
---|
38 | */ |
---|
39 | setIcon : function(icon, tooltip, initWithIcon){ |
---|
40 | if(!icon){ // not supported OS |
---|
41 | return; |
---|
42 | } |
---|
43 | var loader = new air.Loader(); |
---|
44 | loader.contentLoaderInfo.addEventListener(air.Event.COMPLETE, function(e){ |
---|
45 | bitmaps = new runtime.Array(e.target.content.bitmapData); |
---|
46 | if (initWithIcon) { |
---|
47 | icon.bitmaps = bitmaps; |
---|
48 | } |
---|
49 | }); |
---|
50 | |
---|
51 | loader.load(new air.URLRequest(icon)); |
---|
52 | if(tooltip && air.NativeApplication.supportsSystemTrayIcon) { |
---|
53 | app.icon.tooltip = tooltip; |
---|
54 | } |
---|
55 | }, |
---|
56 | |
---|
57 | /** |
---|
58 | * Bounce the OS X dock icon. Accepts a priority to notify the user |
---|
59 | * whether the event which has just occurred is informational (single bounce) |
---|
60 | * or critcal (continual bounce). |
---|
61 | * @param priority {air.NotificationType} The priorities are air.NotificationType.INFORMATIONAL and air.NotificationType.CRITICAL. |
---|
62 | */ |
---|
63 | bounce : function(priority){ |
---|
64 | icon.bounce(priority); |
---|
65 | }, |
---|
66 | |
---|
67 | on : function(eventName, fn, scope){ |
---|
68 | icon.addEventListener(eventName, function(){ |
---|
69 | fn.apply(scope || this, arguments); |
---|
70 | }); |
---|
71 | }, |
---|
72 | |
---|
73 | /** |
---|
74 | * Hide the custom icon |
---|
75 | */ |
---|
76 | hideIcon : function(){ |
---|
77 | if(!icon){ // not supported OS |
---|
78 | return; |
---|
79 | } |
---|
80 | icon.bitmaps = []; |
---|
81 | }, |
---|
82 | |
---|
83 | /** |
---|
84 | * Show the custom icon |
---|
85 | */ |
---|
86 | showIcon : function(){ |
---|
87 | if(!icon){ // not supported OS |
---|
88 | return; |
---|
89 | } |
---|
90 | icon.bitmaps = bitmaps; |
---|
91 | }, |
---|
92 | |
---|
93 | /** |
---|
94 | * Sets a menu for the icon |
---|
95 | * @param {Array} actions Configurations for Ext.air.MenuItem's |
---|
96 | */ |
---|
97 | setMenu: function(actions, _parentMenu){ |
---|
98 | if(!icon){ // not supported OS |
---|
99 | return; |
---|
100 | } |
---|
101 | var menu = new air.NativeMenu(); |
---|
102 | |
---|
103 | for (var i = 0, len = actions.length; i < len; i++) { |
---|
104 | var a = actions[i]; |
---|
105 | if(a == '-'){ |
---|
106 | menu.addItem(new air.NativeMenuItem("", true)); |
---|
107 | }else{ |
---|
108 | var item = menu.addItem(Ext.air.MenuItem(a)); |
---|
109 | if(a.menu || (a.initialConfig && a.initialConfig.menu)){ |
---|
110 | item.submenu = Ext.air.SystemTray.setMenu(a.menu || a.initialConfig.menu, menu); |
---|
111 | } |
---|
112 | } |
---|
113 | |
---|
114 | if(!_parentMenu){ |
---|
115 | icon.menu = menu; |
---|
116 | } |
---|
117 | } |
---|
118 | |
---|
119 | return menu; |
---|
120 | } |
---|
121 | }; |
---|
122 | }(); |
---|