Merge pull request #689 from NBA2K1/main

Move Flutter initialization and error handlers into runZonedGuarded and add Linux exit workaround
This commit is contained in:
Moustapha Kodjo Amadou 2026-04-07 10:38:57 +01:00 committed by GitHub
commit e5d359d6c3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -56,30 +56,30 @@ DiscordRPC? discordRpc;
WebViewEnvironment? webViewEnvironment;
String? customDns;
void main(List<String> args) async {
WidgetsFlutterBinding.ensureInitialized();
if (Platform.isLinux && runWebViewTitleBarWidget(args)) return;
// Widget-layer errors (build / layout / paint)
FlutterError.onError = (FlutterErrorDetails details) {
FlutterError.presentError(details); // keep default red-screen in debug
AppLogger.log(
'FlutterError: ${details.exceptionAsString()}\n${details.stack}',
logLevel: LogLevel.error,
);
};
// Async errors that escape the Flutter framework (PlatformDispatcher)
PlatformDispatcher.instance.onError = (Object error, StackTrace stack) {
AppLogger.log(
'PlatformDispatcher error: $error\n$stack',
logLevel: LogLevel.error,
);
return true; // handled prevent app termination
};
// Zone-level catch-all for anything that slips through both layers
runZonedGuarded(
() async {
WidgetsFlutterBinding.ensureInitialized();
if (Platform.isLinux && runWebViewTitleBarWidget(args)) return;
// Widget-layer errors (build / layout / paint)
FlutterError.onError = (FlutterErrorDetails details) {
FlutterError.presentError(details); // keep default red-screen in debug
AppLogger.log(
'FlutterError: ${details.exceptionAsString()}\n${details.stack}',
logLevel: LogLevel.error,
);
};
// Async errors that escape the Flutter framework (PlatformDispatcher)
PlatformDispatcher.instance.onError = (Object error, StackTrace stack) {
AppLogger.log(
'PlatformDispatcher error: $error\n$stack',
logLevel: LogLevel.error,
);
return true; // handled prevent app termination
};
MediaKit.ensureInitialized();
await RustLib.init();
await imgCropIsolate.start();
@ -250,7 +250,11 @@ class _MyAppState extends ConsumerState<MyApp>
void onWindowMoved() => WindowGeometry.save();
@override
void onWindowClose() => WindowGeometry.save();
void onWindowClose() {
WindowGeometry.save();
// Workaround for libepoxy error when closing app; caused by media-kit
if (Platform.isLinux) exit(0);
}
Future<void> _initDeepLinks() async {
_appLinks = AppLinks();