Skip to content

Commit

Permalink
network applet: fixes to # of visible networks (#12417)
Browse files Browse the repository at this point in the history
* 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.

* 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.
  • Loading branch information
jknockel authored Nov 25, 2024
1 parent 2047cb3 commit 998f54e
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions files/usr/share/cinnamon/applets/[email protected]/applet.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -1383,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);
Expand All @@ -1398,7 +1399,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) {
Expand All @@ -1410,8 +1411,20 @@ NMDeviceWireless.prototype = {
this._networks.splice(pos, 0, apObj);

if (this._shouldShowConnectionList()) {
menuPos += (this._activeConnectionItem ? 1 : 0);
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);
}
}
}
}
},
Expand Down Expand Up @@ -1703,8 +1716,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);
}
Expand Down

0 comments on commit 998f54e

Please sign in to comment.