diff options
| author | Andrew Dolgov <fox@fakecake.org> | 2025-07-27 20:07:55 +0300 |
|---|---|---|
| committer | Andrew Dolgov <fox@fakecake.org> | 2025-07-27 20:07:55 +0300 |
| commit | 524bdeb419cb03a05ec5ee80e42c5c5761b20273 (patch) | |
| tree | aabb88ee473bd90af1fed0ea5a11888b1161de4e /js | |
| parent | bb39b34d7279a873cae4c769a828bf5b96bc6d74 (diff) | |
attempt to retry night mode switch if we're offline
Diffstat (limited to 'js')
| -rw-r--r-- | js/App.js | 22 |
1 files changed, 18 insertions, 4 deletions
@@ -14,6 +14,7 @@ const App = { global_unread: -1, _widescreen_mode: false, _loading_progress: 0, + _night_mode_retry_timeout: false, hotkey_actions: {}, is_prefs: false, LABEL_BASE_INDEX: -1024, @@ -167,12 +168,25 @@ const App = { setInitParam: function(k, v) { this._initParams[k] = v; }, - nightModeChanged: function(is_night, link) { - console.log("night mode changed to", is_night); + nightModeChanged: function(is_night, link, retry = 0) { + console.log("nightModeChanged: night mode changed to", is_night, "retry", retry); if (link) { - const css_override = is_night ? "themes/night.css" : "themes/light.css"; - link.setAttribute("href", css_override + "?" + Date.now()); + if (navigator.onLine) { + const css_override = is_night ? "themes/night.css" : "themes/light.css"; + 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); + + this._night_mode_retry_timeout = window.setTimeout( + () => this.nightModeChanged(is_night, link, ++retry), + 3000); + + } else { + console.log("nightModeChanged: too many retries, giving up"); + } } }, setupNightModeDetection: function(callback) { |