BluetoothStatus: update only devices that actually changed
When receiving a "devices-changed" signal from BluetoothApplet, check if some device item corresponds to an existing one, destroy the remaining and add the new ones. With this patch, signal emission when no device actually changed (which happen due to bluetoothd creating temporary devices) result in a no-op. https://bugzilla.gnome.org/show_bug.cgi?id=637690
This commit is contained in:
parent
23432e616d
commit
5f212b1ae2
@ -68,6 +68,7 @@ Indicator.prototype = {
|
|||||||
this._fullMenuItems = [new PopupMenu.PopupSeparatorMenuItem(),
|
this._fullMenuItems = [new PopupMenu.PopupSeparatorMenuItem(),
|
||||||
new PopupMenu.PopupMenuItem(_("Send Files to Device...")),
|
new PopupMenu.PopupMenuItem(_("Send Files to Device...")),
|
||||||
new PopupMenu.PopupMenuItem(_("Setup a New Device..."))];
|
new PopupMenu.PopupMenuItem(_("Setup a New Device..."))];
|
||||||
|
this._hasDevices = false;
|
||||||
this._deviceSep = this._fullMenuItems[0]; // hidden if no device exists
|
this._deviceSep = this._fullMenuItems[0]; // hidden if no device exists
|
||||||
|
|
||||||
this._fullMenuItems[1].connect('activate', function() {
|
this._fullMenuItems[1].connect('activate', function() {
|
||||||
@ -118,22 +119,56 @@ Indicator.prototype = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
_updateDevices: function() {
|
_deviceCompare: function(d1, d2) {
|
||||||
this._destroyAll(this._deviceItems);
|
return d1.device_path == d2.device_path &&
|
||||||
this._deviceItems = [];
|
d1.bdaddr == d2.bdaddr &&
|
||||||
|
d1.can_connect == d2.can_connect &&
|
||||||
|
d1.capabilities == d2.capabilities;
|
||||||
|
},
|
||||||
|
|
||||||
|
_updateDevices: function() {
|
||||||
let devices = this._applet.get_devices();
|
let devices = this._applet.get_devices();
|
||||||
let anydevice = false;
|
|
||||||
|
for (let i = 0; i < this._deviceItems.length; i++) {
|
||||||
|
let item = this._deviceItems.length;
|
||||||
|
let destroy = true;
|
||||||
|
for (let j = 0; j < devices.length; j++) {
|
||||||
|
// we need to deep compare because BluetoothSimpleDevice is a boxed type
|
||||||
|
// (but we take advantage of that, because _skip will disappear the next
|
||||||
|
// time get_devices() is called)
|
||||||
|
if (this._deviceCompare(item._device, devices[i])) {
|
||||||
|
item.label.text = devices[i].alias;
|
||||||
|
devices[i]._skip = true;
|
||||||
|
destroy = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (destroy) {
|
||||||
|
item.destroy();
|
||||||
|
item._destroyed = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let newlist = [ ];
|
||||||
|
for (let i = 0; i < this._deviceItems.length; i++) {
|
||||||
|
let item = this._deviceItems[i];
|
||||||
|
if (!item._destroyed)
|
||||||
|
newlist.push(item);
|
||||||
|
}
|
||||||
|
this._deviceItems = newlist;
|
||||||
|
|
||||||
|
this._hasDevices = newlist.length > 0;
|
||||||
for (let i = 0; i < devices.length; i++) {
|
for (let i = 0; i < devices.length; i++) {
|
||||||
let d = devices[i];
|
let d = devices[i];
|
||||||
|
if (d._skip)
|
||||||
|
continue;
|
||||||
let item = this._createDeviceItem(d);
|
let item = this._createDeviceItem(d);
|
||||||
if (item) {
|
if (item) {
|
||||||
this.menu.addMenuItem(item, this._deviceItemPosition + this._deviceItems.length);
|
this.menu.addMenuItem(item, this._deviceItemPosition + this._deviceItems.length);
|
||||||
this._deviceItems.push(item);
|
this._deviceItems.push(item);
|
||||||
anydevice = true;
|
this._hasDevices = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (anydevice)
|
if (this._hasDevices)
|
||||||
this._deviceSep.actor.show();
|
this._deviceSep.actor.show();
|
||||||
else
|
else
|
||||||
this._deviceSep.actor.hide();
|
this._deviceSep.actor.hide();
|
||||||
|
Loading…
Reference in New Issue
Block a user