0
Fork 0
mirror of https://github.com/immich-app/immich.git synced 2025-01-21 00:52:43 -05:00

add framework error callbacks

This commit is contained in:
shenlong-tanwen 2024-09-03 22:29:56 +05:30
parent 3246aceab5
commit fdf7d8cf81
8 changed files with 45 additions and 29 deletions

View file

@ -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());
}

View file

@ -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});

View file

@ -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);
}

View file

@ -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 {

View file

@ -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 {

View file

@ -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 {

View file

@ -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';

View file

@ -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<ILogRepository>().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 ?? "<unknown>"} at node ${details.context ?? "<unkown>"}',
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;
};
}
}