@@ -377,20 +377,20 @@ export const Sensors = GObject.registerClass({
377377 _queryBattery ( callback ) {
378378 let battery_slot = this . _settings . get_int ( 'battery-slot' ) ;
379379
380- // addresses issue #161
381- let battery_key = 'BAT' ; // BAT0, BAT1 and BAT2
382- if ( battery_slot == 3 ) {
383- battery_slot = 'T' ;
384- } else if ( battery_slot == 4 ) {
385- battery_key = 'CMB' ; // CMB0
386- battery_slot = 0 ;
387- } else if ( battery_slot == 5 ) {
388- battery_key = 'macsmc-battery' ; // supports Asahi linux
389- battery_slot = '' ;
390- }
380+ // create a mapping of indices to battery paths (from prefs.ui)
381+ const BATTERY_PATHS = {
382+ 0 : 'BAT0' ,
383+ 1 : 'BAT1' ,
384+ 2 : 'BAT2' ,
385+ 3 : 'BATT' ,
386+ 4 : 'CMB0' ,
387+ 5 : 'CMB1' ,
388+ 6 : 'CMB2' ,
389+ 7 : 'macsmc-battery'
390+ } ;
391391
392392 // uevent has all necessary fields, no need to read individual files
393- let battery_path = '/sys/class/power_supply/' + battery_key + battery_slot + '/uevent' ;
393+ let battery_path = '/sys/class/power_supply/' + BATTERY_PATHS [ battery_slot ] + '/uevent' ;
394394 new FileModule . File ( battery_path ) . read ( "\n" ) . then ( lines => {
395395 let output = { } ;
396396 for ( let line of lines ) {
@@ -507,7 +507,7 @@ export const Sensors = GObject.registerClass({
507507 return ;
508508 }
509509 }
510-
510+
511511 this . _nvidia_smi_process . read ( '\n' ) . then ( lines => {
512512 /// for debugging multi-gpu on systems with only one gpu
513513 /// duplicates the first gpu's data 3 times, for 4 total gpus
@@ -518,10 +518,9 @@ export const Sensors = GObject.registerClass({
518518 for ( let i = 0 ; i < lines . length ; i ++ ) {
519519 this . _parseNvidiaSmiLine ( callback , lines [ i ] , i + 1 , lines . length > 1 ) ;
520520 }
521-
522521
523- // if we've already updated the static info during the last parse, then stop doing so.
524- // this is so the _parseNvidiaSmiLine function won't return static info anymore
522+ // if we've already updated the static info during the last parse, then stop doing so.
523+ // this is so the _parseNvidiaSmiLine function won't return static info anymore
525524 // and the nvidia-smi commmand won't be queried for static info either
526525 if ( ! this . _nvidia_static_returned ) {
527526 this . _nvidia_static_returned = true ;
@@ -552,13 +551,13 @@ export const Sensors = GObject.registerClass({
552551 this . _bad_split_count = 0 ;
553552
554553 let [
555- label ,
554+ label ,
556555 fan_speed_pct ,
557- temp_gpu , temp_mem ,
556+ temp_gpu , temp_mem ,
558557 mem_total , mem_used , mem_reserved , mem_free ,
559558 util_gpu , util_mem , util_encoder , util_decoder ,
560559 clock_gpu , clock_mem , clock_encode_decode ,
561- power , power_avg ,
560+ power , power_avg ,
562561 link_gen_current , link_width_current
563562 ] = csv_split ;
564563
@@ -580,12 +579,9 @@ export const Sensors = GObject.registerClass({
580579 }
581580 }
582581
583-
584582 const typeName = 'gpu#' + gpuNum ;
585583 const globalLabel = 'GPU' + ( multiGpu ? ' ' + gpuNum : '' ) ;
586-
587584 const memTempValid = ! isNaN ( parseInt ( temp_mem ) ) ;
588-
589585
590586 this . _returnGpuValue ( callback , 'Graphics' , parseInt ( util_gpu ) * 0.01 , typeName + '-group' , 'percent' ) ;
591587
@@ -687,7 +683,7 @@ export const Sensors = GObject.registerClass({
687683
688684 _returnStaticGpuValue ( callback , label , value , type , format ) {
689685 //if we've already tried to return existing static info before or if the option isn't enabled, then do nothing.
690- if ( this . _nvidia_static_returned || ! this . _settings . get_boolean ( 'include-static-gpu-info' ) )
686+ if ( this . _nvidia_static_returned || ! this . _settings . get_boolean ( 'include-static-gpu-info' ) )
691687 return ;
692688
693689 //we don't need to disable static info labels, so just use ordinary returnValue function
@@ -845,7 +841,7 @@ export const Sensors = GObject.registerClass({
845841 _reconfigureNvidiaSmiProcess ( ) {
846842 if ( this . _settings . get_boolean ( 'show-gpu' ) ) {
847843 this . _terminateNvidiaSmiProcess ( ) ;
848-
844+
849845 try {
850846 let update_time = this . _settings . get_int ( 'update-time' ) ;
851847 let query_interval = Math . max ( update_time , 1 ) ;
@@ -859,13 +855,13 @@ export const Sensors = GObject.registerClass({
859855 'clocks.gr,clocks.mem,clocks.video,' +
860856 'power.draw.instant,power.draw.average,' +
861857 'pcie.link.gen.gpucurrent,pcie.link.width.current,' +
862- ( ! this . _nvidia_static_returned && this . _settings . get_boolean ( 'include-static-gpu-info' ) ?
858+ ( ! this . _nvidia_static_returned && this . _settings . get_boolean ( 'include-static-gpu-info' ) ?
863859 'temperature.gpu.tlimit,' +
864860 'power.limit,' +
865861 'pcie.link.gen.max,pcie.link.width.max,' +
866862 'addressing_mode,' +
867863 'driver_version,vbios_version,serial,' +
868- 'pci.domain,pci.bus,pci.device,pci.device_id,pci.sub_device_id,'
864+ 'pci.domain,pci.bus,pci.device,pci.device_id,pci.sub_device_id,'
869865 : '' ) ,
870866 '--format=csv,noheader,nounits' ,
871867 '-l' , query_interval . toString ( )
0 commit comments