diff --git a/scripts/pi-hole/js/footer.js b/scripts/pi-hole/js/footer.js index 28014487cd..7805bcaf0b 100644 --- a/scripts/pi-hole/js/footer.js +++ b/scripts/pi-hole/js/footer.js @@ -181,8 +181,30 @@ function initCPUtemp() { } } + function setSetupvarsTempUnit(unit, showmsg = true) { + $.getJSON("api.php?setTempUnit=" + unit + "&token=" + token, function (data) { + if (showmsg == true) { + if ("result" in data && data.result == "success") { + utils.showAlert("success", "", "Temperature unit set to " + unit, ""); + } else { + utils.showAlert("error", "", "", "Temperature unit not set"); + } + } + }); + } + // Read the temperature unit from HTML code var tempunit = $("#tempunit").text(); + if (tempunit == "") { + // if no value was set in setupVars.conf, tries to retrieve the old config from localstorage + tempunit = localStorage ? localStorage.getItem("tempunit") : null; + if (tempunit === null) { + tempunit = "C"; + } else { + // if some value was set on localstorage, set the value in setupVars.conf + setSetupvarsTempUnit(tempunit, false); + } + } setCPUtemp(tempunit); @@ -195,13 +217,7 @@ function initCPUtemp() { setCPUtemp(tempunit); // store the selected value on setupVars.conf - $.getJSON("api.php?setTempUnit=" + tempunit + "&token=" + token, function (data) { - if ("result" in data && data.result == "success") { - utils.showAlert("success", "", "Temperature unit set to " + tempunit, ""); - } else { - utils.showAlert("error", "", "", "Temperature unit not set"); - } - }); + setSetupvarsTempUnit(tempunit); }); } } diff --git a/scripts/pi-hole/php/header_authenticated.php b/scripts/pi-hole/php/header_authenticated.php index b82fdbdeb5..b022d4a621 100644 --- a/scripts/pi-hole/php/header_authenticated.php +++ b/scripts/pi-hole/php/header_authenticated.php @@ -110,7 +110,8 @@ function getTemperature() $unit = 'C'; } } else { - $unit = 'C'; + // no value is set in setupVars.conf + $unit = ''; } return array($celsius, $limit, $unit);