veilidchat/lib/main.dart

69 lines
1.9 KiB
Dart
Raw Normal View History

2023-01-12 00:17:04 +00:00
import 'dart:async';
2023-07-26 18:20:29 +00:00
import 'dart:io';
2023-01-12 00:17:04 +00:00
2023-10-10 02:11:39 +00:00
import 'package:ansicolor/ansicolor.dart';
2023-01-12 00:17:04 +00:00
import 'package:flutter/foundation.dart';
2023-01-08 02:43:31 +00:00
import 'package:flutter/material.dart';
2023-07-23 03:29:10 +00:00
import 'package:flutter_translate/flutter_translate.dart';
2023-10-09 20:52:37 +00:00
import 'package:intl/date_symbol_data_local.dart';
2024-06-12 01:27:20 +00:00
2024-06-02 15:04:19 +00:00
import 'package:stack_trace/stack_trace.dart';
2023-07-23 03:29:10 +00:00
2023-07-26 18:20:29 +00:00
import 'app.dart';
2024-01-09 02:37:08 +00:00
import 'settings/preferences_repository.dart';
2023-12-27 01:26:54 +00:00
import 'theme/theme.dart';
2023-09-27 02:32:13 +00:00
import 'tools/tools.dart';
2023-07-24 03:13:21 +00:00
2023-01-09 03:27:33 +00:00
void main() async {
2023-01-12 00:17:04 +00:00
// Disable all debugprints in release mode
if (kReleaseMode) {
2023-07-26 18:20:29 +00:00
debugPrint = (message, {wrapWidth}) {};
2023-01-12 00:17:04 +00:00
}
// Print our PID for debugging
if (!kIsWeb) {
debugPrint('VeilidChat PID: $pid');
}
2023-10-10 02:11:39 +00:00
// Ansi colors
ansiColorDisabled = false;
2024-03-29 02:46:26 +00:00
Future<void> mainFunc() async {
2023-10-14 18:07:58 +00:00
// Logs
initLoggy();
2023-01-09 03:27:33 +00:00
2024-01-09 02:37:08 +00:00
// Prepare preferences from SharedPreferences and theme
2023-10-14 18:07:58 +00:00
WidgetsFlutterBinding.ensureInitialized();
2024-01-09 02:37:08 +00:00
await PreferencesRepository.instance.init();
final initialThemeData =
PreferencesRepository.instance.value.themePreferences.themeData();
2023-01-12 00:17:04 +00:00
2023-10-14 18:07:58 +00:00
// Manage window on desktop platforms
2023-12-28 03:56:24 +00:00
await initializeWindowControl();
2023-01-12 00:17:04 +00:00
2023-10-14 18:07:58 +00:00
// Make localization delegate
2024-02-12 04:18:20 +00:00
final localizationDelegate = await LocalizationDelegate.create(
2023-10-14 18:07:58 +00:00
fallbackLocale: 'en_US', supportedLocales: ['en_US']);
await initializeDateFormatting();
2023-07-07 23:33:28 +00:00
2024-06-12 01:27:20 +00:00
// Get package info
await initPackageInfo();
2023-10-14 18:07:58 +00:00
// Run the app
// Hot reloads will only restart this part, not Veilid
2024-02-12 04:18:20 +00:00
runApp(LocalizedApp(localizationDelegate,
VeilidChatApp(initialThemeData: initialThemeData)));
2024-03-29 02:46:26 +00:00
}
if (kDebugMode) {
// In debug mode, run the app without catching exceptions for debugging
2024-06-02 15:04:19 +00:00
// but do a much deeper async stack trace capture
await Chain.capture(mainFunc);
2024-03-29 02:46:26 +00:00
} else {
// Catch errors in production without killing the app
await runZonedGuarded(mainFunc, (error, stackTrace) {
log.error('Dart Runtime: {$error}\n{$stackTrace}');
});
}
2023-01-08 02:43:31 +00:00
}