1- const Lang = imports . lang ;
2- const UPower = imports . gi . UPowerGlib ;
31const BaseIndicator = imports . ui . status . power . Indicator ;
42const ExtensionUtils = imports . misc . extensionUtils ;
53const Panel = imports . ui . main . panel ;
@@ -28,9 +26,7 @@ var TPIndicator = GObject.registerClass(
2826 super . _init ( ) ;
2927
3028 this . settings = ExtensionUtils . getSettings ( 'org.gnome.shell.extensions.tp_wattmeter' ) ;
31-
32- // to detect changes FIXME: a better way?
33- this . last_period_val = this . settings . get_double ( 'period-sec' ) ;
29+ this . settings . connect ( 'changed::period-sec' , ( ) => { this . _spawn ( ) ; } ) ; // restart timers on setting change
3430
3531 this . readings = [ ] ;
3632 this . last_value = 0.0 ;
@@ -71,13 +67,6 @@ var TPIndicator = GObject.registerClass(
7167 const power = parseFloat ( this . _read_file ( POWER_NOW ) , 0 ) / 1000000 ;
7268 this . readings . push ( power )
7369
74- const period_now = this . settings . get_double ( 'period-sec' ) ;
75- if ( period_now . toFixed ( 1 ) != this . last_period_val . toFixed ( 1 ) ) {
76- // period changed, re-spawn
77- this . _spawn ( ) ;
78- this . last_period_val = period_now ;
79- } ;
80-
8170 const avg_of = this . settings . get_int ( 'avg-of' ) ;
8271 if ( this . readings . length >= avg_of ) {
8372 this . last_value = this . readings . reduce ( ( acc , elem ) => acc + elem , 0.0 ) / this . readings . length ; // simple mean
@@ -94,12 +83,13 @@ var TPIndicator = GObject.registerClass(
9483 this . tm_measure = GLib . timeout_add (
9584 GLib . PRIORITY_DEFAULT ,
9685 this . settings . get_double ( 'period-sec' ) * 1000 ,
97- Lang . bind ( this , this . _measure )
86+ this . _measure . bind ( this ) ,
9887 ) ;
9988 }
10089
10190 _stop ( ) {
10291 GLib . source_remove ( this . tm_measure ) ;
92+ this . tm_measure = null ;
10393 }
10494 }
10595) ;
0 commit comments