@@ -101,9 +101,6 @@ Thermal.prototype = {
101101 this . tempUnits = cpuUnits ;
102102 this . cpuDegrees = 0 ;
103103 this . info = "N/A" ;
104- } ,
105-
106- refresh : function ( ) {
107104 if ( GLib . file_test ( this . cpuPath , GLib . FileTest . EXISTS )
108105 && GLib . file_test ( this . cpuPath , GLib . FileTest . IS_DIR ) ) {
109106 if ( GLib . file_test ( this . cpuPath + '/temp' , GLib . FileTest . EXISTS ) )
@@ -116,7 +113,10 @@ Thermal.prototype = {
116113 global . log ( _ ( "Invalid CPU path detected. Resetting to default." ) ) ;
117114 this . cpuFile = '/sys/class/thermal/thermal_zone0/temp' ;
118115 }
119- if ( GLib . file_test ( this . cpuFile , GLib . FileTest . EXISTS ) ) {
116+ } ,
117+
118+ refresh : function ( ) {
119+ try {
120120 let tempValue = GLib . file_get_contents ( this . cpuFile ) [ 1 ] ;
121121 let tempString = ByteArray . toString ( tempValue ) ;
122122 this . cpuDegrees = parseInt ( tempString ) / 1000 ;
@@ -126,9 +126,10 @@ Thermal.prototype = {
126126 this . cpuDegrees = ( this . cpuDegrees * 1.8 ) + 32 ;
127127 }
128128 this . info = ( this . cpuDegrees ) . toFixed ( 1 ) + this . temp_string ;
129+ } catch ( e ) {
130+ this . info = "Error" ;
129131 }
130- else
131- global . logError ( _ ( "error reading:" ) + ` ${ this . cpuFile } ` ) ;
132+
132133 }
133134}
134135
@@ -142,9 +143,6 @@ ThermalGPU.prototype = {
142143 this . tempUnits = gpuUnits ;
143144 this . gpuDegrees = 0 ;
144145 this . info = "N/A" ;
145- } ,
146-
147- refresh : function ( ) {
148146 if ( GLib . file_test ( this . gpuPath , GLib . FileTest . EXISTS )
149147 && GLib . file_test ( this . gpuPath , GLib . FileTest . IS_DIR ) ) {
150148 if ( GLib . file_test ( this . gpuPath + '/temp' , GLib . FileTest . EXISTS ) )
@@ -157,7 +155,10 @@ ThermalGPU.prototype = {
157155 global . log ( _ ( "Invalid GPU path detected. Resetting to default." ) ) ;
158156 this . gpuFile = '/sys/class/thermal/thermal_zone0/temp' ;
159157 }
160- if ( GLib . file_test ( this . gpuFile , GLib . FileTest . EXISTS ) ) {
158+ } ,
159+
160+ refresh : function ( ) {
161+ try {
161162 let tempValue = GLib . file_get_contents ( this . gpuFile ) [ 1 ] ;
162163 let tempString = ByteArray . toString ( tempValue ) ;
163164 this . gpuDegrees = parseInt ( tempString ) / 1000 ;
@@ -167,9 +168,9 @@ ThermalGPU.prototype = {
167168 this . gpuDegrees = ( this . gpuDegrees * 1.8 ) + 32 ;
168169 }
169170 this . info = ( this . gpuDegrees ) . toFixed ( 1 ) + this . temp_string ;
171+ } catch ( e ) {
172+ this . info = "Error" ;
170173 }
171- else
172- global . logError ( _ ( "error reading:" ) + ` ${ this . gpuFile } ` ) ;
173174 }
174175}
175176
@@ -269,6 +270,7 @@ MyDesklet.prototype = {
269270 _init : function ( metadata , desklet_id ) {
270271 Desklet . Desklet . prototype . _init . call ( this , metadata , desklet_id ) ;
271272 this . metadata = metadata ;
273+ this . _timeoutId = null ;
272274 this . setupUI ( ) ;
273275 } ,
274276
@@ -365,12 +367,20 @@ MyDesklet.prototype = {
365367 } ,
366368
367369 on_desklet_removed : function ( ) {
368- Mainloop . source_remove ( this . timeout ) ;
370+ if ( this . _timeoutId ) {
371+ Mainloop . source_remove ( this . _timeoutId ) ;
372+ this . _timeoutId = null ;
373+ }
369374 } ,
370375
371376 _updateWidget : function ( ) {
372377 this . _updateValues ( ) ;
373- this . timeout = Mainloop . timeout_add_seconds ( 1 , Lang . bind ( this , this . _updateWidget ) ) ;
378+
379+ if ( this . _timeoutId ) {
380+ Mainloop . source_remove ( this . _timeoutId ) ;
381+ }
382+
383+ this . _timeoutId = Mainloop . timeout_add_seconds ( 1 , ( ) => this . _updateWidget ( ) ) ;
374384 } ,
375385
376386 _updateValues : function ( ) {
0 commit comments