From 29e83c6e695e86ee415aa3356d5fcd3e451bddab Mon Sep 17 00:00:00 2001 From: Maximilian Mitchell Date: Sun, 31 Oct 2021 11:21:58 +0000 Subject: [PATCH] add sentry --- lib/main.dart | 51 ++++++++++--------- lib/utils/utils.dart | 11 +++- linux/flutter/generated_plugin_registrant.cc | 4 ++ linux/flutter/generated_plugins.cmake | 1 + macos/Flutter/GeneratedPluginRegistrant.swift | 2 + pubspec.yaml | 1 + 6 files changed, 44 insertions(+), 26 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index 7f839440..efd66690 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -4,6 +4,7 @@ import 'package:desktop_window/desktop_window.dart'; import 'package:firebase_messaging/firebase_messaging.dart'; import 'package:flutter/material.dart'; import 'package:flutter_app_icon_badge/flutter_app_icon_badge.dart'; +import 'package:flutter_dotenv/flutter_dotenv.dart'; import 'package:flutter_local_notifications/flutter_local_notifications.dart'; import 'package:notifi/notifications/db_provider.dart'; import 'package:notifi/notifications/notification.dart'; @@ -20,6 +21,7 @@ import 'package:provider/single_child_widget.dart'; import 'package:shared_preferences/shared_preferences.dart'; import 'package:sqflite_common_ffi/sqflite_ffi.dart'; import 'package:sqflite/sqflite.dart'; +import 'package:sentry_flutter/sentry_flutter.dart'; Future main() => mainImpl(); @@ -72,30 +74,31 @@ Future mainImpl({bool integration: false}) async { } catch (_) { canBadge = false; } - - runApp(MultiProvider( - providers: [ - ChangeNotifierProvider( - create: (BuildContext context) => TableNotifier()), - ChangeNotifierProxyProvider( - create: (BuildContext context) => Notifications(notifications, db, - Provider.of(context, listen: false), - canBadge: canBadge), - update: (BuildContext context, TableNotifier tableNotifier, - Notifications user) => - user..setTableNotifier(tableNotifier), - ), - ChangeNotifierProxyProvider( - create: (BuildContext context) => User( - Provider.of(context, listen: false), - pushNotifications), - update: - (BuildContext context, Notifications notifications, User user) => - user..setNotifications(notifications), - ), - ], - child: const MyApp(), - )); + await SentryFlutter.init( + (SentryFlutterOptions options) => options.dsn = dotenv.env['SENTRY_DSN'], + appRunner: () => runApp(MultiProvider( + providers: [ + ChangeNotifierProvider( + create: (BuildContext context) => TableNotifier()), + ChangeNotifierProxyProvider( + create: (BuildContext context) => Notifications(notifications, + db, Provider.of(context, listen: false), + canBadge: canBadge), + update: (BuildContext context, TableNotifier tableNotifier, + Notifications user) => + user..setTableNotifier(tableNotifier), + ), + ChangeNotifierProxyProvider( + create: (BuildContext context) => User( + Provider.of(context, listen: false), + pushNotifications), + update: (BuildContext context, Notifications notifications, + User user) => + user..setNotifications(notifications), + ), + ], + child: const MyApp(), + ))); } class MyApp extends StatefulWidget { diff --git a/lib/utils/utils.dart b/lib/utils/utils.dart index 8a41cd27..63863f46 100644 --- a/lib/utils/utils.dart +++ b/lib/utils/utils.dart @@ -66,8 +66,15 @@ Future loadDotEnv() async { return true; } else { await dotenv.load(); - return dotenv.isEveryDefined( - ['HOST', 'WS_HOST', 'KEY_STORE', 'TLS', 'SERVER_KEY', 'DEV']); + return dotenv.isEveryDefined([ + 'HOST', + 'WS_HOST', + 'KEY_STORE', + 'TLS', + 'SERVER_KEY', + 'DEV', + 'SENTRY_DSN' + ]); } } diff --git a/linux/flutter/generated_plugin_registrant.cc b/linux/flutter/generated_plugin_registrant.cc index 9a5ae0b9..cbe3dda7 100644 --- a/linux/flutter/generated_plugin_registrant.cc +++ b/linux/flutter/generated_plugin_registrant.cc @@ -8,6 +8,7 @@ #include #include +#include #include void fl_register_plugins(FlPluginRegistry* registry) { @@ -17,6 +18,9 @@ void fl_register_plugins(FlPluginRegistry* registry) { g_autoptr(FlPluginRegistrar) flutter_app_icon_badge_registrar = fl_plugin_registry_get_registrar_for_plugin(registry, "FlutterAppIconBadgePlugin"); flutter_app_icon_badge_plugin_register_with_registrar(flutter_app_icon_badge_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 b1c96538..19e09261 100644 --- a/linux/flutter/generated_plugins.cmake +++ b/linux/flutter/generated_plugins.cmake @@ -5,6 +5,7 @@ list(APPEND FLUTTER_PLUGIN_LIST desktop_window flutter_app_icon_badge + sentry_flutter url_launcher_linux ) diff --git a/macos/Flutter/GeneratedPluginRegistrant.swift b/macos/Flutter/GeneratedPluginRegistrant.swift index c2601549..b3cc70ef 100644 --- a/macos/Flutter/GeneratedPluginRegistrant.swift +++ b/macos/Flutter/GeneratedPluginRegistrant.swift @@ -15,6 +15,7 @@ import launch_at_login import package_info import package_info_plus_macos import path_provider_macos +import sentry_flutter import share_plus_macos import shared_preferences_macos import sqflite @@ -31,6 +32,7 @@ func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { FLTPackageInfoPlugin.register(with: registry.registrar(forPlugin: "FLTPackageInfoPlugin")) FLTPackageInfoPlusPlugin.register(with: registry.registrar(forPlugin: "FLTPackageInfoPlusPlugin")) PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin")) + SentryFlutterPlugin.register(with: registry.registrar(forPlugin: "SentryFlutterPlugin")) SharePlusMacosPlugin.register(with: registry.registrar(forPlugin: "SharePlusMacosPlugin")) SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin")) SqflitePlugin.register(with: registry.registrar(forPlugin: "SqflitePlugin")) diff --git a/pubspec.yaml b/pubspec.yaml index c5de3781..61f5eb5a 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -47,6 +47,7 @@ dependencies: path_provider: ^2.0.2 provider: ^6.0.0 pull_to_refresh: ^2.0.0 + sentry_flutter: ^6.0.1 share_plus: ^3.0.2 shared_preferences: ^2.0.6 sqflite: ^2.0.0+3