veilidchat/lib/init.dart

47 lines
1.2 KiB
Dart
Raw Normal View History

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