feat: make sentry logging optional.

This commit is contained in:
Aunali321 2022-10-15 01:52:10 +05:30
parent f1261398e9
commit 6d35c47b6b
6 changed files with 74 additions and 3 deletions

View File

@ -106,6 +106,7 @@
"teamSectionTitle": "Team",
"infoSectionTitle": "Info",
"advancedSectionTitle": "Advanced",
"privacySectionTitle": "Privacy",
"darkThemeLabel": "Dark Mode",
"darkThemeHint": "Welcome to the Dark Side",
"dynamicThemeLabel": "Material You",
@ -130,7 +131,10 @@
"apiURLHint": "Configure your custom API URL",
"selectApiURL": "Select URL",
"aboutLabel": "About",
"snackbarMessage": "Copied to clipboard"
"snackbarMessage": "Copied to clipboard",
"sentryLabel": "Sentry Logging",
"sentryHint": "Send anonymous logs to help us improve ReVanced Manager",
"restartAppForChanges": "Restart the app to apply changes"
},
"appInfoView": {
"widgetTitle": "App Info",

View File

@ -20,19 +20,30 @@ Future main() async {
await locator<ManagerAPI>().initialize();
String apiUrl = locator<ManagerAPI>().getApiUrl();
await locator<RevancedAPI>().initialize(apiUrl);
bool isSentryEnabled = locator<ManagerAPI>().isSentryEnabled();
locator<GithubAPI>().initialize();
await locator<PatcherAPI>().initialize();
tz.initializeTimeZones();
await SentryFlutter.init(
(options) {
options
..dsn = Env.SENTRY_DSN
..dsn = isSentryEnabled ? Env.SENTRY_DSN : ''
..environment = 'alpha'
..release = '0.1'
..tracesSampleRate = 1.0
..anrEnabled = true
..enableOutOfMemoryTracking = true
..sampleRate = 1.0;
..sampleRate = isSentryEnabled ? 1.0 : 0.0
..beforeSend = (event, hint) {
print('isSentryEnabled: $isSentryEnabled');
if (isSentryEnabled) {
print("Sentry event sent");
return event;
} else {
print("Sentry is disabled");
return null;
}
} as BeforeSendCallback?;
},
appRunner: () => runApp(const MyApp()),
);

View File

@ -82,6 +82,15 @@ class ManagerAPI {
await _prefs.setBool('useDarkTheme', value);
}
bool isSentryEnabled() {
return _prefs.getBool('sentryEnabled') ?? true;
}
Future<void> setSentryStatus(bool value) async {
await _prefs.setBool('sentryEnabled', value);
print('Sentry status: $value');
}
List<PatchedApplication> getPatchedApps() {
List<String> apps = _prefs.getStringList('patchedApps') ?? [];
return apps.map((a) => PatchedApplication.fromJson(jsonDecode(a))).toList();

View File

@ -20,4 +20,15 @@ class Toast {
gravity: t.ToastGravity.CENTER,
);
}
void showBottom(String text) {
t.Fluttertoast.showToast(
msg: FlutterI18n.translate(
_fToast.context!,
text,
),
toastLength: t.Toast.LENGTH_LONG,
gravity: t.ToastGravity.BOTTOM,
);
}
}

View File

@ -139,6 +139,28 @@ class SettingsView extends StatelessWidget {
],
),
_settingsDivider,
SettingsSection(
title: 'settingsView.privacySectionTitle',
children: <Widget>[
CustomSwitchTile(
padding: const EdgeInsets.symmetric(horizontal: 20.0),
title: I18nText(
'settingsView.sentryLabel',
child: const Text(
'',
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.w500,
),
),
),
subtitle: I18nText('settingsView.sentryHint'),
value: model.isSentryEnabled(),
onTap: (value) => model.useSentry(value),
),
],
),
_settingsDivider,
SettingsSection(
title: 'settingsView.infoSectionTitle',
children: <Widget>[

View File

@ -10,6 +10,7 @@ import 'package:path_provider/path_provider.dart';
import 'package:revanced_manager/app/app.locator.dart';
import 'package:revanced_manager/app/app.router.dart';
import 'package:revanced_manager/services/manager_api.dart';
import 'package:revanced_manager/services/toast.dart';
import 'package:revanced_manager/ui/widgets/shared/custom_material_button.dart';
import 'package:revanced_manager/ui/widgets/settingsView/custom_text_field.dart';
import 'package:share_extend/share_extend.dart';
@ -23,6 +24,7 @@ const int ANDROID_12_SDK_VERSION = 31;
class SettingsViewModel extends BaseViewModel {
final NavigationService _navigationService = locator<NavigationService>();
final ManagerAPI _managerAPI = locator<ManagerAPI>();
final Toast _toast = locator<Toast>();
final TextEditingController _orgPatSourceController = TextEditingController();
final TextEditingController _patSourceController = TextEditingController();
final TextEditingController _orgIntSourceController = TextEditingController();
@ -313,6 +315,18 @@ class SettingsViewModel extends BaseViewModel {
);
}
// disable sentry using switch boolean
bool isSentryEnabled() {
return _managerAPI.isSentryEnabled();
}
void useSentry(bool value) {
_managerAPI.setSentryStatus(value);
_toast.showBottom('settingsView.restartAppForChanges');
notifyListeners();
}
Future<int> getSdkVersion() async {
AndroidDeviceInfo info = await DeviceInfoPlugin().androidInfo;
return info.version.sdkInt ?? -1;