fluffychat/lib/utils/sentry_controller.dart

37 lines
1.1 KiB
Dart
Raw Normal View History

2020-12-19 12:06:31 +00:00
import 'package:famedlysdk/famedlysdk.dart';
2021-04-09 14:29:48 +00:00
import 'package:fluffychat/config/app_config.dart';
2020-09-08 08:55:32 +00:00
import 'package:flutter/material.dart';
2020-10-28 17:13:04 +00:00
import 'package:flutter/foundation.dart';
2020-10-28 09:56:24 +00:00
import 'package:sentry/sentry.dart';
2020-10-13 10:20:13 +00:00
import 'famedlysdk_store.dart';
import '../config/setting_keys.dart';
2020-09-08 08:55:32 +00:00
abstract class SentryController {
2021-01-17 14:33:31 +00:00
static Future<void> toggleSentryAction(
BuildContext context, bool enableSentry) async {
2020-12-11 13:14:33 +00:00
if (!AppConfig.enableSentry) return;
2020-10-25 15:59:55 +00:00
final storage = Store();
await storage.setItem(SettingKeys.sentry, enableSentry.toString());
2020-09-08 08:55:32 +00:00
return;
}
static Future<bool> getSentryStatus() async {
2020-12-11 13:14:33 +00:00
if (!AppConfig.enableSentry) return false;
2020-10-25 15:59:55 +00:00
final storage = Store();
return await storage.getItemBool(SettingKeys.sentry);
2020-09-08 08:55:32 +00:00
}
2020-10-28 09:56:24 +00:00
2020-12-11 13:14:33 +00:00
static final sentry = SentryClient(dsn: AppConfig.sentryDns);
2020-10-28 09:56:24 +00:00
static void captureException(error, stackTrace) async {
2020-12-19 12:06:31 +00:00
Logs().e('Capture exception', error, stackTrace);
2020-10-28 17:13:04 +00:00
if (!kDebugMode && await getSentryStatus()) {
2020-10-28 09:56:24 +00:00
await sentry.captureException(
exception: error,
stackTrace: stackTrace,
);
}
}
2020-09-08 08:55:32 +00:00
}