fluffychat/lib/utils/sentry_controller.dart

38 lines
1.1 KiB
Dart
Raw Normal View History

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