Switch SQL to main process on disconnect

This commit is contained in:
Fedor Indutny 2022-01-03 13:44:04 -08:00 committed by GitHub
parent 35530a4832
commit 2d596ac8b2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 21 deletions

View file

@ -3417,26 +3417,6 @@ export async function startApp(): Promise<void> {
return;
}
if (
error instanceof HTTPError &&
(error.code === -1 || error.code === 502)
) {
// Failed to connect to server
if (navigator.onLine) {
const timeout = reconnectBackOff.getAndIncrement();
log.info(`retrying in ${timeout}ms`);
reconnectTimer = Timers.setTimeout(connect, timeout);
window.Whisper.events.trigger('reconnectTimer');
// If we couldn't connect during startup - we should still switch SQL to
// the main process to avoid stalling UI.
window.Signal.Data.goBackToMainProcess();
}
return;
}
log.warn('background onError: Doing nothing with incoming error');
}

View file

@ -8,6 +8,7 @@ import type {
import { getSocketStatus } from '../shims/socketStatus';
import * as log from '../logging/log';
import { SECOND } from '../util/durations';
import { SocketStatus } from '../types/SocketStatus';
type NetworkActions = {
checkNetworkStatus: (x: CheckNetworkStatusPayloadType) => NetworkActionType;
@ -20,9 +21,17 @@ export function initializeNetworkObserver(
log.info('Initializing network observer');
const refresh = () => {
const socketStatus = getSocketStatus();
if (socketStatus === SocketStatus.CLOSED) {
// If we couldn't connect during startup - we should still switch SQL to
// the main process to avoid stalling UI.
window.Signal.Data.goBackToMainProcess();
}
networkActions.checkNetworkStatus({
isOnline: navigator.onLine,
socketStatus: getSocketStatus(),
socketStatus,
});
};