f655adfbea
Migrate app code into canonical feature slices, add phone-only AI digest scheduling and review, wire local notification/background task support, and cover the flow with tests.
64 lines
1.7 KiB
Dart
64 lines
1.7 KiB
Dart
import 'dart:async';
|
|
|
|
import 'package:flutter/foundation.dart';
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
import 'package:relationship_saver/core/config/app_config.dart';
|
|
import 'package:sentry_flutter/sentry_flutter.dart';
|
|
|
|
class SentryInit {
|
|
SentryInit();
|
|
|
|
Future<void>? _initializeFuture;
|
|
bool _initialized = false;
|
|
|
|
Future<void> initialize({FutureOr<void> Function()? appRunner}) async {
|
|
final Future<void>? inFlight = _initializeFuture;
|
|
if (inFlight != null) {
|
|
await inFlight;
|
|
if (appRunner != null && !_initialized) {
|
|
await Future<void>.sync(appRunner);
|
|
}
|
|
return;
|
|
}
|
|
|
|
_initializeFuture = _initializeInternal(appRunner: appRunner);
|
|
return _initializeFuture;
|
|
}
|
|
|
|
Future<void> _initializeInternal({
|
|
FutureOr<void> Function()? appRunner,
|
|
}) async {
|
|
if (!kReleaseMode || AppConfig.sentryDsn.isEmpty) {
|
|
if (appRunner != null) {
|
|
await Future<void>.sync(appRunner);
|
|
}
|
|
return;
|
|
}
|
|
|
|
await SentryFlutter.init((options) {
|
|
options.dsn = AppConfig.sentryDsn;
|
|
options.environment = AppConfig.useFakeBackend
|
|
? 'development'
|
|
: 'production';
|
|
options.tracesSampleRate = 0.1;
|
|
}, appRunner: appRunner);
|
|
_initialized = true;
|
|
}
|
|
|
|
void captureException(Object error, {StackTrace? stackTrace}) {
|
|
if (_initialized) {
|
|
Sentry.captureException(error, stackTrace: stackTrace);
|
|
}
|
|
}
|
|
|
|
void captureMessage(String message, {SentryLevel level = SentryLevel.info}) {
|
|
if (_initialized) {
|
|
Sentry.captureMessage(message, level: level);
|
|
}
|
|
}
|
|
}
|
|
|
|
final sentryInitProvider = Provider<SentryInit>((Ref ref) {
|
|
return SentryInit();
|
|
});
|