check if backend is reachable when handling night mode change instead of relying on navigator.onLine
This commit is contained in:
18
js/App.js
18
js/App.js
@@ -172,21 +172,21 @@ const App = {
|
|||||||
console.log("nightModeChanged: night mode changed to", is_night, "retry", retry);
|
console.log("nightModeChanged: night mode changed to", is_night, "retry", retry);
|
||||||
|
|
||||||
if (link) {
|
if (link) {
|
||||||
if (navigator.onLine) {
|
if (retry < 5) {
|
||||||
const css_override = is_night ? App.getInitParam("default_dark_theme") : App.getInitParam("default_light_theme");
|
|
||||||
link.setAttribute("href", css_override + "?" + Date.now());
|
|
||||||
} else if (retry < 5) {
|
|
||||||
console.log("nightModeChanged: we're offline, will attempt to retry...");
|
|
||||||
|
|
||||||
window.clearTimeout(this._night_mode_retry_timeout);
|
window.clearTimeout(this._night_mode_retry_timeout);
|
||||||
|
|
||||||
this._night_mode_retry_timeout = window.setTimeout(
|
this._night_mode_retry_timeout = window.setTimeout(
|
||||||
() => this.nightModeChanged(is_night, link, ++retry),
|
() => this.nightModeChanged(is_night, link, ++retry),
|
||||||
3000);
|
3000);
|
||||||
|
|
||||||
} else {
|
|
||||||
console.log("nightModeChanged: too many retries, giving up");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
xhr.post("backend.php", {op: "RPC", method: "getRuntimeInfo"}, () => {
|
||||||
|
const css_override = is_night ? App.getInitParam("default_dark_theme") : App.getInitParam("default_light_theme");
|
||||||
|
|
||||||
|
link.setAttribute("href", css_override + "?" + Date.now());
|
||||||
|
|
||||||
|
window.clearTimeout(this._night_mode_retry_timeout);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
setupNightModeDetection: function(callback) {
|
setupNightModeDetection: function(callback) {
|
||||||
|
|||||||
Reference in New Issue
Block a user