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/cupertino.dart' show CupertinoThemeData, DefaultCupertinoLocalizations;
|
||||||
import 'package:flutter/material.dart'
|
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/scheduler.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'package:flutter/widgets.dart';
|
import 'package:flutter/widgets.dart';
|
||||||
|
@ -15,6 +15,9 @@ import 'package:sentry_flutter/sentry_flutter.dart';
|
||||||
|
|
||||||
Future<void> main() async {
|
Future<void> main() async {
|
||||||
usePathUrlStrategy();
|
usePathUrlStrategy();
|
||||||
|
|
||||||
|
var settings = Settings();
|
||||||
|
if (settings.trackErrors) {
|
||||||
await SentryFlutter.init(
|
await SentryFlutter.init(
|
||||||
(options) {
|
(options) {
|
||||||
options.dsn = 'https://96106df405ade3f013187dfc8e4200e7@o920269.ingest.us.sentry.io/4508132321001472';
|
options.dsn = 'https://96106df405ade3f013187dfc8e4200e7@o920269.ingest.us.sentry.io/4508132321001472';
|
||||||
|
@ -25,8 +28,9 @@ Future<void> main() async {
|
||||||
},
|
},
|
||||||
appRunner: () => runApp(Main()),
|
appRunner: () => runApp(Main()),
|
||||||
);
|
);
|
||||||
|
} else {
|
||||||
// or define SENTRY_DSN via Dart environment variable (--dart-define)
|
runApp(Main());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: EventChannel might be better than the stream controller we are using now
|
//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: [
|
items.add(ConfigSection(children: [
|
||||||
ConfigPageItem(
|
ConfigPageItem(
|
||||||
label: Text('Enroll with Managed Nebula'),
|
label: Text('Enroll with Managed Nebula'),
|
||||||
labelWidth: 200,
|
labelWidth: 250,
|
||||||
onPressed: () =>
|
onPressed: () =>
|
||||||
Utils.openPage(context, (context) => EnrollmentScreen(stream: widget.stream, allowCodeEntry: true)))
|
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/cupertino.dart';
|
||||||
import 'package:flutter/scheduler.dart';
|
import 'package:flutter/scheduler.dart';
|
||||||
import 'package:mobile_nebula/services/storage.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 {
|
class Settings {
|
||||||
final _storage = Storage();
|
final _storage = Storage();
|
||||||
|
@ -30,13 +34,26 @@ class Settings {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool get logWrap {
|
bool get logWrap {
|
||||||
return _getBool('logWrap', false);
|
return _getBool('logWrap', DEFAULT_LOG_WRAP);
|
||||||
}
|
}
|
||||||
|
|
||||||
set logWrap(bool enabled) {
|
set logWrap(bool enabled) {
|
||||||
_set('logWrap', 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) {
|
String _getString(String key, String defaultValue) {
|
||||||
final val = _settings[key];
|
final val = _settings[key];
|
||||||
if (val is String) {
|
if (val is String) {
|
||||||
|
|
|
@ -42,7 +42,6 @@ class Storage {
|
||||||
// Read the file
|
// Read the file
|
||||||
return await file.readAsString();
|
return await file.readAsString();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// If encountering an error, return 0
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue