mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-27 09:06:43 +08:00
Allow Analytics collection and Crash report collection to be disabled
As the developer I really don't want users to disable these, but as a User, I always want the option, so I should include it.
This commit is contained in:
10
lib/app.dart
10
lib/app.dart
@ -19,15 +19,15 @@ import 'screens/githostsetup_screens.dart';
|
|||||||
import 'screens/onboarding_screens.dart';
|
import 'screens/onboarding_screens.dart';
|
||||||
|
|
||||||
class JournalApp extends StatelessWidget {
|
class JournalApp extends StatelessWidget {
|
||||||
static Future main() async {
|
static Future main(SharedPreferences pref) async {
|
||||||
Fimber.plantTree(DebugTree.elapsed(useColors: true));
|
Fimber.plantTree(DebugTree.elapsed(useColors: true));
|
||||||
|
|
||||||
var pref = await SharedPreferences.getInstance();
|
|
||||||
var appState = AppState(pref);
|
var appState = AppState(pref);
|
||||||
|
|
||||||
appState.dumpToLog();
|
appState.dumpToLog();
|
||||||
|
|
||||||
_enableAnalyticsIfPossible();
|
if (Settings.instance.collectUsageStatistics) {
|
||||||
|
_enableAnalyticsIfPossible();
|
||||||
|
}
|
||||||
|
|
||||||
if (appState.localGitRepoConfigured == false) {
|
if (appState.localGitRepoConfigured == false) {
|
||||||
// FIXME: What about exceptions!
|
// FIXME: What about exceptions!
|
||||||
@ -41,8 +41,6 @@ class JournalApp extends StatelessWidget {
|
|||||||
var dir = await getGitBaseDirectory();
|
var dir = await getGitBaseDirectory();
|
||||||
appState.gitBaseDirectory = dir.path;
|
appState.gitBaseDirectory = dir.path;
|
||||||
|
|
||||||
Settings.instance.load(pref);
|
|
||||||
|
|
||||||
runApp(StateContainer(
|
runApp(StateContainer(
|
||||||
appState: appState,
|
appState: appState,
|
||||||
child: JournalApp(),
|
child: JournalApp(),
|
||||||
|
@ -2,23 +2,32 @@ import 'dart:async';
|
|||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_crashlytics/flutter_crashlytics.dart';
|
import 'package:flutter_crashlytics/flutter_crashlytics.dart';
|
||||||
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
|
|
||||||
import 'package:journal/app.dart';
|
import 'package:journal/app.dart';
|
||||||
|
import 'package:journal/settings.dart';
|
||||||
|
|
||||||
void main() async {
|
void main() async {
|
||||||
|
var pref = await SharedPreferences.getInstance();
|
||||||
|
Settings.instance.load(pref);
|
||||||
|
|
||||||
|
var reportCrashes =
|
||||||
|
!JournalApp.isInDebugMode && Settings.instance.collectCrashReports;
|
||||||
|
|
||||||
FlutterError.onError = (FlutterErrorDetails details) {
|
FlutterError.onError = (FlutterErrorDetails details) {
|
||||||
if (JournalApp.isInDebugMode) {
|
if (!reportCrashes) {
|
||||||
FlutterError.dumpErrorToConsole(details);
|
FlutterError.dumpErrorToConsole(details);
|
||||||
} else {
|
} else {
|
||||||
Zone.current.handleUncaughtError(details.exception, details.stack);
|
Zone.current.handleUncaughtError(details.exception, details.stack);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!JournalApp.isInDebugMode) {
|
if (reportCrashes) {
|
||||||
await FlutterCrashlytics().initialize();
|
await FlutterCrashlytics().initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
runZoned<Future<void>>(() async {
|
runZoned<Future<void>>(() async {
|
||||||
await JournalApp.main();
|
await JournalApp.main(pref);
|
||||||
}, onError: (Object error, StackTrace stackTrace) async {
|
}, onError: (Object error, StackTrace stackTrace) async {
|
||||||
print("Uncaught Exception: " + error.toString());
|
print("Uncaught Exception: " + error.toString());
|
||||||
print(stackTrace);
|
print(stackTrace);
|
||||||
|
@ -197,6 +197,34 @@ class SettingsListState extends State<SettingsList> {
|
|||||||
Settings.instance.save();
|
Settings.instance.save();
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
SizedBox(height: 16.0),
|
||||||
|
PreferenceTitle("Analytics"),
|
||||||
|
CheckboxPreference(
|
||||||
|
"Collect Anonymous Usage Statistics",
|
||||||
|
"usage_stats",
|
||||||
|
defaultVal: Settings.instance.collectUsageStatistics,
|
||||||
|
onEnable: () {
|
||||||
|
Settings.instance.collectUsageStatistics = true;
|
||||||
|
Settings.instance.save();
|
||||||
|
},
|
||||||
|
onDisable: () {
|
||||||
|
Settings.instance.collectUsageStatistics = false;
|
||||||
|
Settings.instance.save();
|
||||||
|
},
|
||||||
|
),
|
||||||
|
CheckboxPreference(
|
||||||
|
"Collect Anonymous Crash Reports",
|
||||||
|
"crash_reports",
|
||||||
|
defaultVal: Settings.instance.collectCrashReports,
|
||||||
|
onEnable: () {
|
||||||
|
Settings.instance.collectCrashReports = true;
|
||||||
|
Settings.instance.save();
|
||||||
|
},
|
||||||
|
onDisable: () {
|
||||||
|
Settings.instance.collectCrashReports = false;
|
||||||
|
Settings.instance.save();
|
||||||
|
},
|
||||||
|
),
|
||||||
VersionNumberTile(),
|
VersionNumberTile(),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
@ -24,6 +24,9 @@ class Settings {
|
|||||||
|
|
||||||
NoteViewerFontSize noteViewerFontSize = NoteViewerFontSize.Normal;
|
NoteViewerFontSize noteViewerFontSize = NoteViewerFontSize.Normal;
|
||||||
|
|
||||||
|
bool collectUsageStatistics = true;
|
||||||
|
bool collectCrashReports = true;
|
||||||
|
|
||||||
void load(SharedPreferences pref) {
|
void load(SharedPreferences pref) {
|
||||||
gitAuthor = pref.getString("gitAuthor") ?? gitAuthor;
|
gitAuthor = pref.getString("gitAuthor") ?? gitAuthor;
|
||||||
gitAuthorEmail = pref.getString("gitAuthorEmail") ?? gitAuthorEmail;
|
gitAuthorEmail = pref.getString("gitAuthorEmail") ?? gitAuthorEmail;
|
||||||
@ -36,6 +39,11 @@ class Settings {
|
|||||||
str = pref.getString("noteFileNameFormat") ?? noteFileNameFormat.toString();
|
str = pref.getString("noteFileNameFormat") ?? noteFileNameFormat.toString();
|
||||||
noteFileNameFormat =
|
noteFileNameFormat =
|
||||||
NoteFileNameFormat.values.firstWhere((e) => e.toString() == str);
|
NoteFileNameFormat.values.firstWhere((e) => e.toString() == str);
|
||||||
|
|
||||||
|
collectUsageStatistics =
|
||||||
|
pref.getBool("collectCrashReports") ?? collectUsageStatistics;
|
||||||
|
collectCrashReports =
|
||||||
|
pref.getBool("collectCrashReports") ?? collectCrashReports;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future save() async {
|
Future save() async {
|
||||||
@ -44,6 +52,8 @@ class Settings {
|
|||||||
pref.setString("gitAuthorEmail", gitAuthorEmail);
|
pref.setString("gitAuthorEmail", gitAuthorEmail);
|
||||||
pref.setString("noteViewerFontSize", noteViewerFontSize.toString());
|
pref.setString("noteViewerFontSize", noteViewerFontSize.toString());
|
||||||
pref.setString("noteFileNameFormat", noteFileNameFormat.toString());
|
pref.setString("noteFileNameFormat", noteFileNameFormat.toString());
|
||||||
|
pref.setBool("collectUsageStatistics", collectUsageStatistics);
|
||||||
|
pref.setBool("collectCrashReports", collectCrashReports);
|
||||||
|
|
||||||
// Shouldn't we check if something has actually changed?
|
// Shouldn't we check if something has actually changed?
|
||||||
for (var f in changeObservers) {
|
for (var f in changeObservers) {
|
||||||
|
Reference in New Issue
Block a user