Add Sentry crash-reporting opt-out (#211)
* Add Sentry opt-out * [chore] Remove inaccurate comment * Prevent line-wrap in iOS
This commit is contained in:
parent
e5ca54f7f2
commit
3d250f4e41
|
@ -2,7 +2,7 @@ import 'dart:async';
|
|||
|
||||
import 'package:flutter/cupertino.dart' show CupertinoThemeData, DefaultCupertinoLocalizations;
|
||||
import 'package:flutter/material.dart'
|
||||
show BottomSheetThemeData, Colors, DefaultMaterialLocalizations, ThemeData, ThemeMode, MaterialApp, Scaffold;
|
||||
show BottomSheetThemeData, Colors, DefaultMaterialLocalizations, ThemeData, ThemeMode;
|
||||
import 'package:flutter/scheduler.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
@ -15,18 +15,22 @@ import 'package:sentry_flutter/sentry_flutter.dart';
|
|||
|
||||
Future<void> main() async {
|
||||
usePathUrlStrategy();
|
||||
await SentryFlutter.init(
|
||||
(options) {
|
||||
options.dsn = 'https://96106df405ade3f013187dfc8e4200e7@o920269.ingest.us.sentry.io/4508132321001472';
|
||||
// Capture all traces. May need to adjust if overwhelming
|
||||
options.tracesSampleRate = 1.0;
|
||||
// For each trace, capture all profiles
|
||||
options.profilesSampleRate = 1.0;
|
||||
},
|
||||
appRunner: () => runApp(Main()),
|
||||
);
|
||||
|
||||
// or define SENTRY_DSN via Dart environment variable (--dart-define)
|
||||
var settings = Settings();
|
||||
if (settings.trackErrors) {
|
||||
await SentryFlutter.init(
|
||||
(options) {
|
||||
options.dsn = 'https://96106df405ade3f013187dfc8e4200e7@o920269.ingest.us.sentry.io/4508132321001472';
|
||||
// Capture all traces. May need to adjust if overwhelming
|
||||
options.tracesSampleRate = 1.0;
|
||||
// For each trace, capture all profiles
|
||||
options.profilesSampleRate = 1.0;
|
||||
},
|
||||
appRunner: () => runApp(Main()),
|
||||
);
|
||||
} else {
|
||||
runApp(Main());
|
||||
}
|
||||
}
|
||||
|
||||
//TODO: EventChannel might be better than the stream controller we are using now
|
||||
|
|
|
@ -85,10 +85,27 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
|||
)),
|
||||
));
|
||||
|
||||
items.add(ConfigSection(children: [
|
||||
ConfigItem(
|
||||
label: Text('Report errors automatically'),
|
||||
labelWidth: 250,
|
||||
content: Align(
|
||||
alignment: Alignment.centerRight,
|
||||
child: Switch.adaptive(
|
||||
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
||||
value: settings.trackErrors,
|
||||
onChanged: (value) {
|
||||
setState(() {
|
||||
settings.trackErrors = value;
|
||||
});
|
||||
},
|
||||
))),
|
||||
]));
|
||||
|
||||
items.add(ConfigSection(children: [
|
||||
ConfigPageItem(
|
||||
label: Text('Enroll with Managed Nebula'),
|
||||
labelWidth: 200,
|
||||
labelWidth: 250,
|
||||
onPressed: () =>
|
||||
Utils.openPage(context, (context) => EnrollmentScreen(stream: widget.stream, allowCodeEntry: true)))
|
||||
]));
|
||||
|
|
|
@ -3,6 +3,10 @@ import 'dart:convert';
|
|||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/scheduler.dart';
|
||||
import 'package:mobile_nebula/services/storage.dart';
|
||||
import 'package:sentry_flutter/sentry_flutter.dart';
|
||||
|
||||
bool DEFAULT_LOG_WRAP = false;
|
||||
bool DEFAULT_TRACK_ERRORS = true;
|
||||
|
||||
class Settings {
|
||||
final _storage = Storage();
|
||||
|
@ -30,13 +34,26 @@ class Settings {
|
|||
}
|
||||
|
||||
bool get logWrap {
|
||||
return _getBool('logWrap', false);
|
||||
return _getBool('logWrap', DEFAULT_LOG_WRAP);
|
||||
}
|
||||
|
||||
set logWrap(bool enabled) {
|
||||
_set('logWrap', enabled);
|
||||
}
|
||||
|
||||
bool get trackErrors {
|
||||
return _getBool('trackErrors', DEFAULT_TRACK_ERRORS);
|
||||
}
|
||||
|
||||
set trackErrors(bool enabled) {
|
||||
_set('trackErrors', enabled);
|
||||
|
||||
// Side-effect: Disable Sentry immediately
|
||||
if (!enabled) {
|
||||
Sentry.close();
|
||||
}
|
||||
}
|
||||
|
||||
String _getString(String key, String defaultValue) {
|
||||
final val = _settings[key];
|
||||
if (val is String) {
|
||||
|
|
|
@ -42,7 +42,6 @@ class Storage {
|
|||
// Read the file
|
||||
return await file.readAsString();
|
||||
} catch (e) {
|
||||
// If encountering an error, return 0
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue