[gnome-shell] bluetooth: Do not sync() immediately on model changes



commit 456ca3d3e09b761f6506497444306a8cf3c4ffe7
Author: Florian Müllner <fmuellner gnome org>
Date:   Fri Apr 3 20:27:34 2020 +0200

    bluetooth: Do not sync() immediately on model changes
    
    Our intended behavior when bluetooth is turned off is to keep
    the menu visible if devices had been set up previously.
    
    However since gnome-bluetooth@c437c729, devices are removed
    first before removing the default adapter, so we now end up
    always setting the property to false before checking for it.
    
    Fix this by deferring all model changes to an idle, so that
    we can process them as a unit. Do the same for proxy property
    changes, as those may trigger a row-removal.
    
    https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1174

 js/ui/status/bluetooth.js | 20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)
---
diff --git a/js/ui/status/bluetooth.js b/js/ui/status/bluetooth.js
index 0c43749fee..a5b714ccc7 100644
--- a/js/ui/status/bluetooth.js
+++ b/js/ui/status/bluetooth.js
@@ -1,7 +1,7 @@
 // -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
 /* exported Indicator */
 
-const { Gio, GnomeBluetooth, GObject } = imports.gi;
+const { Gio, GLib, GnomeBluetooth, GObject } = imports.gi;
 
 const Main = imports.ui.main;
 const PanelMenu = imports.ui.panelMenu;
@@ -35,7 +35,7 @@ class Indicator extends PanelMenu.SystemIndicator {
 
                                                  this._sync();
                                              });
-        this._proxy.connect('g-properties-changed', this._sync.bind(this));
+        this._proxy.connect('g-properties-changed', this._queueSync.bind(this));
 
         this._item = new PopupMenu.PopupSubMenuMenuItem(_("Bluetooth"), true);
         this._item.icon.icon_name = 'bluetooth-active-symbolic';
@@ -49,10 +49,12 @@ class Indicator extends PanelMenu.SystemIndicator {
         this._item.menu.addSettingsAction(_("Bluetooth Settings"), 'gnome-bluetooth-panel.desktop');
         this.menu.addMenuItem(this._item);
 
+        this._syncId = 0;
+
         this._client = new GnomeBluetooth.Client();
         this._model = this._client.get_model();
-        this._model.connect('row-changed', this._sync.bind(this));
-        this._model.connect('row-deleted', this._sync.bind(this));
+        this._model.connect('row-deleted', this._queueSync.bind(this));
+        this._model.connect('row-changed', this._queueSync.bind(this));
         this._model.connect('row-inserted', this._sync.bind(this));
         Main.sessionMode.connect('updated', this._sync.bind(this));
         this._sync();
@@ -104,6 +106,16 @@ class Indicator extends PanelMenu.SystemIndicator {
         return deviceInfos;
     }
 
+    _queueSync() {
+        if (this._syncId)
+            return;
+        this._syncId = GLib.idle_add(GLib.PRIORITY_DEFAULT, () => {
+            this._syncId = 0;
+            this._sync();
+            return GLib.SOURCE_REMOVE;
+        });
+    }
+
     _sync() {
         let adapter = this._getDefaultAdapter();
         let devices = this._getDeviceInfos(adapter);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]