From 54ffbb053ae18507b5b9532db424d17a9c0917cf Mon Sep 17 00:00:00 2001 From: Peter Boughton Date: Fri, 7 May 2021 13:59:58 +0100 Subject: [PATCH 1/2] network applet: Add settings for wireless network list. --- .../applets/network@cinnamon.org/applet.js | 26 ++++++++++++++----- .../network@cinnamon.org/settings-schema.json | 15 +++++++++++ 2 files changed, 34 insertions(+), 7 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 c17799b487..78e705bf2f 100644 --- a/files/usr/share/cinnamon/applets/network@cinnamon.org/applet.js +++ b/files/usr/share/cinnamon/applets/network@cinnamon.org/applet.js @@ -40,9 +40,10 @@ const NM80211Mode = NM['80211Mode']; const NM80211ApFlags = NM['80211ApFlags']; const NM80211ApSecurityFlags = NM['80211ApSecurityFlags']; -// number of wireless networks that should be visible -// (the remaining are placed into More...) -const NUM_VISIBLE_NETWORKS = 5; +const APPLET_SETTINGS = { + num_visible_networks: 5, + hide_other_networks_when_connected: false +}; var NMIface = '\ \ @@ -595,6 +596,8 @@ NMDevice.prototype = { if (this._activeConnection) { this._createActiveConnectionItem(); this.section.addMenuItem(this._activeConnectionItem); + if (APPLET_SETTINGS.hide_other_networks_when_connected) + return; } if (this._connections.length > 0) { let activeOffset = this._activeConnectionItem ? 1 : 0; @@ -606,7 +609,7 @@ NMDevice.prototype = { continue; obj.item = this._createConnectionItem(obj); - if (j + activeOffset >= NUM_VISIBLE_NETWORKS) { + if (j + activeOffset >= APPLET_SETTINGS.num_visible_networks) { if (!this._overflowItem) { this._overflowItem = new PopupMenu.PopupSubMenuMenuItem(_("More")); this.section.addMenuItem(this._overflowItem); @@ -1384,7 +1387,7 @@ NMDeviceWireless.prototype = { // clear the cycle, and allow the construction of the new item item._apObj.item = null; - this._createNetworkItem(item._apObj, NUM_VISIBLE_NETWORKS-1); + this._createNetworkItem(item._apObj, APPLET_SETTINGS.num_visible_networks-1); } else { log('The more... menu was existing and empty! This should not happen'); } @@ -1616,7 +1619,10 @@ NMDeviceWireless.prototype = { } apObj.item._apObj = apObj; - if (position < NUM_VISIBLE_NETWORKS) { + if (this._activeConnectionItem && APPLET_SETTINGS.hide_other_networks_when_connected) + return; + + if (position < APPLET_SETTINGS.num_visible_networks) { apObj.isMore = false; this.section.addMenuItem(apObj.item, position); } else { @@ -1624,7 +1630,7 @@ NMDeviceWireless.prototype = { this._overflowItem = new PopupMenu.PopupSubMenuMenuItem(_("More")); this.section.addMenuItem(this._overflowItem); } - this._overflowItem.menu.addMenuItem(apObj.item, position - NUM_VISIBLE_NETWORKS); + this._overflowItem.menu.addMenuItem(apObj.item, position - APPLET_SETTINGS.num_visible_networks); apObj.isMore = true; } }, @@ -1636,6 +1642,8 @@ NMDeviceWireless.prototype = { if(this._activeConnection) { this._createActiveConnectionItem(); this.section.addMenuItem(this._activeConnectionItem); + if (APPLET_SETTINGS.hide_other_networks_when_connected) + return; } let activeOffset = this._activeConnectionItem ? 1 : 0; @@ -1692,6 +1700,10 @@ CinnamonNetworkApplet.prototype = { this.settings = new Settings.AppletSettings(this, metadata.uuid, this.instance_id); this.settings.bind("keyOpen", "keyOpen", this._setKeybinding); + this.settings.bind("num-visible-networks", "num_visible_networks"); + this.settings.bind("hide-other-networks-when-connected", "hide_other_networks_when_connected"); + APPLET_SETTINGS.num_visible_networks = this.num_visible_networks; + APPLET_SETTINGS.hide_other_networks_when_connected = this.hide_other_networks_when_connected; this._setKeybinding(); NM.Client.new_async(null, Lang.bind(this, this._clientGot)); diff --git a/files/usr/share/cinnamon/applets/network@cinnamon.org/settings-schema.json b/files/usr/share/cinnamon/applets/network@cinnamon.org/settings-schema.json index ce51043e80..967bf05508 100644 --- a/files/usr/share/cinnamon/applets/network@cinnamon.org/settings-schema.json +++ b/files/usr/share/cinnamon/applets/network@cinnamon.org/settings-schema.json @@ -8,5 +8,20 @@ "description": "Show menu", "default": "n", "tooltip": "Set keybinding(s) to show the network applet menu." + }, + "num-visible-networks": { + "type" : "spinbutton", + "default" : 5, + "min" : 1, + "max" : 10, + "step" : 1, + "description" : "Wireless networks listed in panel", + "tooltip" : "Choose how many wireless networks are shown in panel. Additional networks are listed in More menu" + }, + "hide-other-networks-when-connected": { + "type" : "switch", + "default" : false, + "description" : "Hide other wireless networks when connected", + "tooltip" : "When enabled and connected to a wireless network, other networks are not listed." } } \ No newline at end of file From 287f58b9578b271bbd87e8a6a0a7a76b9584569b Mon Sep 17 00:00:00 2001 From: Peter Boughton Date: Thu, 10 Jun 2021 17:27:16 +0100 Subject: [PATCH 2/2] network applet: Use callbacks to update settings --- .../applets/network@cinnamon.org/applet.js | 17 +++++++++++++---- 1 file changed, 13 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 78e705bf2f..73f6431a64 100644 --- a/files/usr/share/cinnamon/applets/network@cinnamon.org/applet.js +++ b/files/usr/share/cinnamon/applets/network@cinnamon.org/applet.js @@ -1700,11 +1700,11 @@ CinnamonNetworkApplet.prototype = { this.settings = new Settings.AppletSettings(this, metadata.uuid, this.instance_id); this.settings.bind("keyOpen", "keyOpen", this._setKeybinding); - this.settings.bind("num-visible-networks", "num_visible_networks"); - this.settings.bind("hide-other-networks-when-connected", "hide_other_networks_when_connected"); - APPLET_SETTINGS.num_visible_networks = this.num_visible_networks; - APPLET_SETTINGS.hide_other_networks_when_connected = this.hide_other_networks_when_connected; + this.settings.bind("num-visible-networks", this._setNumVisibleNetworks); + this.settings.bind("hide-other-networks-when-connected", this._setHideOtherNetworksWhenConnected); this._setKeybinding(); + this._setNumVisibleNetworks(); + this._setHideOtherNetworksWhenConnected(); NM.Client.new_async(null, Lang.bind(this, this._clientGot)); } @@ -1717,6 +1717,15 @@ CinnamonNetworkApplet.prototype = { Main.keybindingManager.addHotKey("network-open-" + this.instance_id, this.keyOpen, Lang.bind(this, this._openMenu)); }, + _setNumVisibleNetworks() { + APPLET_SETTINGS.num_visible_networks = this.num_visible_networks; + }, + + _setHideOtherNetworksWhenConnected() { + APPLET_SETTINGS.hide_other_networks_when_connected = this.hide_other_networks_when_connected; + }, + + _clientGot: function(obj, result) { try { this._client = NM.Client.new_finish(result);