Do not use window reload

Summary: Let's keep it simple, do not reload. Just show/hide the right content.

Reviewed By: antonk52

Differential Revision: D49377316

fbshipit-source-id: 9b2a47374da3e72f17e2d55c9290960b703fd43e
This commit is contained in:
Lorenzo Blasa
2023-09-18 12:03:09 -07:00
committed by Facebook GitHub Bot
parent 2fd8003fd8
commit f1c88a464b
3 changed files with 30 additions and 15 deletions

View File

@@ -19,7 +19,6 @@ if (loadingContainer) {
let cachedFile: {name: string; data: string} | undefined; let cachedFile: {name: string; data: string} | undefined;
let cachedDeepLinkURL: string | undefined; let cachedDeepLinkURL: string | undefined;
let once: boolean = false;
async function start() { async function start() {
// @ts-ignore // @ts-ignore
electronRequire = function (path: string) { electronRequire = function (path: string) {
@@ -76,10 +75,6 @@ async function start() {
window.flipperShowMessage?.('Connecting to server...'); window.flipperShowMessage?.('Connecting to server...');
break; break;
case FlipperServerState.CONNECTED: case FlipperServerState.CONNECTED:
if (once) {
return window.location.reload();
}
once = true;
window.flipperHideMessage?.(); window.flipperHideMessage?.();
break; break;
case FlipperServerState.DISCONNECTED: case FlipperServerState.DISCONNECTED:

View File

@@ -143,13 +143,18 @@
window.location.reload(); window.location.reload();
}); });
function showNoConnection(reload) { function toggleUI(main) {
const root = document.getElementById('root'); const root = document.getElementById('root');
root.remove();
const troubleshoot = document.getElementById('troubleshoot'); const troubleshoot = document.getElementById('troubleshoot');
if (main) {
root.style.display = 'block';
troubleshoot.style.display = 'none';
} else {
root.style.display = 'none';
troubleshoot.style.display = 'flex'; troubleshoot.style.display = 'flex';
} }
}
const params = new URL(location.href).searchParams; const params = new URL(location.href).searchParams;
let token = params.get('token'); let token = params.get('token');
@@ -208,8 +213,14 @@
box.textContent = text; box.textContent = text;
} }
} }
window.flipperShowMessage = showMessage; window.flipperShowMessage = showMessage;
window.flipperShowNoConnection = showNoConnection; window.flipperShowNoConnection = () => {
toggleUI(false);
};
window.flipperHideMessage = () => {
toggleUI(true);
}
// load correct theme (n.b. this doesn't handle system value specifically, will assume light in such cases) // load correct theme (n.b. this doesn't handle system value specifically, will assume light in such cases)
try { try {

View File

@@ -153,13 +153,18 @@
window.location.reload(); window.location.reload();
}); });
function showNoConnection() { function toggleUI(main) {
const root = document.getElementById('root'); const root = document.getElementById('root');
root.remove();
const troubleshoot = document.getElementById('troubleshoot'); const troubleshoot = document.getElementById('troubleshoot');
if (main) {
root.style.display = 'block';
troubleshoot.style.display = 'none';
} else {
root.style.display = 'none';
troubleshoot.style.display = 'flex'; troubleshoot.style.display = 'flex';
} }
}
function showMessage(text) { function showMessage(text) {
if (suppressErrors) { if (suppressErrors) {
@@ -178,10 +183,14 @@
} }
} }
window.flipperShowMessage = showMessage; window.flipperShowMessage = showMessage;
window.flipperShowNoConnection = showNoConnection; window.flipperShowNoConnection = () => {
toggleUI(false);
};
window.flipperHideMessage = () => { window.flipperHideMessage = () => {
const box = document.querySelector('.__infinity-dev-box-error'); const box = document.querySelector('.__infinity-dev-box-error');
box.setAttribute('hidden', true); box.setAttribute('hidden', true);
toggleUI(true);
} }
const closeButton = document.createElement('button'); const closeButton = document.createElement('button');