74 lines
2.6 KiB
TypeScript
74 lines
2.6 KiB
TypeScript
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
import {CallsManager} from '@calls/calls_manager';
|
|
import DatabaseManager from '@database/manager';
|
|
import {getAllServerCredentials} from '@init/credentials';
|
|
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 OfflinePersistenceManager from '@managers/offline_persistence_manager';
|
|
import SecurityManager from '@managers/security_manager';
|
|
import SessionManager from '@managers/session_manager';
|
|
import WebsocketManager from '@managers/websocket_manager';
|
|
import EphemeralStore from '@store/ephemeral_store';
|
|
import {NavigationStore} from '@store/navigation_store';
|
|
|
|
// Controls whether the main initialization (database, etc...) is done, either on app launch
|
|
// or on the Share Extension, for example.
|
|
let baseAppInitialized = 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 (!baseAppInitialized) {
|
|
baseAppInitialized = true;
|
|
serverCredentials = await getAllServerCredentials();
|
|
const serverUrls = serverCredentials.map((credential) => credential.serverUrl);
|
|
|
|
await DatabaseManager.init(serverUrls);
|
|
await NetworkManager.init(serverCredentials);
|
|
|
|
// OfflinePersistenceManager init runs before WS init so any pending wipes
|
|
// complete before WebSocket clients start populating server databases.
|
|
await OfflinePersistenceManager.init(serverCredentials);
|
|
await WebsocketManager.init(serverCredentials);
|
|
}
|
|
|
|
NavigationStore.reset();
|
|
EphemeralStore.setCurrentThreadId('');
|
|
EphemeralStore.setProcessingNotification('');
|
|
|
|
await SecurityManager.init();
|
|
|
|
GlobalEventHandler.init();
|
|
ManagedApp.init();
|
|
SessionManager.init();
|
|
CallsManager.initialize();
|
|
|
|
PushNotifications.init(serverCredentials.length > 0);
|
|
}
|
|
|
|
export function cleanup() {
|
|
ManagedApp.cleanup();
|
|
GlobalEventHandler.cleanup();
|
|
SecurityManager.cleanup();
|
|
SessionManager.cleanup();
|
|
CallsManager.cleanup();
|
|
PushNotifications.cleanup();
|
|
OfflinePersistenceManager.cleanup();
|
|
}
|