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
|
|
|
|
2024-04-03 21:55:49 -04:00
|
|
|
class VeilidChatGlobalInit {
|
|
|
|
VeilidChatGlobalInit._();
|
2023-12-26 20:26:54 -05:00
|
|
|
|
2024-04-03 21:55:49 -04:00
|
|
|
// Initialize Veilid
|
|
|
|
Future<void> _initializeVeilid() async {
|
|
|
|
// Init Veilid
|
|
|
|
Veilid.instance.initializeVeilidCore(
|
2024-07-03 20:59:54 -04:00
|
|
|
await getDefaultVeilidPlatformConfig(kIsWeb, VeilidChatApp.name));
|
2023-12-26 20:26:54 -05:00
|
|
|
|
2024-04-03 21:55:49 -04:00
|
|
|
// Veilid logging
|
|
|
|
initVeilidLog(kDebugMode);
|
2023-12-26 20:26:54 -05:00
|
|
|
|
2024-04-03 21:55:49 -04:00
|
|
|
// Startup Veilid
|
|
|
|
await ProcessorRepository.instance.startup();
|
2024-02-12 10:35:41 -05:00
|
|
|
|
2024-04-03 21:55:49 -04:00
|
|
|
// DHT Record Pool
|
2024-04-06 22:36:30 -04:00
|
|
|
await DHTRecordPool.init(
|
|
|
|
logger: (message) => log.debug('DHTRecordPool: $message'));
|
2024-04-03 21:55:49 -04:00
|
|
|
}
|
2023-12-26 20:26:54 -05:00
|
|
|
|
|
|
|
// Initialize repositories
|
2024-04-03 21:55:49 -04:00
|
|
|
Future<void> _initializeRepositories() async {
|
|
|
|
await AccountRepository.instance.init();
|
|
|
|
}
|
|
|
|
|
|
|
|
static Future<VeilidChatGlobalInit> initialize() async {
|
|
|
|
final veilidChatGlobalInit = VeilidChatGlobalInit._();
|
2023-12-26 20:26:54 -05:00
|
|
|
|
2024-04-03 21:55:49 -04:00
|
|
|
log.info('Initializing Veilid');
|
|
|
|
await veilidChatGlobalInit._initializeVeilid();
|
|
|
|
log.info('Initializing Repositories');
|
|
|
|
await veilidChatGlobalInit._initializeRepositories();
|
2023-12-26 20:26:54 -05:00
|
|
|
|
2024-04-03 21:55:49 -04:00
|
|
|
return veilidChatGlobalInit;
|
|
|
|
}
|
2023-12-26 20:26:54 -05:00
|
|
|
}
|