mirror of
https://github.com/revanced/revanced-manager.git
synced 2025-06-12 04:37:37 +02:00
refactor: update deprecated and minor code refactors (#710)
Improve code readability & additional refactoring Commits: chore: exclude generated from analyzer refactor: add SharedPreferences to locator refactor: access shared pref from locator, and code refactor refactor: remove unwanted `await` refactor: remove `const` from `CacheConfig`
This commit is contained in:

committed by
EvadeMaster

parent
3ae4d69110
commit
6829d3cdea
@ -88,7 +88,7 @@ class AppSelectorViewModel extends BaseViewModel {
|
||||
}
|
||||
}
|
||||
} on Exception catch (e, s) {
|
||||
await Sentry.captureException(e, stackTrace: s);
|
||||
Sentry.captureException(e, stackTrace: s).ignore();
|
||||
_toast.showBottom('appSelectorView.errorMessage');
|
||||
}
|
||||
}
|
||||
|
@ -96,7 +96,7 @@ class HomeViewModel extends BaseViewModel {
|
||||
int.parse(currentVersion.replaceAll(RegExp('[^0-9]'), ''));
|
||||
return latestVersionInt > currentVersionInt;
|
||||
} on Exception catch (e, s) {
|
||||
await Sentry.captureException(e, stackTrace: s);
|
||||
Sentry.captureException(e, stackTrace: s).ignore();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -138,7 +138,7 @@ class HomeViewModel extends BaseViewModel {
|
||||
_toast.showBottom('homeView.errorDownloadMessage');
|
||||
}
|
||||
} on Exception catch (e, s) {
|
||||
await Sentry.captureException(e, stackTrace: s);
|
||||
Sentry.captureException(e, stackTrace: s).ignore();
|
||||
_toast.showBottom('homeView.errorInstallMessage');
|
||||
}
|
||||
}
|
||||
|
@ -57,7 +57,7 @@ class InstallerViewModel extends BaseViewModel {
|
||||
),
|
||||
).then((value) => FlutterBackground.enableBackgroundExecution());
|
||||
} on Exception catch (e, s) {
|
||||
await Sentry.captureException(e, stackTrace: s);
|
||||
Sentry.captureException(e, stackTrace: s).ignore();
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
@ -131,14 +131,13 @@ class InstallerViewModel extends BaseViewModel {
|
||||
_app.apkFilePath,
|
||||
_patches,
|
||||
);
|
||||
} on Exception catch (e, s) {
|
||||
} on Exception catch (e) {
|
||||
update(
|
||||
-100.0,
|
||||
'Aborting...',
|
||||
'An error occurred! Aborting\nError:\n$e',
|
||||
);
|
||||
await Sentry.captureException(e, stackTrace: s);
|
||||
throw await Sentry.captureException(e, stackTrace: s);
|
||||
rethrow;
|
||||
}
|
||||
} else {
|
||||
update(-100.0, 'Aborting...', 'No app or patches selected! Aborting');
|
||||
@ -146,14 +145,13 @@ class InstallerViewModel extends BaseViewModel {
|
||||
if (FlutterBackground.isBackgroundExecutionEnabled) {
|
||||
try {
|
||||
FlutterBackground.disableBackgroundExecution();
|
||||
} on Exception catch (e, s) {
|
||||
await Sentry.captureException(e, stackTrace: s);
|
||||
// ignore
|
||||
} on Exception {
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
await Wakelock.disable();
|
||||
} on Exception catch (e, s) {
|
||||
await Sentry.captureException(e, stackTrace: s);
|
||||
Sentry.captureException(e, stackTrace: s).ignore();
|
||||
}
|
||||
}
|
||||
|
||||
@ -212,7 +210,7 @@ class InstallerViewModel extends BaseViewModel {
|
||||
}
|
||||
}
|
||||
} on Exception catch (e, s) {
|
||||
await Sentry.captureException(e, stackTrace: s);
|
||||
Sentry.captureException(e, stackTrace: s).ignore();
|
||||
}
|
||||
}
|
||||
|
||||
@ -220,7 +218,7 @@ class InstallerViewModel extends BaseViewModel {
|
||||
try {
|
||||
_patcherAPI.exportPatchedFile(_app.name, _app.version);
|
||||
} on Exception catch (e, s) {
|
||||
Sentry.captureException(e, stackTrace: s);
|
||||
Sentry.captureException(e, stackTrace: s).ignore();
|
||||
}
|
||||
}
|
||||
|
||||
@ -228,7 +226,7 @@ class InstallerViewModel extends BaseViewModel {
|
||||
try {
|
||||
_patcherAPI.sharePatchedFile(_app.name, _app.version);
|
||||
} on Exception catch (e, s) {
|
||||
Sentry.captureException(e, stackTrace: s);
|
||||
Sentry.captureException(e, stackTrace: s).ignore();
|
||||
}
|
||||
}
|
||||
|
||||
@ -243,7 +241,7 @@ class InstallerViewModel extends BaseViewModel {
|
||||
locator<PatcherViewModel>().selectedPatches.clear();
|
||||
locator<PatcherViewModel>().notifyListeners();
|
||||
} on Exception catch (e, s) {
|
||||
await Sentry.captureException(e, stackTrace: s);
|
||||
Sentry.captureException(e, stackTrace: s).ignore();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -15,9 +15,9 @@ import 'package:stacked/stacked.dart';
|
||||
|
||||
@lazySingleton
|
||||
class NavigationViewModel extends IndexTrackingViewModel {
|
||||
final prefs = locator<SharedPreferences>();
|
||||
Future<void> initialize(BuildContext context) async {
|
||||
locator<Toast>().initialize(context);
|
||||
final SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||
if (prefs.getBool('permissionsRequested') == null) {
|
||||
await prefs.setBool('permissionsRequested', true);
|
||||
RootAPI().hasRootPermissions().then(
|
||||
|
@ -3,7 +3,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_i18n/flutter_i18n.dart';
|
||||
import 'package:revanced_manager/app/app.locator.dart';
|
||||
import 'package:revanced_manager/main.dart';
|
||||
import 'package:revanced_manager/services/crowdin_api.dart';
|
||||
import 'package:revanced_manager/services/toast.dart';
|
||||
import 'package:revanced_manager/ui/views/navigation/navigation_viewmodel.dart';
|
||||
@ -17,23 +16,14 @@ final _settingViewModel = SettingsViewModel();
|
||||
|
||||
class SUpdateLanguage extends BaseViewModel {
|
||||
final CrowdinAPI _crowdinAPI = locator<CrowdinAPI>();
|
||||
final SharedPreferences _prefs = locator<SharedPreferences>();
|
||||
final Toast _toast = locator<Toast>();
|
||||
late SharedPreferences _prefs;
|
||||
String selectedLanguage = 'English';
|
||||
String selectedLanguageLocale = prefs.getString('language') ?? 'en_US';
|
||||
String get selectedLanguageLocale => _prefs.getString('language') ?? 'en_US';
|
||||
List languages = [];
|
||||
|
||||
Future<void> initialize() async {
|
||||
_prefs = await SharedPreferences.getInstance();
|
||||
selectedLanguageLocale =
|
||||
_prefs.getString('language') ?? selectedLanguageLocale;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<void> updateLanguage(BuildContext context, String? value) async {
|
||||
if (value != null) {
|
||||
selectedLanguageLocale = value;
|
||||
_prefs = await SharedPreferences.getInstance();
|
||||
await _prefs.setString('language', value);
|
||||
await FlutterI18n.refresh(context, Locale(value));
|
||||
timeago.setLocaleMessages(value, timeago.EnMessages());
|
||||
|
@ -1,4 +1,5 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:cr_file_saver/file_saver.dart';
|
||||
import 'package:device_info_plus/device_info_plus.dart';
|
||||
import 'package:file_picker/file_picker.dart';
|
||||
@ -74,14 +75,18 @@ class SettingsViewModel extends BaseViewModel {
|
||||
if (outFile.existsSync()) {
|
||||
final String dateTime =
|
||||
DateTime.now().toString().replaceAll(' ', '_').split('.').first;
|
||||
await CRFileSaver.saveFileWithDialog(SaveFileDialogParams(
|
||||
sourceFilePath: outFile.path, destinationFileName: 'selected_patches_$dateTime.json',),);
|
||||
await CRFileSaver.saveFileWithDialog(
|
||||
SaveFileDialogParams(
|
||||
sourceFilePath: outFile.path,
|
||||
destinationFileName: 'selected_patches_$dateTime.json',
|
||||
),
|
||||
);
|
||||
_toast.showBottom('settingsView.exportedPatches');
|
||||
} else {
|
||||
_toast.showBottom('settingsView.noExportFileFound');
|
||||
}
|
||||
} on Exception catch (e, s) {
|
||||
Sentry.captureException(e, stackTrace: s);
|
||||
Sentry.captureException(e, stackTrace: s).ignore();
|
||||
}
|
||||
}
|
||||
|
||||
@ -101,7 +106,7 @@ class SettingsViewModel extends BaseViewModel {
|
||||
_toast.showBottom('settingsView.importedPatches');
|
||||
}
|
||||
} on Exception catch (e, s) {
|
||||
await Sentry.captureException(e, stackTrace: s);
|
||||
Sentry.captureException(e, stackTrace: s).ignore();
|
||||
_toast.showBottom('settingsView.jsonSelectorErrorMessage');
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user