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>
This commit is contained in:
Florian Müllner 2022-08-04 16:47:22 +02:00
parent 586bb29b9c
commit 58d29f95a7

View File

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