Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

[RFT, 1.6.1?] Fix Network Manager applet consuming a lot of CPU #1186

Merged
merged 4 commits into from

2 participants

Per Ångström Clement Lefebvre
Per Ångström
Collaborator

This makes the Network Manager applet consume less CPU by not running its updateIcon routine quite so often. Also, when it performs one of its frequent icon updates, the update is actually not performed unless the new icon is different from the current one (an enhancement that will benefit all applets).

This also corrects a bug which made the updateIcon routine forever continue running on a timeout even after the applet had been unloaded.

See also: #1154.

Current status: Ready for test. It would be great if this could be speedily expedited in time for version 1.6.1.

Clement Lefebvre clefebvre merged commit f7e83c7 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
1  NEWS
View
@@ -3,6 +3,7 @@
- Fixed: Administration category missing in menu
- Fixed: Blur in Alt-Tab preview
+ - Fixed: Network Manager applet consumes a lot of CPU
FIX NEEDED FOR 1.6.x
--------------------
35 files/usr/share/cinnamon/applets/network@cinnamon.org/applet.js
View
@@ -14,6 +14,9 @@ const MessageTray = imports.ui.messageTray;
const ModemManager = imports.misc.modemManager;
const Util = imports.misc.util;
+const DEFAULT_PERIODIC_UPDATE_FREQUENCY_SECONDS = 10;
+const FAST_PERIODIC_UPDATE_FREQUENCY_SECONDS = 2;
+
const NMConnectionCategory = {
INVALID: 'invalid',
WIRED: 'wired',
@@ -1710,14 +1713,14 @@ MyApplet.prototype = {
this._client.connect('notify::manager-running', Lang.bind(this, this._syncNMState));
this._client.connect('notify::networking-enabled', Lang.bind(this, this._syncNMState));
this._client.connect('notify::state', Lang.bind(this, this._syncNMState));
- //this._client.connect('notify::active-connections', Lang.bind(this, this._updateIcon));
+ this._client.connect('notify::active-connections', Lang.bind(this, this._updateIcon));
this._client.connect('device-added', Lang.bind(this, this._deviceAdded));
this._client.connect('device-removed', Lang.bind(this, this._deviceRemoved));
this._settings.connect('new-connection', Lang.bind(this, this._newConnection));
}
}));
- this._updateIcon();
+ this._periodicUpdateIcon();
}
catch (e) {
@@ -1959,7 +1962,7 @@ MyApplet.prototype = {
activeConnection._primaryDevice._notification = null;
}
- //this._updateIcon();
+ this._updateIcon();
},
_readConnections: function() {
@@ -1990,7 +1993,7 @@ MyApplet.prototype = {
this._updateConnection(connection);
this._connections.push(connection);
- //this._updateIcon();
+ this._updateIcon();
},
_connectionRemoved: function(connection) {
@@ -2079,13 +2082,12 @@ MyApplet.prototype = {
}
this._showNormal();
- //this._updateIcon();
+ this._updateIcon();
},
- _updateIcon: function() {
+ _updateIcon: function() {
try {
- this.set_applet_tooltip("");
-
+ this._updateFrequencySeconds = DEFAULT_PERIODIC_UPDATE_FREQUENCY_SECONDS;
this._syncActiveConnections();
let mc = this._mainConnection;
let hasApIcon = false;
@@ -2095,6 +2097,7 @@ MyApplet.prototype = {
this.set_applet_icon_symbolic_name('network-offline');
this.set_applet_tooltip(_("No connection"));
} else if (mc.state == NetworkManager.ActiveConnectionState.ACTIVATING) {
+ this._updateFrequencySeconds = FAST_PERIODIC_UPDATE_FREQUENCY_SECONDS;
switch (mc._section) {
case NMConnectionCategory.WWAN:
this.set_applet_icon_symbolic_name('network-cellular-acquiring');
@@ -2176,14 +2179,24 @@ MyApplet.prototype = {
break;
}
}
-
- Mainloop.timeout_add_seconds(1, Lang.bind(this, this._updateIcon));
}
catch (e) {
global.logError(e);
}
- }
+ },
+ _periodicUpdateIcon: function() {
+ this._updateIcon();
+ this._updateFrequencySeconds = Math.max(2, this._updateFrequencySeconds);
+ this._periodicTimeoutId = Mainloop.timeout_add_seconds(this._updateFrequencySeconds, Lang.bind(this, this._periodicUpdateIcon));
+ },
+
+ on_applet_removed_from_panel: function() {
+ if (this._periodicTimeoutId){
+ Mainloop.source_remove(this._periodicTimeoutId);
+ }
+ },
+
};
function main(metadata, orientation, panel_height) {
10 js/ui/applet.js
View
@@ -169,8 +169,10 @@ Applet.prototype = {
},
set_applet_tooltip: function (text) {
- this._applet_tooltip_text = text;
- this._applet_tooltip.set_text(text);
+ if (this._applet_tooltip_text !== text) {
+ this._applet_tooltip.set_text(text);
+ this._applet_tooltip_text = text;
+ }
},
on_applet_clicked: function(event) {
@@ -281,6 +283,10 @@ IconApplet.prototype = {
},
set_applet_icon_symbolic_name: function (icon_name) {
+ if (this.__icon_name === icon_name) {
+ return;
+ }
+
if (this._scaleMode) {
let height = (this._panelHeight / DEFAULT_PANEL_HEIGHT) * PANEL_SYMBOLIC_ICON_DEFAULT_HEIGHT;
this._applet_icon = new St.Icon({icon_name: icon_name, icon_size: height, icon_type: St.IconType.SYMBOLIC, reactive: true, track_hover: true, style_class: 'system-status-icon' });
Something went wrong with that request. Please try again.