From ad6ec0226118b80e79446f16747976a1dd1fabcd Mon Sep 17 00:00:00 2001 From: AUTOMATIC <16777216c@gmail.com> Date: Tue, 9 May 2023 11:42:47 +0300 Subject: [PATCH] prevent Reload UI button/link from reloading the page when it's not yet ready --- javascript/ui.js | 11 ++++++++++- modules/ui.py | 2 ++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/javascript/ui.js b/javascript/ui.js index 611b70d1..ed9673d6 100644 --- a/javascript/ui.js +++ b/javascript/ui.js @@ -395,7 +395,16 @@ function update_token_counter(button_id) { function restart_reload(){ document.body.innerHTML='

Reloading...

'; - setTimeout(function(){location.reload()},2000) + + var requestPing = function(){ + requestGet("./internal/ping", {}, function(data){ + location.reload(); + }, function(){ + setTimeout(requestPing, 500); + }) + } + + setTimeout(requestPing, 2000); return [] } diff --git a/modules/ui.py b/modules/ui.py index 842c57f7..34b2aaff 100644 --- a/modules/ui.py +++ b/modules/ui.py @@ -1958,3 +1958,5 @@ def setup_ui_api(app): return [QuicksettingsHint(name=k, label=v.label) for k, v in opts.data_labels.items()] app.add_api_route("/internal/quicksettings-hint", quicksettings_hint, methods=["GET"], response_model=List[QuicksettingsHint]) + + app.add_api_route("/internal/ping", lambda: {}, methods=["GET"])