Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #1186 from autarkper/network-applet-cpu

[RFT, 1.6.1?] Fix Network Manager applet consuming a lot of CPU
  • Loading branch information...
commit f7e83c7bf7a193d489a1d8b186c72143c308eea1 2 parents 84d0569 + 85f2539
@clefebvre clefebvre authored
View
1  NEWS
@@ -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
Muffin 1.1.1
------------
View
35 files/usr/share/cinnamon/applets/network@cinnamon.org/applet.js
@@ -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) {
View
10 js/ui/applet.js
@@ -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' });
Please sign in to comment.
Something went wrong with that request. Please try again.