From fdf7d8cf81a4495cc5a9f892b164b8daaae19b10 Mon Sep 17 00:00:00 2001 From: shenlong-tanwen <139912620+shalong-tanwen@users.noreply.github.com> Date: Tue, 3 Sep 2024 22:29:56 +0530 Subject: [PATCH] add framework error callbacks --- mobile-v2/lib/main.dart | 9 +------ ...dart => adaptive_route_appbar.widget.dart} | 15 +++++++++++ .../adaptive_route_primary_appbar.widget.dart | 17 ------------- .../settings/pages/about_settings.page.dart | 2 +- .../settings/pages/advance_settings.page.dart | 2 +- .../settings/pages/general_settings.page.dart | 2 +- .../modules/settings/pages/settings.page.dart | 2 +- mobile-v2/lib/utils/log_manager.dart | 25 +++++++++++++++++++ 8 files changed, 45 insertions(+), 29 deletions(-) rename mobile-v2/lib/presentation/components/scaffold/{adaptive_route_secondary_appbar.widget.dart => adaptive_route_appbar.widget.dart} (61%) delete mode 100644 mobile-v2/lib/presentation/components/scaffold/adaptive_route_primary_appbar.widget.dart diff --git a/mobile-v2/lib/main.dart b/mobile-v2/lib/main.dart index 979446091d..a37187541f 100644 --- a/mobile-v2/lib/main.dart +++ b/mobile-v2/lib/main.dart @@ -3,8 +3,6 @@ import 'package:immich_mobile/i18n/strings.g.dart'; import 'package:immich_mobile/immich_app.dart'; import 'package:immich_mobile/service_locator.dart'; import 'package:immich_mobile/utils/log_manager.dart'; -// ignore: depend_on_referenced_packages -import 'package:stack_trace/stack_trace.dart' as stack_trace; void main() { WidgetsFlutterBinding.ensureInitialized(); @@ -12,14 +10,9 @@ void main() { ServiceLocator.configureServices(); // Init logging LogManager.I.init(); + LogManager.setGlobalErrorCallbacks(); // Init localization LocaleSettings.useDeviceLocale(); - FlutterError.demangleStackTrace = (StackTrace stack) { - if (stack is stack_trace.Trace) return stack.vmTrace; - if (stack is stack_trace.Chain) return stack.toTrace().vmTrace; - return stack; - }; - runApp(const ImmichApp()); } diff --git a/mobile-v2/lib/presentation/components/scaffold/adaptive_route_secondary_appbar.widget.dart b/mobile-v2/lib/presentation/components/scaffold/adaptive_route_appbar.widget.dart similarity index 61% rename from mobile-v2/lib/presentation/components/scaffold/adaptive_route_secondary_appbar.widget.dart rename to mobile-v2/lib/presentation/components/scaffold/adaptive_route_appbar.widget.dart index ccb347a7eb..bb6190b9ae 100644 --- a/mobile-v2/lib/presentation/components/scaffold/adaptive_route_secondary_appbar.widget.dart +++ b/mobile-v2/lib/presentation/components/scaffold/adaptive_route_appbar.widget.dart @@ -2,6 +2,21 @@ import 'package:auto_route/auto_route.dart'; import 'package:flutter/material.dart'; import 'package:immich_mobile/utils/extensions/build_context.extension.dart'; +class ImAdaptiveRoutePrimaryAppBar extends StatelessWidget + implements PreferredSizeWidget { + const ImAdaptiveRoutePrimaryAppBar({super.key}); + + @override + Widget build(BuildContext context) { + return AppBar( + leading: BackButton(onPressed: () => context.router.root.maybePop()), + ); + } + + @override + Size get preferredSize => const Size.fromHeight(kToolbarHeight); +} + class ImAdaptiveRouteSecondaryAppBar extends StatelessWidget implements PreferredSizeWidget { const ImAdaptiveRouteSecondaryAppBar({super.key}); diff --git a/mobile-v2/lib/presentation/components/scaffold/adaptive_route_primary_appbar.widget.dart b/mobile-v2/lib/presentation/components/scaffold/adaptive_route_primary_appbar.widget.dart deleted file mode 100644 index 1629168a7e..0000000000 --- a/mobile-v2/lib/presentation/components/scaffold/adaptive_route_primary_appbar.widget.dart +++ /dev/null @@ -1,17 +0,0 @@ -import 'package:auto_route/auto_route.dart'; -import 'package:flutter/material.dart'; - -class ImAdaptiveRoutePrimaryAppBar extends StatelessWidget - implements PreferredSizeWidget { - const ImAdaptiveRoutePrimaryAppBar({super.key}); - - @override - Widget build(BuildContext context) { - return AppBar( - leading: BackButton(onPressed: () => context.router.root.maybePop()), - ); - } - - @override - Size get preferredSize => const Size.fromHeight(kToolbarHeight); -} diff --git a/mobile-v2/lib/presentation/modules/settings/pages/about_settings.page.dart b/mobile-v2/lib/presentation/modules/settings/pages/about_settings.page.dart index daa0ec146d..be71894c4c 100644 --- a/mobile-v2/lib/presentation/modules/settings/pages/about_settings.page.dart +++ b/mobile-v2/lib/presentation/modules/settings/pages/about_settings.page.dart @@ -1,6 +1,6 @@ import 'package:auto_route/auto_route.dart'; import 'package:flutter/material.dart'; -import 'package:immich_mobile/presentation/components/scaffold/adaptive_route_secondary_appbar.widget.dart'; +import 'package:immich_mobile/presentation/components/scaffold/adaptive_route_appbar.widget.dart'; @RoutePage() class AboutSettingsPage extends StatelessWidget { diff --git a/mobile-v2/lib/presentation/modules/settings/pages/advance_settings.page.dart b/mobile-v2/lib/presentation/modules/settings/pages/advance_settings.page.dart index 0ae30810d9..89dd35ab38 100644 --- a/mobile-v2/lib/presentation/modules/settings/pages/advance_settings.page.dart +++ b/mobile-v2/lib/presentation/modules/settings/pages/advance_settings.page.dart @@ -1,6 +1,6 @@ import 'package:auto_route/auto_route.dart'; import 'package:flutter/material.dart'; -import 'package:immich_mobile/presentation/components/scaffold/adaptive_route_secondary_appbar.widget.dart'; +import 'package:immich_mobile/presentation/components/scaffold/adaptive_route_appbar.widget.dart'; @RoutePage() class AdvanceSettingsPage extends StatelessWidget { diff --git a/mobile-v2/lib/presentation/modules/settings/pages/general_settings.page.dart b/mobile-v2/lib/presentation/modules/settings/pages/general_settings.page.dart index deabaead98..a4fe953bf9 100644 --- a/mobile-v2/lib/presentation/modules/settings/pages/general_settings.page.dart +++ b/mobile-v2/lib/presentation/modules/settings/pages/general_settings.page.dart @@ -1,6 +1,6 @@ import 'package:auto_route/auto_route.dart'; import 'package:flutter/material.dart'; -import 'package:immich_mobile/presentation/components/scaffold/adaptive_route_secondary_appbar.widget.dart'; +import 'package:immich_mobile/presentation/components/scaffold/adaptive_route_appbar.widget.dart'; @RoutePage() class GeneralSettingsPage extends StatelessWidget { diff --git a/mobile-v2/lib/presentation/modules/settings/pages/settings.page.dart b/mobile-v2/lib/presentation/modules/settings/pages/settings.page.dart index 59a3729c9e..7657dc175f 100644 --- a/mobile-v2/lib/presentation/modules/settings/pages/settings.page.dart +++ b/mobile-v2/lib/presentation/modules/settings/pages/settings.page.dart @@ -1,7 +1,7 @@ import 'package:auto_route/auto_route.dart'; import 'package:flutter/material.dart'; import 'package:immich_mobile/i18n/strings.g.dart'; -import 'package:immich_mobile/presentation/components/scaffold/adaptive_route_primary_appbar.widget.dart'; +import 'package:immich_mobile/presentation/components/scaffold/adaptive_route_appbar.widget.dart'; import 'package:immich_mobile/presentation/components/scaffold/adaptive_route_wrapper.widget.dart'; import 'package:immich_mobile/presentation/modules/settings/models/settings_section.model.dart'; import 'package:immich_mobile/presentation/router/router.dart'; diff --git a/mobile-v2/lib/utils/log_manager.dart b/mobile-v2/lib/utils/log_manager.dart index de40ea9e78..af168c0062 100644 --- a/mobile-v2/lib/utils/log_manager.dart +++ b/mobile-v2/lib/utils/log_manager.dart @@ -5,6 +5,8 @@ import 'package:immich_mobile/domain/interfaces/log.interface.dart'; import 'package:immich_mobile/domain/models/log.model.dart'; import 'package:immich_mobile/service_locator.dart'; import 'package:logging/logging.dart'; +// ignore: depend_on_referenced_packages +import 'package:stack_trace/stack_trace.dart' as stack_trace; /// [LogManager] is a custom logger that is built on top of the [logging] package. /// The logs are written to the database and onto console, using `debugPrint` method. @@ -72,4 +74,27 @@ class LogManager { _msgBuffer.clear(); di().clear(); } + + static void setGlobalErrorCallbacks() { + FlutterError.demangleStackTrace = (StackTrace stack) { + if (stack is stack_trace.Trace) return stack.vmTrace; + if (stack is stack_trace.Chain) return stack.toTrace().vmTrace; + return stack; + }; + + FlutterError.onError = (details) { + Logger("FlutterError").severe( + 'Unknown framework error occured in library ${details.library ?? ""} at node ${details.context ?? ""}', + details.exception, + details.stack, + ); + FlutterError.presentError(details); + }; + + PlatformDispatcher.instance.onError = (error, stack) { + Logger("PlatformDispatcher") + .severe('Unknown error occured in root isolate', error, stack); + return true; + }; + } }