From 0c701eeffb2a57b442b244608c55be42e4656a1d Mon Sep 17 00:00:00 2001 From: Michel Weststrate Date: Wed, 11 Oct 2023 11:46:23 -0700 Subject: [PATCH] auto start server Summary: This will automatically invoke the "Start" button if Flipper detect it is offline, to automate that step. It will do so only once (safe for the reload logic that also triggers on server errors, not sure if that was intentionally?) Reviewed By: lblasa Differential Revision: D50074673 fbshipit-source-id: 2c11e80429a2c4ed0e43e62cb2f6057fad5eb410 --- desktop/static/offline.html | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/desktop/static/offline.html b/desktop/static/offline.html index 975c29049..18416204e 100644 --- a/desktop/static/offline.html +++ b/desktop/static/offline.html @@ -137,7 +137,6 @@ setTimeout(() => { button.disabled = false; button.value = 'Start'; - }, 30 * 10000); } @@ -148,18 +147,24 @@ window.location.reload(); }); + let autoStarted = false; + // Check if the server is responding & reload the page if it is. // This handles the case when the device is online, but the server // is offline or misbehaving. async function checkNetworkAndReload() { try { const response = await fetch('.'); - if (response.status >= 200 && response.status < 500) { + if (response.status === 200) { window.location.reload(); return; } } catch { - // Unable to connect to the server, ignore. + // trigger submit button automatically, but only once + if (!autoStarted) { + autoStarted = true; + document.getElementById("submit").click(); + } } window.setTimeout(checkNetworkAndReload, 2500); }