From 6508cee0e145481b85f2eb94c4ef47f3bb103665 Mon Sep 17 00:00:00 2001 From: Dipesh Acharya Date: Sat, 3 Dec 2011 14:03:48 +0545 Subject: [PATCH] optimized the flow --- extension.js | 152 ++++++++++++++++++++++++++++----------------------- 1 file changed, 85 insertions(+), 67 deletions(-) diff --git a/extension.js b/extension.js index f210e8a..b6189d8 100644 --- a/extension.js +++ b/extension.js @@ -18,93 +18,110 @@ CpuTemperature.prototype = { _init: function(){ PanelMenu.SystemStatusButton.prototype._init.call(this, 'temperature'); - this.statusLabel = new St.Label({ text: '-' }); + + this.statusLabel = new St.Label({ text: "--", style_class: "temperature-label" }); + // destroy all previously created children, and add our statusLabel this.actor.get_children().forEach(function(c) { c.destroy() }); this.actor.add_actor(this.statusLabel); - - this._update_temp(); + + this.sensorsPath = this._detectSensors(); + debug(this.sensorsPath); + + if(this.sensorsPath){ + this.title='Error'; + this.content='Run sensors-detect as root. If it doesn\'t help, click here to report!'; + this.command=["xdg-open", "http://github.com/xtranophilist/gnome-shell-extension-cpu-temperature/issues/"]; + } + else{ + this.title='Warning'; + this.content='Please install lm_sensors. If it doesn\'t help, click here to report!'; + this.command=["xdg-open", "http://github.com/xtranophilist/gnome-shell-extension-cpu-temperature/issues/"]; + } + + this._update_temp(); //update every 15 seconds GLib.timeout_add(0, 15000, Lang.bind(this, function () { - this._update_temp(); - return true; + this._update_temp(); + return true; })); }, + + _detectSensors: function(){ + //detect if sensors is installed + let ret = GLib.spawn_command_line_sync("which --skip-alias sensors"); + + if ( (ret[0]) && (ret[3] == 0) ) {//if yes + return ret[1].toString().split("\n", 1)[0];//find the path of the sensors + } + return null; + }, _update_temp: function() { - let title='Error'; - let content='Click here to report!'; - let command=["firefox", "http://github.com/xtranophilist/gnome-shell-extension-cpu-temperature/issues/"]; - - let foundTemperature=false; - let cpuTemperatureInfo = ['/sys/devices/platform/coretemp.0/temp1_input', - '/sys/bus/acpi/devices/LNXTHERM\:00/thermal_zone/temp', - '/sys/devices/virtual/thermal/thermal_zone0/temp', - //old kernels with proc fs - '/proc/acpi/thermal_zone/THM0/temperature', - '/proc/acpi/thermal_zone/THRM/temperature', - '/proc/acpi/thermal_zone/THR0/temperature', - '/proc/acpi/thermal_zone/TZ0/temperature', - '/sys/bus/acpi/drivers/ATK0110/ATK0110:00/hwmon/hwmon0/temp1_input', - //hwmon for new 2.6.39, 3.0 linux kernels - '/sys/class/hwmon/hwmon0/temp1_input', - //Debian Sid/Experimental on AMD-64 - '/sys/class/hwmon/hwmon0/device/temp1_input']; - - for (let i=0;i