appIndicators: use arrow functions in lambdas
Marco Trevisan (TreviƱo) authored 5 years ago
Marco Trevisan committed 5 years ago
65 | 65 | g_name: bus_name, |
66 | 66 | g_object_path: object, |
67 | 67 | g_flags: Gio.DBusProxyFlags.GET_INVALIDATED_PROPERTIES }) |
68 | this._proxy.init_async(GLib.PRIORITY_DEFAULT, null, (function(initable, result) { | |
68 | this._proxy.init_async(GLib.PRIORITY_DEFAULT, null, ((initable, result) => { | |
69 | 69 | try { |
70 | 70 | initable.init_finish(result); |
71 | 71 | |
74 | 74 | } catch(e) { |
75 | 75 | Util.Logger.warn("While intializing proxy for "+bus_name+object+": "+e) |
76 | 76 | } |
77 | }).bind(this)) | |
77 | })) | |
78 | 78 | |
79 | 79 | this._proxyPropertyList = interface_info.properties.map((propinfo) => { return propinfo.name }) |
80 | 80 | this._addExtraProperty('XAyatanaLabel'); |
165 | 165 | _onPropertiesChanged: function(proxy, changed, invalidated) { |
166 | 166 | let props = Object.keys(changed.deep_unpack()) |
167 | 167 | |
168 | props.forEach(function(property) { | |
168 | props.forEach((property) => { | |
169 | 169 | // some property changes require updates on our part, |
170 | 170 | // a few need to be passed down to the displaying code |
171 | 171 | |
307 | 307 | // we try to avoid messing with the default icon theme, so we'll create a new one if needed |
308 | 308 | if (themePath) { |
309 | 309 | var icon_theme = new Gtk.IconTheme() |
310 | Gtk.IconTheme.get_default().get_search_path().forEach(function(path) { | |
310 | Gtk.IconTheme.get_default().get_search_path().forEach((path) => { | |
311 | 311 | icon_theme.append_search_path(path) |
312 | 312 | }); |
313 | 313 | icon_theme.append_search_path(themePath) |
356 | 356 | if (!iconPixmapArray || iconPixmapArray.length < 1) |
357 | 357 | return null |
358 | 358 | |
359 | let sortedIconPixmapArray = iconPixmapArray.sort(function(pixmapA, pixmapB) { | |
359 | let sortedIconPixmapArray = iconPixmapArray.sort((pixmapA, pixmapB) => { | |
360 | 360 | // we sort biggest to smallest |
361 | 361 | let areaA = pixmapA[0] * pixmapA[1] |
362 | 362 | let areaB = pixmapB[0] * pixmapB[1] |
364 | 364 | return areaB - areaA |
365 | 365 | }) |
366 | 366 | |
367 | let qualifiedIconPixmapArray = sortedIconPixmapArray.filter(function(pixmap) { | |
367 | let qualifiedIconPixmapArray = sortedIconPixmapArray.filter((pixmap) => { | |
368 | 368 | // we disqualify any pixmap that is bigger than our requested size |
369 | 369 | return pixmap[0] <= iconSize && pixmap[1] <= iconSize |
370 | 370 | }) |
177 | 177 | }, |
178 | 178 | |
179 | 179 | get_children: function() { |
180 | return this._children_ids.map(function(el) { | |
180 | return this._children_ids.map((el) => { | |
181 | 181 | return this._client.get_item(el) |
182 | 182 | }, this) |
183 | 183 | }, |
237 | 237 | if (this._propertiesRequestedFor.length < 1) |
238 | 238 | GLib.idle_add(GLib.PRIORITY_DEFAULT_IDLE, this._beginRequestProperties.bind(this)) |
239 | 239 | |
240 | if (this._propertiesRequestedFor.filter(function(e) { return e === id }).length == 0) | |
240 | if (this._propertiesRequestedFor.filter((e) => { return e === id }).length == 0) | |
241 | 241 | this._propertiesRequestedFor.push(id) |
242 | 242 | |
243 | 243 | }, |
257 | 257 | } |
258 | 258 | |
259 | 259 | // for some funny reason, the result array is hidden in an array |
260 | result[0].forEach(function([id, properties]) { | |
260 | result[0].forEach(([id, properties]) => { | |
261 | 261 | if (!(id in this._items)) |
262 | 262 | return |
263 | 263 | |
313 | 313 | _doLayoutUpdate: function(item) { |
314 | 314 | let [ id, properties, children ] = item |
315 | 315 | |
316 | let children_unpacked = children.map(function(child) { return child.deep_unpack() }) | |
317 | let children_ids = children_unpacked.map(function(child) { return child[0] }) | |
316 | let children_unpacked = children.map((child) => { return child.deep_unpack() }) | |
317 | let children_ids = children_unpacked.map((child) => { return child[0] }) | |
318 | 318 | |
319 | 319 | // make sure all our children exist |
320 | 320 | children_unpacked.forEach(this._doLayoutUpdate, this) |
348 | 348 | } |
349 | 349 | |
350 | 350 | // remove any old children that weren't reused |
351 | old_children_ids.forEach(function(child_id) { this._items[id].remove_child(child_id) }, this) | |
351 | old_children_ids.forEach((child_id) => { this._items[id].remove_child(child_id) }, this) | |
352 | 352 | } else { |
353 | 353 | // we don't, so let's create us |
354 | 354 | this._items[id] = new DbusMenuItem(this, id, properties, children_ids) |
381 | 381 | |
382 | 382 | // we don't need to cache and burst-send that since it will not happen that frequently |
383 | 383 | send_about_to_show: function(id) { |
384 | this._proxy.AboutToShowRemote(id, (function(result, error) { | |
384 | this._proxy.AboutToShowRemote(id, ((result, error) => { | |
385 | 385 | if (error) |
386 | 386 | Util.Logger.warn("while calling AboutToShow: "+error) |
387 | 387 | else if (result && result[0]) |
388 | 388 | this._requestLayoutUpdate() |
389 | }).bind(this)) | |
389 | })) | |
390 | 390 | }, |
391 | 391 | |
392 | 392 | send_event: function(id, event, params, timestamp) { |
401 | 401 | }, |
402 | 402 | |
403 | 403 | _onPropertiesUpdated: function(proxy, name, [changed, removed]) { |
404 | changed.forEach(function([id, props]) { | |
404 | changed.forEach(([id, props]) => { | |
405 | 405 | if (!(id in this._items)) |
406 | 406 | return |
407 | 407 | |
408 | 408 | for (let prop in props) |
409 | 409 | this._items[id].property_set(prop, props[prop]) |
410 | 410 | }, this) |
411 | removed.forEach(function([id, propNames]) { | |
411 | removed.forEach(([id, propNames]) => { | |
412 | 412 | if (!(id in this._items)) |
413 | 413 | return |
414 | 414 | |
415 | propNames.forEach(function(propName) { | |
415 | propNames.forEach((propName) => { | |
416 | 416 | this._items[id].property_set(propName, null) |
417 | 417 | }, this) |
418 | 418 | }, this) |
555 | 555 | MenuItemFactory._replaceSelf.call(this) |
556 | 556 | } else { |
557 | 557 | // find it! |
558 | this.menu._getMenuItems().forEach(function(item) { | |
558 | this.menu._getMenuItems().forEach((item) => { | |
559 | 559 | if (item._dbusItem == child) |
560 | 560 | item.destroy() |
561 | 561 | }) |
702 | 702 | this._rootItem.send_about_to_show() |
703 | 703 | |
704 | 704 | // fill the menu for the first time |
705 | this._rootItem.get_children().forEach(function(child) { | |
705 | this._rootItem.get_children().forEach((child) => { | |
706 | 706 | this._rootMenu.addMenuItem(MenuItemFactory.createItem(this, child)) |
707 | 707 | }, this) |
708 | 708 | }, |
730 | 730 | _onRootChildRemoved: function(dbusItem, child) { |
731 | 731 | // children like to play hide and seek |
732 | 732 | // but we know how to find it for sure! |
733 | this._rootMenu._getMenuItems().forEach(function(item) { | |
733 | this._rootMenu._getMenuItems().forEach((item) => { | |
734 | 734 | if (item._dbusItem == child) |
735 | 735 | item.destroy() |
736 | 736 | }) |
33 | 33 | if (typeof global['--appindicator-extension-on-reload'] == 'function') |
34 | 34 | global['--appindicator-extension-on-reload']() |
35 | 35 | |
36 | global['--appindicator-extension-on-reload'] = function() { | |
36 | global['--appindicator-extension-on-reload'] = () => { | |
37 | 37 | Util.Logger.debug("Reload detected, destroying old watchdog") |
38 | 38 | NameWatchdog.destroy() |
39 | 39 | } |
8 | 8 | const AppIndicator = imports.gi.AppIndicator3; |
9 | 9 | const GLib = imports.gi.GLib; |
10 | 10 | |
11 | (function() { | |
11 | (() => { | |
12 | 12 | |
13 | 13 | var app = new Gtk.Application({ |
14 | 14 | application_id: null |
16 | 16 | |
17 | 17 | var window = null; |
18 | 18 | |
19 | app.connect("activate", function(){ | |
19 | app.connect("activate", () => { | |
20 | 20 | window.present(); |
21 | 21 | }); |
22 | 22 | |
23 | app.connect("startup", function() { | |
23 | app.connect("startup", () => { | |
24 | 24 | window = new Gtk.ApplicationWindow({ |
25 | 25 | title: "test", |
26 | 26 | application: app |
96 | 96 | menu.append(item); |
97 | 97 | |
98 | 98 | item = Gtk.MenuItem.new_with_label("Set Label"); |
99 | item.connect('activate', function() { | |
99 | item.connect('activate', () => { | |
100 | 100 | indicator.set_label(''+new Date().getSeconds(), 'Blub'); |
101 | 101 | }); |
102 | 102 | menu.append(item); |
103 | 103 | |
104 | 104 | item = Gtk.MenuItem.new_with_label("Unset Label"); |
105 | item.connect('activate', function() { | |
105 | item.connect('activate', () => { | |
106 | 106 | indicator.set_label('', ''); |
107 | 107 | }) |
108 | 108 | menu.append(item); |
111 | 111 | menu.append(item); |
112 | 112 | |
113 | 113 | item = Gtk.MenuItem.new_with_label("Hide for some time"); |
114 | item.connect('activate', function() { | |
114 | item.connect('activate', () => { | |
115 | 115 | indicator.set_status(AppIndicator.IndicatorStatus.PASSIVE); |
116 | GLib.timeout_add(0, 5000, function() { | |
116 | GLib.timeout_add(0, 5000, () => { | |
117 | 117 | indicator.set_status(AppIndicator.IndicatorStatus.ACTIVE); |
118 | 118 | return false; |
119 | 119 | }); |
121 | 121 | menu.append(item); |
122 | 122 | |
123 | 123 | item = Gtk.MenuItem.new_with_label("Close in 5 seconds"); |
124 | item.connect('activate', function() { | |
125 | GLib.timeout_add(0, 5000, function() { | |
124 | item.connect('activate', () => { | |
125 | GLib.timeout_add(0, 5000, () => { | |
126 | 126 | app.quit(); |
127 | 127 | return false; |
128 | 128 | }); |
58 | 58 | this._nameWatcher = { }; |
59 | 59 | |
60 | 60 | this._seekStatusNotifierItems(); |
61 | }, | |
61 | } | |
62 | 62 | |
63 | 63 | _acquiredName: function() { |
64 | 64 | this._everAcquiredName = true; |
136 | 136 | let id = src.connect(signal, handler) |
137 | 137 | |
138 | 138 | if (src.connect && (!(src instanceof GObject.Object) || GObject.signal_lookup('destroy', src))) { |
139 | let destroy_id = src.connect('destroy', function() { | |
139 | let destroy_id = src.connect('destroy', () => { | |
140 | 140 | src.disconnect(id) |
141 | 141 | src.disconnect(destroy_id) |
142 | 142 | }) |
170 | 170 | * Usage: |
171 | 171 | * Util.connectSmart(srcOb, 'signal', tgtObj, 'handler') |
172 | 172 | * or |
173 | * Util.connectSmart(srcOb, 'signal', function() { ... }) | |
173 | * Util.connectSmart(srcOb, 'signal', () => { ... }) | |
174 | 174 | */ |
175 | 175 | var connectSmart = function() { |
176 | 176 | if (arguments.length == 4) |