mirror of
https://github.com/morgan9e/gnome-shell-extension-freon
synced 2026-04-14 00:14:14 +09:00
clean code
This commit is contained in:
@@ -8,10 +8,10 @@ const AticonfigUtil = new Lang.Class({
|
||||
Name: 'AticonfigUtil',
|
||||
Extends: CommandLineUtil.CommandLineUtil,
|
||||
|
||||
detect: function(){
|
||||
_init: function() {
|
||||
this.parent();
|
||||
let path = GLib.find_program_in_path('aticonfig');
|
||||
this._argv = path ? [path, '--odgt'] : null;
|
||||
return this._argv != null;
|
||||
},
|
||||
|
||||
/*
|
||||
|
||||
@@ -27,17 +27,15 @@ const FreonMenuButton = new Lang.Class({
|
||||
_init: function(){
|
||||
this.parent(St.Align.START);
|
||||
|
||||
this._settings = Convenience.getSettings();
|
||||
|
||||
this._sensorMenuItems = {};
|
||||
|
||||
this._utils = {
|
||||
aticonfig: new AticonfigUtil.AticonfigUtil(),
|
||||
hddtemp: new HddtempUtil.HddtempUtil(),
|
||||
sensors: new SensorsUtil.SensorsUtil(),
|
||||
nvidia: new NvidiaUtil.NvidiaUtil()
|
||||
sensors: new SensorsUtil.SensorsUtil()
|
||||
};
|
||||
this._udisks2 = new UDisks2.UDisks2();
|
||||
|
||||
this._settings = Convenience.getSettings();
|
||||
this._initDriveUtility();
|
||||
this._initGpuUtility();
|
||||
|
||||
let temperatureIcon = Gio.icon_new_for_string(Me.path + '/icons/freon-temperature-symbolic.svg');
|
||||
this._sensorIcons = {
|
||||
@@ -65,10 +63,6 @@ const FreonMenuButton = new Lang.Class({
|
||||
|
||||
this.actor.add_actor(this._menuLayout);
|
||||
|
||||
this._utils.sensors.detect();
|
||||
this._initDriveUtility();
|
||||
this._initGpuUtility();
|
||||
|
||||
this._settingChangedSignals = [];
|
||||
this._addSettingChangedSignal('update-time', Lang.bind(this, this._updateTimeChanged));
|
||||
this._addSettingChangedSignal('unit', Lang.bind(this, this._querySensors));
|
||||
@@ -158,10 +152,10 @@ const FreonMenuButton = new Lang.Class({
|
||||
_initDriveUtility : function(){
|
||||
switch(this._settings.get_string('drive-utility')){
|
||||
case 'hddtemp':
|
||||
this._utils.hddtemp.detect();
|
||||
this._utils.disks = new HddtempUtil.HddtempUtil();
|
||||
break;
|
||||
case 'udisks2':
|
||||
this._udisks2.detect(Lang.bind(this, function() {
|
||||
this._utils.disks = new UDisks2.UDisks2(Lang.bind(this, function() {
|
||||
this._updateDisplay();
|
||||
}));
|
||||
break;
|
||||
@@ -169,24 +163,28 @@ const FreonMenuButton = new Lang.Class({
|
||||
},
|
||||
|
||||
_destroyDriveUtility : function(){
|
||||
this._udisks2.destroy();
|
||||
this._utils.hddtemp.destroy();
|
||||
if(this._utils.disks){
|
||||
this._utils.disks.destroy();
|
||||
delete this._utils.disks;
|
||||
}
|
||||
},
|
||||
|
||||
_initGpuUtility : function(){
|
||||
switch(this._settings.get_string('gpu-utility')){
|
||||
case 'nvidia-settings':
|
||||
this._utils.nvidia.detect();
|
||||
this._utils.gpu = new NvidiaUtil.NvidiaUtil();
|
||||
break;
|
||||
case 'aticonfig':
|
||||
this._utils.aticonfig.detect();
|
||||
this._utils.gpu = new AticonfigUtil.AticonfigUtil();
|
||||
break;
|
||||
}
|
||||
},
|
||||
|
||||
_destroyGpuUtility : function(){
|
||||
this._utils.nvidia.destroy();
|
||||
this._utils.aticonfig.destroy();
|
||||
if(this._utils.gpu){
|
||||
this._utils.gpu.destroy();
|
||||
delete this._utils.gpu;
|
||||
}
|
||||
},
|
||||
|
||||
_gpuUtilityChanged : function(){
|
||||
@@ -233,10 +231,8 @@ const FreonMenuButton = new Lang.Class({
|
||||
|
||||
_updateDisplay: function(){
|
||||
let gpuTempInfo = [];
|
||||
if (this._utils.aticonfig.available)
|
||||
gpuTempInfo = gpuTempInfo.concat(this._utils.aticonfig.temp);
|
||||
if (this._utils.nvidia.available)
|
||||
gpuTempInfo = gpuTempInfo.concat(this._utils.nvidia.temp);
|
||||
if (this._utils.gpu && this._utils.gpu.available)
|
||||
gpuTempInfo = gpuTempInfo.concat(this._utils.gpu.temp);
|
||||
|
||||
let sensorsTempInfo = this._utils.sensors.temp;
|
||||
|
||||
@@ -249,10 +245,8 @@ const FreonMenuButton = new Lang.Class({
|
||||
voltageInfo = this._utils.sensors.volt;
|
||||
|
||||
let driveTempInfo = [];
|
||||
if(this._utils.hddtemp.available) {
|
||||
driveTempInfo = this._utils.hddtemp.temp;
|
||||
} else if(this._udisks2.available){
|
||||
driveTempInfo = this._udisks2.temp;
|
||||
if(this._utils.disks && this._utils.disks.available) {
|
||||
driveTempInfo = this._utils.disks.temp;
|
||||
}
|
||||
|
||||
sensorsTempInfo.sort(function(a,b) { return a.label.localeCompare(b.label) });
|
||||
|
||||
@@ -8,18 +8,19 @@ const HddtempUtil = new Lang.Class({
|
||||
Name: 'HddtempUtil',
|
||||
Extends: CommandLineUtil.CommandLineUtil,
|
||||
|
||||
detect: function(){
|
||||
_init: function() {
|
||||
this.parent();
|
||||
let hddtempArgv = GLib.find_program_in_path('hddtemp');
|
||||
if(hddtempArgv) {
|
||||
// check if this user can run hddtemp directly.
|
||||
if(!GLib.spawn_command_line_sync(hddtempArgv)[3]){
|
||||
this._argv = [hddtempArgv];
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// doesn't seem to be the case… is it running as a daemon?
|
||||
// Check first for systemd
|
||||
// Check first for systemd
|
||||
let systemctl = GLib.find_program_in_path('systemctl');
|
||||
let pidof = GLib.find_program_in_path('pidof');
|
||||
let nc = GLib.find_program_in_path('nc');
|
||||
@@ -50,11 +51,7 @@ const HddtempUtil = new Lang.Class({
|
||||
let port = match ? parseInt(match[2]) : 7634;
|
||||
// use net cat to get data
|
||||
this._argv = [nc, 'localhost', port.toString()];
|
||||
return true;
|
||||
}
|
||||
|
||||
// not found
|
||||
return false;
|
||||
},
|
||||
|
||||
get temp() {
|
||||
|
||||
@@ -8,7 +8,8 @@ const NvidiaUtil = new Lang.Class({
|
||||
Name: 'NvidiaUtil',
|
||||
Extends: CommandLineUtil.CommandLineUtil,
|
||||
|
||||
detect: function(){
|
||||
_init: function() {
|
||||
this.parent();
|
||||
let path = GLib.find_program_in_path('nvidia-settings');
|
||||
this._argv = path ? [path, '-q', 'gpucoretemp', '-t'] : null;
|
||||
this._label = 'NVIDIA';
|
||||
@@ -22,7 +23,6 @@ const NvidiaUtil = new Lang.Class({
|
||||
}
|
||||
}
|
||||
}
|
||||
return this._argv != null;
|
||||
},
|
||||
|
||||
get temp() {
|
||||
|
||||
@@ -8,10 +8,10 @@ const SensorsUtil = new Lang.Class({
|
||||
Name: 'SensorsUtil',
|
||||
Extends: CommandLineUtil.CommandLineUtil,
|
||||
|
||||
detect: function(){
|
||||
_init: function() {
|
||||
this.parent();
|
||||
let path = GLib.find_program_in_path('sensors');
|
||||
this._argv = path ? [path] : null;
|
||||
return this._argv != null;
|
||||
},
|
||||
|
||||
get temp() {
|
||||
|
||||
@@ -35,10 +35,8 @@ const UDisks2 = new Lang.Class({
|
||||
Name: 'UDisks2',
|
||||
|
||||
_init: function(callback) {
|
||||
this.parent();
|
||||
this._udisksProxies = [];
|
||||
},
|
||||
|
||||
detect: function(callback){
|
||||
this._get_drive_ata_proxies(Lang.bind(this, function(proxies) {
|
||||
this._udisksProxies = proxies;
|
||||
callback();
|
||||
@@ -114,4 +112,6 @@ const UDisks2 = new Lang.Class({
|
||||
this._udisksProxies = [];
|
||||
},
|
||||
|
||||
execute: function(callback) {},
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user