2023-01-11 19:17:04 -05:00
|
|
|
import 'dart:async';
|
2023-07-26 14:20:29 -04:00
|
|
|
import 'dart:io';
|
2023-01-11 19:17:04 -05:00
|
|
|
|
2023-10-09 22:11:39 -04:00
|
|
|
import 'package:ansicolor/ansicolor.dart';
|
2023-01-11 19:17:04 -05:00
|
|
|
import 'package:flutter/foundation.dart';
|
2023-01-07 21:43:31 -05:00
|
|
|
import 'package:flutter/material.dart';
|
2023-07-22 23:29:10 -04:00
|
|
|
import 'package:flutter_translate/flutter_translate.dart';
|
2023-10-09 16:52:37 -04:00
|
|
|
import 'package:intl/date_symbol_data_local.dart';
|
2023-07-22 23:29:10 -04:00
|
|
|
|
2023-07-26 14:20:29 -04:00
|
|
|
import 'app.dart';
|
2023-12-27 22:56:24 -05:00
|
|
|
import 'init.dart';
|
2024-01-08 21:37:08 -05:00
|
|
|
import 'settings/preferences_repository.dart';
|
2023-12-26 20:26:54 -05:00
|
|
|
import 'theme/theme.dart';
|
2023-09-26 22:32:13 -04:00
|
|
|
import 'tools/tools.dart';
|
2023-07-23 23:13:21 -04:00
|
|
|
|
2023-01-08 22:27:33 -05:00
|
|
|
void main() async {
|
2023-01-11 19:17:04 -05:00
|
|
|
// Disable all debugprints in release mode
|
|
|
|
if (kReleaseMode) {
|
2023-07-26 14:20:29 -04:00
|
|
|
debugPrint = (message, {wrapWidth}) {};
|
2023-01-11 19:17:04 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Print our PID for debugging
|
|
|
|
if (!kIsWeb) {
|
|
|
|
debugPrint('VeilidChat PID: $pid');
|
|
|
|
}
|
|
|
|
|
2023-10-09 22:11:39 -04:00
|
|
|
// Ansi colors
|
|
|
|
ansiColorDisabled = false;
|
|
|
|
|
2023-10-14 14:07:58 -04:00
|
|
|
// Catch errors
|
|
|
|
await runZonedGuarded(() async {
|
|
|
|
// Logs
|
|
|
|
initLoggy();
|
2023-01-08 22:27:33 -05:00
|
|
|
|
2024-01-08 21:37:08 -05:00
|
|
|
// Prepare preferences from SharedPreferences and theme
|
2023-10-14 14:07:58 -04:00
|
|
|
WidgetsFlutterBinding.ensureInitialized();
|
2024-01-08 21:37:08 -05:00
|
|
|
await PreferencesRepository.instance.init();
|
|
|
|
final initialThemeData =
|
|
|
|
PreferencesRepository.instance.value.themePreferences.themeData();
|
2023-01-11 19:17:04 -05:00
|
|
|
|
2023-10-14 14:07:58 -04:00
|
|
|
// Manage window on desktop platforms
|
2023-12-27 22:56:24 -05:00
|
|
|
await initializeWindowControl();
|
2023-01-11 19:17:04 -05:00
|
|
|
|
2023-10-14 14:07:58 -04:00
|
|
|
// Make localization delegate
|
2024-02-11 23:18:20 -05:00
|
|
|
final localizationDelegate = await LocalizationDelegate.create(
|
2023-10-14 14:07:58 -04:00
|
|
|
fallbackLocale: 'en_US', supportedLocales: ['en_US']);
|
|
|
|
await initializeDateFormatting();
|
2023-07-07 19:33:28 -04:00
|
|
|
|
2023-10-14 14:07:58 -04:00
|
|
|
// Start up Veilid and Veilid processor in the background
|
2024-01-08 21:37:08 -05:00
|
|
|
unawaited(initializeVeilidChat());
|
2023-07-22 23:29:10 -04:00
|
|
|
|
2023-10-14 14:07:58 -04:00
|
|
|
// Run the app
|
|
|
|
// Hot reloads will only restart this part, not Veilid
|
2024-02-11 23:18:20 -05:00
|
|
|
runApp(LocalizedApp(localizationDelegate,
|
|
|
|
VeilidChatApp(initialThemeData: initialThemeData)));
|
2023-10-09 16:52:37 -04:00
|
|
|
}, (error, stackTrace) {
|
|
|
|
log.error('Dart Runtime: {$error}\n{$stackTrace}');
|
|
|
|
});
|
2023-01-07 21:43:31 -05:00
|
|
|
}
|