diff --git a/ts/background.ts b/ts/background.ts index 4a1f0c8585..4122510fa3 100644 --- a/ts/background.ts +++ b/ts/background.ts @@ -3417,26 +3417,6 @@ export async function startApp(): Promise { 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'); } diff --git a/ts/services/networkObserver.ts b/ts/services/networkObserver.ts index acaa4cf736..b375e0d672 100644 --- a/ts/services/networkObserver.ts +++ b/ts/services/networkObserver.ts @@ -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, }); };