2023-12-26 20:26:54 -05:00
|
|
|
import 'dart:async';
|
|
|
|
|
2024-01-04 22:29:43 -05:00
|
|
|
import 'package:flutter/foundation.dart';
|
|
|
|
import 'package:veilid_support/veilid_support.dart';
|
|
|
|
|
|
|
|
import 'account_manager/account_manager.dart';
|
2023-12-27 22:56:24 -05:00
|
|
|
import 'app.dart';
|
2023-12-26 20:26:54 -05:00
|
|
|
import 'tools/tools.dart';
|
2024-01-04 22:29:43 -05:00
|
|
|
import 'veilid_processor/veilid_processor.dart';
|
2023-12-26 20:26:54 -05:00
|
|
|
|
|
|
|
final Completer<void> eventualInitialized = Completer<void>();
|
|
|
|
|
|
|
|
// Initialize Veilid
|
|
|
|
Future<void> initializeVeilid() async {
|
|
|
|
// Init Veilid
|
2024-01-04 22:29:43 -05:00
|
|
|
Veilid.instance.initializeVeilidCore(
|
|
|
|
getDefaultVeilidPlatformConfig(kIsWeb, VeilidChatApp.name));
|
2023-12-26 20:26:54 -05:00
|
|
|
|
|
|
|
// Veilid logging
|
2024-01-04 22:29:43 -05:00
|
|
|
initVeilidLog(kDebugMode);
|
2023-12-26 20:26:54 -05:00
|
|
|
|
2024-01-04 22:29:43 -05:00
|
|
|
// DHT Record Pool
|
|
|
|
await DHTRecordPool.init();
|
2023-12-26 20:26:54 -05:00
|
|
|
|
2024-01-04 22:29:43 -05:00
|
|
|
// Startup Veilid
|
|
|
|
await ProcessorRepository.instance.startup();
|
2023-12-26 20:26:54 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Initialize repositories
|
|
|
|
Future<void> initializeRepositories() async {
|
2023-12-27 22:56:24 -05:00
|
|
|
await AccountRepository.instance.init();
|
2023-12-26 20:26:54 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
Future<void> initializeVeilidChat() async {
|
2024-01-04 22:29:43 -05:00
|
|
|
log.info('Initializing Veilid');
|
2023-12-26 20:26:54 -05:00
|
|
|
await initializeVeilid();
|
2024-01-04 22:29:43 -05:00
|
|
|
log.info('Initializing Repositories');
|
2023-12-26 20:26:54 -05:00
|
|
|
await initializeRepositories();
|
|
|
|
|
|
|
|
eventualInitialized.complete();
|
|
|
|
}
|