diff --git a/lib/services/manager_api.dart b/lib/services/manager_api.dart index dbd75098..60c44357 100644 --- a/lib/services/manager_api.dart +++ b/lib/services/manager_api.dart @@ -20,8 +20,8 @@ class ManagerAPI { final RootAPI _rootAPI = RootAPI(); final String patcherRepo = 'revanced-patcher'; final String cliRepo = 'revanced-cli'; - late String storedPatchesFile = '/selected-patches.json'; late SharedPreferences _prefs; + String storedPatchesFile = '/selected-patches.json'; String defaultApiUrl = 'https://releases.revanced.app/'; String defaultRepoUrl = 'https://api.github.com'; String defaultPatcherRepo = 'revanced/revanced-patcher'; @@ -424,30 +424,20 @@ class ManagerAPI { } else { patchesMap[app] = patches; } - if (selectedPatchesFile.existsSync()) { - selectedPatchesFile.createSync(recursive: true); - } selectedPatchesFile.writeAsString(jsonEncode(patchesMap)); } Future> getSelectedPatches(String app) async { Map patchesMap = await readSelectedPatchesFile(); - if (patchesMap.isNotEmpty) { - final List patches = - List.from(patchesMap.putIfAbsent(app, () => List.empty())); - return patches; - } - return List.empty(); + return List.from(patchesMap.putIfAbsent(app, () => List.empty())); } Future> readSelectedPatchesFile() async { final File selectedPatchesFile = File(storedPatchesFile); - if (selectedPatchesFile.existsSync()) { - String string = selectedPatchesFile.readAsStringSync(); - if (string.trim().isEmpty) return {}; - return json.decode(string); - } - return {}; + if (!selectedPatchesFile.existsSync()) return {}; + String string = selectedPatchesFile.readAsStringSync(); + if (string.trim().isEmpty) return {}; + return jsonDecode(string); } Future resetLastSelectedPatches() async { diff --git a/lib/ui/views/app_selector/app_selector_viewmodel.dart b/lib/ui/views/app_selector/app_selector_viewmodel.dart index caaa4b31..9b5943a5 100644 --- a/lib/ui/views/app_selector/app_selector_viewmodel.dart +++ b/lib/ui/views/app_selector/app_selector_viewmodel.dart @@ -42,7 +42,6 @@ class AppSelectorViewModel extends BaseViewModel { patchDate: DateTime.now(), ); locator().loadLastSelectedPatches(); - locator().notifyListeners(); } Future selectAppFromStorage(BuildContext context) async { @@ -78,7 +77,6 @@ class AppSelectorViewModel extends BaseViewModel { isFromStorage: true, ); locator().loadLastSelectedPatches(); - locator().notifyListeners(); } } } on Exception catch (e, s) { diff --git a/lib/ui/views/patcher/patcher_viewmodel.dart b/lib/ui/views/patcher/patcher_viewmodel.dart index 1c16ed6c..fa6c4221 100644 --- a/lib/ui/views/patcher/patcher_viewmodel.dart +++ b/lib/ui/views/patcher/patcher_viewmodel.dart @@ -114,8 +114,7 @@ class PatcherViewModel extends BaseViewModel { await _managerAPI.getSelectedPatches(selectedApp!.originalPackageName); List patches = _patcherAPI.getFilteredPatches(selectedApp!.originalPackageName); - this - .selectedPatches + this.selectedPatches .addAll(patches.where((patch) => selectedPatches.contains(patch.name))); notifyListeners(); } diff --git a/lib/ui/views/settings/settings_viewmodel.dart b/lib/ui/views/settings/settings_viewmodel.dart index 53aac65e..416068b6 100644 --- a/lib/ui/views/settings/settings_viewmodel.dart +++ b/lib/ui/views/settings/settings_viewmodel.dart @@ -80,9 +80,9 @@ class SettingsViewModel extends BaseViewModel { await CRFileSaver.saveFileWithDialog(SaveFileDialogParams( sourceFilePath: tempFilePath, destinationFileName: '')); File(tempFilePath).delete(); - locator().showBottom('settingsView.exportedPatches'); + _toast.showBottom('settingsView.exportedPatches'); } else { - locator().showBottom('settingsView.noExportFileFound'); + _toast.showBottom('settingsView.noExportFileFound'); } } on Exception catch (e, s) { Sentry.captureException(e, stackTrace: s); @@ -97,20 +97,16 @@ class SettingsViewModel extends BaseViewModel { ); if (result != null && result.files.single.path != null) { File inFile = File(result.files.single.path!); - final File storedPatchesFile = File(_managerAPI.storedPatchesFile); - if (!storedPatchesFile.existsSync()) { - storedPatchesFile.createSync(recursive: true); - } - inFile.copySync(storedPatchesFile.path); + inFile.copySync(_managerAPI.storedPatchesFile); inFile.delete(); if (locator().selectedApp != null) { locator().loadLastSelectedPatches(); } - locator().showBottom('settingsView.importedPatches'); + _toast.showBottom('settingsView.importedPatches'); } } on Exception catch (e, s) { await Sentry.captureException(e, stackTrace: s); - locator().showBottom('settingsView.jsonSelectorErrorMessage'); + _toast.showBottom('settingsView.jsonSelectorErrorMessage'); } }