Skip to content

Commit

Permalink
If no unit is set on setupVars, try to use localstorage value, if exists
Browse files Browse the repository at this point in the history
Signed-off-by: RD WebDesign <github@rdwebdesign.com.br>
  • Loading branch information
rdwebdesign committed Jan 28, 2023
1 parent 4966f01 commit 39aa423
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
30 changes: 23 additions & 7 deletions scripts/pi-hole/js/footer.js
Expand Up @@ -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);

Expand All @@ -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);
});
}
}
Expand Down
3 changes: 2 additions & 1 deletion scripts/pi-hole/php/header_authenticated.php
Expand Up @@ -110,7 +110,8 @@ function getTemperature()
$unit = 'C';
}
} else {
$unit = 'C';
// no value is set in setupVars.conf
$unit = '';
}

return array($celsius, $limit, $unit);
Expand Down

0 comments on commit 39aa423

Please sign in to comment.