From 9218eb646ebe7900b20cc917277234c410b5d245 Mon Sep 17 00:00:00 2001 From: debuggerx Date: Thu, 20 Apr 2023 18:53:21 +0800 Subject: [PATCH] add sentry. --- lib/main.dart | 24 +++++++++++++++++++++++- linux/flutter/generated_plugin_registrant.cc | 4 ++++ linux/flutter/generated_plugins.cmake | 1 + pubspec.yaml | 1 + 4 files changed, 29 insertions(+), 1 deletion(-) diff --git a/lib/main.dart b/lib/main.dart index efabec1..8ab0a74 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -7,6 +7,7 @@ import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_acrylic/flutter_acrylic.dart'; +import 'package:sentry_flutter/sentry_flutter.dart'; import 'package:url_launcher/url_launcher_string.dart'; import 'package:window_manager/window_manager.dart'; import 'package:zbar_scan_plugin/zbar_scan_plugin.dart' as zbar; @@ -35,7 +36,19 @@ Future main() async { await windowManager.focus(); }); - runApp(const MyApp()); + await SentryFlutter.init( + (options) { + options.dsn = 'https://6b0c6212196241fa88df20dfcc495c4a@o644838.ingest.sentry.io/4505045898166272'; + options.tracesSampleRate = 1.0; + options.reportPackages = false; + Sentry.configureScope( + (scope) => scope.setUser( + SentryUser(username: Platform.environment['USER']), + ), + ); + }, + appRunner: () => runApp(const MyApp()), + ); } class MyApp extends StatelessWidget { @@ -100,6 +113,12 @@ class _MyHomePageState extends State { status = codes.isEmpty ? Status.notFound : Status.found; }); } + Sentry.captureMessage( + 'Found ${result.length} codes.', + withScope: (scope) { + SentryUser(username: Platform.environment['USER']); + }, + ); Future.delayed(const Duration(seconds: 3), () { if (status == Status.notFound) { exit(0); @@ -125,6 +144,9 @@ class _MyHomePageState extends State { @override Widget build(BuildContext context) { + if (MediaQuery.of(context).size.shortestSide < 10) { + return const SizedBox.shrink(); + } return GestureDetector( onTap: () { if ([ diff --git a/linux/flutter/generated_plugin_registrant.cc b/linux/flutter/generated_plugin_registrant.cc index e379152..297eb50 100644 --- a/linux/flutter/generated_plugin_registrant.cc +++ b/linux/flutter/generated_plugin_registrant.cc @@ -8,6 +8,7 @@ #include #include +#include #include #include @@ -18,6 +19,9 @@ void fl_register_plugins(FlPluginRegistry* registry) { g_autoptr(FlPluginRegistrar) screen_retriever_registrar = fl_plugin_registry_get_registrar_for_plugin(registry, "ScreenRetrieverPlugin"); screen_retriever_plugin_register_with_registrar(screen_retriever_registrar); + g_autoptr(FlPluginRegistrar) sentry_flutter_registrar = + fl_plugin_registry_get_registrar_for_plugin(registry, "SentryFlutterPlugin"); + sentry_flutter_plugin_register_with_registrar(sentry_flutter_registrar); g_autoptr(FlPluginRegistrar) url_launcher_linux_registrar = fl_plugin_registry_get_registrar_for_plugin(registry, "UrlLauncherPlugin"); url_launcher_plugin_register_with_registrar(url_launcher_linux_registrar); diff --git a/linux/flutter/generated_plugins.cmake b/linux/flutter/generated_plugins.cmake index c5fb1d8..0e93bd5 100644 --- a/linux/flutter/generated_plugins.cmake +++ b/linux/flutter/generated_plugins.cmake @@ -5,6 +5,7 @@ list(APPEND FLUTTER_PLUGIN_LIST flutter_acrylic screen_retriever + sentry_flutter url_launcher_linux window_manager ) diff --git a/pubspec.yaml b/pubspec.yaml index a3d0dc6..ec80cc9 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -42,6 +42,7 @@ dependencies: zbar_scan_plugin: git: url: https://github.com/debuggerx01/zbar_scan_plugin.git + sentry_flutter: ^7.4.2 dev_dependencies: flutter_test: