forked from Ivasoft/mattermost-mobile
* Only call app entry on websocket reconnect * Handle notification on its own entry and run app entry on websocket initialization * Fix notification entry issues * Fix login entry and add retry on entry failure * feedback review * Put back handleEntryAfterLoadNavigation before the batching --------- Co-authored-by: Elias Nahum <nahumhbl@gmail.com>
58 lines
1.8 KiB
TypeScript
58 lines
1.8 KiB
TypeScript
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
import DatabaseManager from '@database/manager';
|
|
import {getAllServerCredentials} from '@init/credentials';
|
|
import {initialLaunch} from '@init/launch';
|
|
import ManagedApp from '@init/managed_app';
|
|
import PushNotifications from '@init/push_notifications';
|
|
import GlobalEventHandler from '@managers/global_event_handler';
|
|
import NetworkManager from '@managers/network_manager';
|
|
import SessionManager from '@managers/session_manager';
|
|
import WebsocketManager from '@managers/websocket_manager';
|
|
import {registerScreens} from '@screens/index';
|
|
import {registerNavigationListeners} from '@screens/navigation';
|
|
|
|
let alreadyInitialized = false;
|
|
let serverCredentials: ServerCredential[];
|
|
|
|
// Fallback Polyfill for Promise.allSettle
|
|
Promise.allSettled = Promise.allSettled || (<T>(promises: Array<Promise<T>>) => Promise.all(
|
|
promises.map((p) => p.
|
|
then((value) => ({
|
|
status: 'fulfilled',
|
|
value,
|
|
})).
|
|
catch((reason) => ({
|
|
status: 'rejected',
|
|
reason,
|
|
})),
|
|
),
|
|
));
|
|
|
|
export async function initialize() {
|
|
if (!alreadyInitialized) {
|
|
alreadyInitialized = true;
|
|
serverCredentials = await getAllServerCredentials();
|
|
const serverUrls = serverCredentials.map((credential) => credential.serverUrl);
|
|
|
|
await DatabaseManager.init(serverUrls);
|
|
await NetworkManager.init(serverCredentials);
|
|
|
|
GlobalEventHandler.init();
|
|
ManagedApp.init();
|
|
SessionManager.init();
|
|
}
|
|
}
|
|
|
|
export async function start() {
|
|
await initialize();
|
|
|
|
PushNotifications.init(serverCredentials.length > 0);
|
|
|
|
registerNavigationListeners();
|
|
registerScreens();
|
|
await WebsocketManager.init(serverCredentials);
|
|
initialLaunch();
|
|
}
|