@@ -160,10 +160,6 @@ function initCheckboxRadioStyle() {
160160
161161function initCPUtemp ( ) {
162162 function setCPUtemp ( unit ) {
163- if ( localStorage ) {
164- localStorage . setItem ( "tempunit" , tempunit ) ;
165- }
166-
167163 var temperature = parseFloat ( $ ( "#rawtemp" ) . text ( ) ) ;
168164 var displaytemp = $ ( "#tempdisplay" ) ;
169165 if ( ! isNaN ( temperature ) ) {
@@ -185,10 +181,30 @@ function initCPUtemp() {
185181 }
186182 }
187183
188- // Read from local storage, initialize if needed
189- var tempunit = localStorage ? localStorage . getItem ( "tempunit" ) : null ;
190- if ( tempunit === null ) {
191- tempunit = "C" ;
184+ function setSetupvarsTempUnit ( unit , showmsg = true ) {
185+ var token = encodeURIComponent ( $ ( "#token" ) . text ( ) ) ;
186+ $ . getJSON ( "api.php?setTempUnit=" + unit + "&token=" + token , function ( data ) {
187+ if ( showmsg === true ) {
188+ if ( "result" in data && data . result === "success" ) {
189+ utils . showAlert ( "success" , "" , "Temperature unit set to " + unit , "" ) ;
190+ } else {
191+ utils . showAlert ( "error" , "" , "" , "Temperature unit not set" ) ;
192+ }
193+ }
194+ } ) ;
195+ }
196+
197+ // Read the temperature unit from HTML code
198+ var tempunit = $ ( "#tempunit" ) . text ( ) ;
199+ if ( ! tempunit ) {
200+ // if no value was set in setupVars.conf, tries to retrieve the old config from localstorage
201+ tempunit = localStorage ? localStorage . getItem ( "tempunit" ) : null ;
202+ if ( tempunit === null ) {
203+ tempunit = "C" ;
204+ } else {
205+ // if some value was found on localstorage, set the value in setupVars.conf
206+ setSetupvarsTempUnit ( tempunit , false ) ;
207+ }
192208 }
193209
194210 setCPUtemp ( tempunit ) ;
@@ -200,6 +216,9 @@ function initCPUtemp() {
200216 tempunitSelector . on ( "change" , function ( ) {
201217 tempunit = $ ( this ) . val ( ) ;
202218 setCPUtemp ( tempunit ) ;
219+
220+ // store the selected value on setupVars.conf
221+ setSetupvarsTempUnit ( tempunit ) ;
203222 } ) ;
204223 }
205224}
0 commit comments