[gnome-shell] status/network: Track device sections as device sections



commit 58d29f95a76a8bd96af0bdb2e4d744217df10319
Author: Florian Müllner <fmuellner gnome org>
Date:   Thu Aug 4 16:47:22 2022 +0200

    status/network: Track device sections as device sections
    
    The _devices property is another case of overloading the
    "device" term.
    
    Fun fact:
    
      this._devices[device._delegate.category].devices
    
    uses three different meanings of "device" (section, NM.Device, item).
    
    The devices array in sections won't be around for much longer,
    but the property that tracks the sections is worth renaming.
    
    While at it, use a map instead of a plain object, which has a
    guaranteed order when iterating (which will come in handy later).
    
    Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2406>

 js/ui/status/network.js | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)
---
diff --git a/js/ui/status/network.js b/js/ui/status/network.js
index 05913d1796..c36be957fc 100644
--- a/js/ui/status/network.js
+++ b/js/ui/status/network.js
@@ -1784,7 +1784,7 @@ class Indicator extends PanelMenu.SystemIndicator {
         this._notification = null;
 
         this._nmDevices = [];
-        this._devices = { };
+        this._deviceSections = new Map();
 
         const categories = [
             NMConnectionCategory.WIRED,
@@ -1792,8 +1792,8 @@ class Indicator extends PanelMenu.SystemIndicator {
             NMConnectionCategory.WWAN,
         ];
         for (let category of categories) {
-            this._devices[category] = new DeviceCategory(category);
-            this.menu.addMenuItem(this._devices[category]);
+            this._deviceSections.set(category, new DeviceCategory(category));
+            this.menu.addMenuItem(this._deviceSections.get(category));
         }
 
         this._vpnSection = new NMVpnSection(this._client);
@@ -1924,10 +1924,10 @@ class Indicator extends PanelMenu.SystemIndicator {
         wrapper.connectObject('activation-failed',
             this._onActivationFailed.bind(this), this);
 
-        let section = this._devices[wrapper.category].section;
+        const {section} = this._deviceSections.get(wrapper.category);
         section.addMenuItem(wrapper.item);
 
-        let devices = this._devices[wrapper.category].devices;
+        const {devices} = this._deviceSections.get(wrapper.category);
         devices.push(wrapper);
     }
 
@@ -1951,7 +1951,7 @@ class Indicator extends PanelMenu.SystemIndicator {
         wrapper.disconnectObject(this);
         wrapper.destroy();
 
-        let devices = this._devices[wrapper.category].devices;
+        const {devices} = this._deviceSections.get(wrapper.category);
         let pos = devices.indexOf(wrapper);
         devices.splice(pos, 1);
     }
@@ -2058,7 +2058,7 @@ class Indicator extends PanelMenu.SystemIndicator {
         if (section == NMConnectionCategory.VPN) {
             this._vpnSection.removeConnection(connection);
         } else {
-            let devices = this._devices[section].devices;
+            const {devices} = this._deviceSections.get(section);
             for (let i = 0; i < devices.length; i++) {
                 if (devices[i] instanceof NMConnectionSection)
                     devices[i].removeConnection(connection);
@@ -2081,7 +2081,7 @@ class Indicator extends PanelMenu.SystemIndicator {
         if (section == NMConnectionCategory.VPN) {
             this._vpnSection.checkConnection(connection);
         } else {
-            let devices = this._devices[section].devices;
+            const {devices} = this._deviceSections.get(section);
             devices.forEach(wrapper => {
                 if (wrapper instanceof NMConnectionSection)
                     wrapper.checkConnection(connection);


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