From bf029d7eedeb6be4e3a37d0fdc02e0b826b57b7e Mon Sep 17 00:00:00 2001 From: UshakovVasilii Date: Sat, 20 Jan 2018 08:26:50 +0300 Subject: [PATCH] update UI every 250ms if necessary, resolve #74 --- .../commandLineUtil.js | 10 +++++++++ .../extension.js | 22 ++++++++++++++++++- .../udisks2.js | 13 ++++++++++- 3 files changed, 43 insertions(+), 2 deletions(-) diff --git a/freon@UshakovVasilii_Github.yahoo.com/commandLineUtil.js b/freon@UshakovVasilii_Github.yahoo.com/commandLineUtil.js index 4ff8db1..b77dc0c 100644 --- a/freon@UshakovVasilii_Github.yahoo.com/commandLineUtil.js +++ b/freon@UshakovVasilii_Github.yahoo.com/commandLineUtil.js @@ -7,6 +7,7 @@ const CommandLineUtil = new Lang.Class({ _init: function(){ this._argv = null; + this._updated = false; }, execute: function(callback) { @@ -35,6 +36,7 @@ const CommandLineUtil = new Lang.Class({ stdout.close(null); GLib.source_remove(childWatch); this._output = output; + this._updated = true; callback(); })); } catch(e){ @@ -46,6 +48,14 @@ const CommandLineUtil = new Lang.Class({ return this._argv != null; }, + get updated (){ + return this._updated; + }, + + set updated (updated){ + this._updated = updated; + }, + destroy: function(){ this._argv = null; } diff --git a/freon@UshakovVasilii_Github.yahoo.com/extension.js b/freon@UshakovVasilii_Github.yahoo.com/extension.js index c132eb0..f05abd8 100644 --- a/freon@UshakovVasilii_Github.yahoo.com/extension.js +++ b/freon@UshakovVasilii_Github.yahoo.com/extension.js @@ -84,6 +84,11 @@ const FreonMenuButton = new Lang.Class({ this._querySensors(); this._addTimer(); + this._updateUITimeoutId = Mainloop.timeout_add(250, Lang.bind(this, function (){ + this._updateUI(); + // readd to update queue + return true; + })); }, _createHotItem: function(s, showIcon, gicon){ @@ -218,6 +223,7 @@ const FreonMenuButton = new Lang.Class({ this._destroyDriveUtility(); this._destroyGpuUtility(); Mainloop.source_remove(this._timeoutId); + Mainloop.source_remove(this._updateUITimeoutId); for each (let signal in this._settingChangedSignals){ this._settings.disconnect(signal); @@ -232,7 +238,21 @@ const FreonMenuButton = new Lang.Class({ })); } } - this._updateDisplay(); // #74 + }, + + _updateUI: function(){ + let needUpdate = false; + for each (let sensor in this._utils) { + if (sensor.available && sensor.updated) { + // global.log(sensor + ' updated'); + sensor.updated = false; + needUpdate = true; + } + } + if(needUpdate) { + this._updateDisplay(); // #74 + // global.log('update display'); + } }, _fixNames: function(sensors){ diff --git a/freon@UshakovVasilii_Github.yahoo.com/udisks2.js b/freon@UshakovVasilii_Github.yahoo.com/udisks2.js index c6227ed..5a60c1d 100644 --- a/freon@UshakovVasilii_Github.yahoo.com/udisks2.js +++ b/freon@UshakovVasilii_Github.yahoo.com/udisks2.js @@ -41,12 +41,21 @@ const UDisks2 = new Lang.Class({ this._udisksProxies = proxies; callback(); })); + this._updated = true; }, get available(){ return this._udisksProxies.length > 0; }, + get updated (){ + return this._updated; + }, + + set updated (updated){ + this._updated = updated; + }, + // creates a list of sensor objects from the list of proxies given get temp() { return this._udisksProxies.filter(function(proxy) { @@ -112,6 +121,8 @@ const UDisks2 = new Lang.Class({ this._udisksProxies = []; }, - execute: function(callback) {}, + execute: function(callback) { + this._updated = true; + }, });