From 2d89551c4bfd8da8a8d706705d1d3c4f3a92f2d8 Mon Sep 17 00:00:00 2001 From: Jeffrey Knockel Date: Thu, 26 Sep 2024 19:52:17 -0400 Subject: [PATCH 1/2] network applet: fix accounting of menu indexes In _createSection() and _createNetworkItem(), previously we would skip the menu index in which the active network is present. If this index was < NUM_VISIBLE_NETWORKS, then we could display too few networks before we begin stashing them in the "more" menu. _accessPointAdded() is also refactored to more closely resemble the above two, but this is a nonbehavioral change. --- .../cinnamon/applets/network@cinnamon.org/applet.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/files/usr/share/cinnamon/applets/network@cinnamon.org/applet.js b/files/usr/share/cinnamon/applets/network@cinnamon.org/applet.js index eb6931a4b4..15f0290d3d 100644 --- a/files/usr/share/cinnamon/applets/network@cinnamon.org/applet.js +++ b/files/usr/share/cinnamon/applets/network@cinnamon.org/applet.js @@ -603,8 +603,10 @@ NMDevice.prototype = { for(let j = 0; j < this._connections.length; ++j) { let obj = this._connections[j]; if (this._activeConnection && - obj.connection == this._activeConnection.connection) + obj.connection == this._activeConnection.connection) { + activeOffset = 0; // we no longer need to account for this continue; + } obj.item = this._createConnectionItem(obj); if (j + activeOffset >= NUM_VISIBLE_NETWORKS) { @@ -1398,7 +1400,7 @@ NMDeviceWireless.prototype = { } // skip networks that should appear earlier - let menuPos = 0; + let menuPos = this._activeConnectionItem ? 1 : 0; for (pos = 0; pos < this._networks.length && this._networkSortFunction(this._networks[pos], apObj) < 0; ++pos) { @@ -1410,7 +1412,6 @@ NMDeviceWireless.prototype = { this._networks.splice(pos, 0, apObj); if (this._shouldShowConnectionList()) { - menuPos += (this._activeConnectionItem ? 1 : 0); this._createNetworkItem(apObj, menuPos); } } @@ -1703,8 +1704,10 @@ NMDeviceWireless.prototype = { for(let j = 0; j < this._networks.length; j++) { let apObj = this._networks[j]; - if (apObj == this._activeNetwork) + if (apObj == this._activeNetwork) { + activeOffset = 0; // we no longer need to account for this continue; + } this._createNetworkItem(apObj, j + activeOffset); } From bc8baf87e1f9886a683b0c07a2f7044ec3457b90 Mon Sep 17 00:00:00 2001 From: Jeffrey Knockel Date: Thu, 26 Sep 2024 20:02:23 -0400 Subject: [PATCH 2/2] network applet: keep visible networks under limit When adding a network, if we add it to a menu index < NUM_VISIBLE_NETWORKS, if we now have > NUM_VISIBLE_NETWORKS networks, we need to push the last visible network to being the first network in the "more" menu. Otherwise, we could end up with too many visible networks. When updating a network position, we first removed it from the menu. When doing this, if its original menu index was < NUM_VISIBLE_NETWORKS, then we need to bump the first network in the "more" menu to being the last visible network. We now do this by now calling the already existing _accessPointRemoved() method which handles this case. Otherwise, we could end up with too few visible networks. --- .../applets/network@cinnamon.org/applet.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/files/usr/share/cinnamon/applets/network@cinnamon.org/applet.js b/files/usr/share/cinnamon/applets/network@cinnamon.org/applet.js index 15f0290d3d..43d82db65c 100644 --- a/files/usr/share/cinnamon/applets/network@cinnamon.org/applet.js +++ b/files/usr/share/cinnamon/applets/network@cinnamon.org/applet.js @@ -1385,8 +1385,7 @@ NMDeviceWireless.prototype = { } if (needsupdate) { - if (apObj.item) - apObj.item.destroy(); + this._accessPointRemoved(device, accessPoint); if (pos != -1) this._networks.splice(pos, 1); @@ -1413,6 +1412,19 @@ NMDeviceWireless.prototype = { if (this._shouldShowConnectionList()) { this._createNetworkItem(apObj, menuPos); + if (menuPos < NUM_VISIBLE_NETWORKS && this._networks.length > NUM_VISIBLE_NETWORKS) { + for (; menuPos < NUM_VISIBLE_NETWORKS; ++pos) { + if (this._networks[pos] != this._activeNetwork) + menuPos++; + } + let item = this._networks[pos].item; + if (item && item._apObj) { + item.destroy(); + item._apObj.item = null; + + this._createNetworkItem(item._apObj, NUM_VISIBLE_NETWORKS); + } + } } } },