From a22c58bab48abdcd835e5666e0f1a76c1a9f50bf Mon Sep 17 00:00:00 2001 From: aAbed Date: Sat, 21 Sep 2024 21:13:42 +0545 Subject: [PATCH 1/2] feat: Show changelogs from the latest to the last used patches version --- lib/services/github_api.dart | 20 ++++++++++++++----- lib/services/manager_api.dart | 8 ++++++++ lib/ui/views/home/home_viewmodel.dart | 10 ++-------- .../views/installer/installer_viewmodel.dart | 1 + .../homeView/update_confirmation_sheet.dart | 5 +---- 5 files changed, 27 insertions(+), 17 deletions(-) diff --git a/lib/services/github_api.dart b/lib/services/github_api.dart index b4ab03a669..ed8d3be5d6 100644 --- a/lib/services/github_api.dart +++ b/lib/services/github_api.dart @@ -49,18 +49,24 @@ class GithubAPI { } } - Future getManagerChangelogs() async { + Future getChangelogs(bool isPatches) async { + final String repoName = isPatches + ? _managerAPI.getPatchesRepo() + : _managerAPI.defaultManagerRepo; try { final response = await _dioGetSynchronously( - '/repos/${_managerAPI.defaultManagerRepo}/releases?per_page=50', + '/repos/$repoName/releases?per_page=50', ); final buffer = StringBuffer(); - final String currentVersion = - await _managerAPI.getCurrentManagerVersion(); + final String version = isPatches + ? _managerAPI.getLastUsedPatchesVersion() + : await _managerAPI.getCurrentManagerVersion(); + int releases = 0; for (final release in response.data) { - if (release['tag_name'] == currentVersion) { + if (release['tag_name'] == version) { if (buffer.isEmpty) { buffer.writeln(release['body']); + releases++; } break; } @@ -68,6 +74,10 @@ class GithubAPI { continue; } buffer.writeln(release['body']); + releases++; + if (isPatches && releases == 10) { + break; + } } return buffer.toString(); } on Exception catch (e) { diff --git a/lib/services/manager_api.dart b/lib/services/manager_api.dart index 68144df68d..4d02f0c0f4 100644 --- a/lib/services/manager_api.dart +++ b/lib/services/manager_api.dart @@ -570,6 +570,14 @@ class ManagerAPI { } } + String getLastUsedPatchesVersion() { + return _prefs.getString('lastUsedPatchesVersion') ?? '0.0.0'; + } + + void setLastUsedPatchesVersion(String version) { + _prefs.setString('lastUsedPatchesVersion', version); + } + Future getCurrentManagerVersion() async { final PackageInfo packageInfo = await PackageInfo.fromPlatform(); String version = packageInfo.version; diff --git a/lib/ui/views/home/home_viewmodel.dart b/lib/ui/views/home/home_viewmodel.dart index 2ce7cf5b28..8271f96b71 100644 --- a/lib/ui/views/home/home_viewmodel.dart +++ b/lib/ui/views/home/home_viewmodel.dart @@ -478,14 +478,8 @@ class HomeViewModel extends BaseViewModel { ); } - Future getManagerChangelogs() { - return _githubAPI.getManagerChangelogs(); - } - - Future getLatestPatchesChangelog() async { - final release = - await _githubAPI.getLatestRelease(_managerAPI.getPatchesRepo()); - return release?['body']; + Future getChangelogs(bool isPatches) { + return _githubAPI.getChangelogs(isPatches); } Future getLatestPatchesReleaseTime() { diff --git a/lib/ui/views/installer/installer_viewmodel.dart b/lib/ui/views/installer/installer_viewmodel.dart index 84276e54c0..74b0dbd231 100644 --- a/lib/ui/views/installer/installer_viewmodel.dart +++ b/lib/ui/views/installer/installer_viewmodel.dart @@ -159,6 +159,7 @@ class InstallerViewModel extends BaseViewModel { _app.packageName, ); await _managerAPI.setUsedPatches(_patches, _app.packageName); + _managerAPI.setLastUsedPatchesVersion(_managerAPI.patchesVersion!); } else if (value == -100.0) { isPatching = false; hasErrors = true; diff --git a/lib/ui/widgets/homeView/update_confirmation_sheet.dart b/lib/ui/widgets/homeView/update_confirmation_sheet.dart index 21f37c247f..ecc06cb9ff 100644 --- a/lib/ui/widgets/homeView/update_confirmation_sheet.dart +++ b/lib/ui/widgets/homeView/update_confirmation_sheet.dart @@ -105,9 +105,7 @@ class UpdateConfirmationSheet extends StatelessWidget { ), ), FutureBuilder( - future: !isPatches - ? model.getManagerChangelogs() - : model.getLatestPatchesChangelog(), + future: model.getChangelogs(isPatches), builder: (_, snapshot) { if (!snapshot.hasData) { return Padding( @@ -117,7 +115,6 @@ class UpdateConfirmationSheet extends StatelessWidget { ), ); } - return Container( margin: const EdgeInsets.symmetric(horizontal: 24.0), decoration: BoxDecoration( From 5806cdf0ec06887a236168e862031575075612c8 Mon Sep 17 00:00:00 2001 From: aAbed Date: Sat, 21 Sep 2024 22:17:44 +0545 Subject: [PATCH 2/2] feat: Save last used patches version along with their sources --- lib/services/manager_api.dart | 35 +++++++++++++------ .../views/installer/installer_viewmodel.dart | 8 +++-- .../settings_manage_sources.dart | 1 + lib/ui/views/settings/settings_viewmodel.dart | 1 + 4 files changed, 33 insertions(+), 12 deletions(-) diff --git a/lib/services/manager_api.dart b/lib/services/manager_api.dart index 4d02f0c0f4..3875d333ff 100644 --- a/lib/services/manager_api.dart +++ b/lib/services/manager_api.dart @@ -367,7 +367,8 @@ class ManagerAPI { ) async { deleteLastPatchedApp(); final Directory appCache = await getApplicationSupportDirectory(); - app.patchedFilePath = outFile.copySync('${appCache.path}/lastPatchedApp.apk').path; + app.patchedFilePath = + outFile.copySync('${appCache.path}/lastPatchedApp.apk').path; app.fileSize = outFile.lengthSync(); await _prefs.setString( 'lastPatchedApp', @@ -511,8 +512,7 @@ class ManagerAPI { defaultPatchesRepo, ); } else { - final release = - await _githubAPI.getLatestRelease(getPatchesRepo()); + final release = await _githubAPI.getLatestRelease(getPatchesRepo()); if (release != null) { final DateTime timestamp = DateTime.parse(release['created_at'] as String); @@ -560,8 +560,7 @@ class ManagerAPI { defaultPatchesRepo, ); } else { - final release = - await _githubAPI.getLatestRelease(getPatchesRepo()); + final release = await _githubAPI.getLatestRelease(getPatchesRepo()); if (release != null) { return release['tag_name']; } else { @@ -571,11 +570,27 @@ class ManagerAPI { } String getLastUsedPatchesVersion() { - return _prefs.getString('lastUsedPatchesVersion') ?? '0.0.0'; - } - - void setLastUsedPatchesVersion(String version) { - _prefs.setString('lastUsedPatchesVersion', version); + final String lastPatchesVersions = + _prefs.getString('lastUsedPatchesVersion') ?? '{}'; + final Map lastPatchesVersionMap = + jsonDecode(lastPatchesVersions); + final String repo = getPatchesRepo(); + return lastPatchesVersionMap[repo] ?? '0.0.0'; + } + + void setLastUsedPatchesVersion({String? version}) { + final String lastPatchesVersions = + _prefs.getString('lastUsedPatchesVersion') ?? '{}'; + final Map lastPatchesVersionMap = + jsonDecode(lastPatchesVersions); + final repo = getPatchesRepo(); + final String lastPatchesVersion = + version ?? lastPatchesVersionMap[repo] ?? '0.0.0'; + lastPatchesVersionMap[repo] = lastPatchesVersion; + _prefs.setString( + 'lastUsedPatchesVersion', + jsonEncode(lastPatchesVersionMap), + ); } Future getCurrentManagerVersion() async { diff --git a/lib/ui/views/installer/installer_viewmodel.dart b/lib/ui/views/installer/installer_viewmodel.dart index 74b0dbd231..2bc9fb5b29 100644 --- a/lib/ui/views/installer/installer_viewmodel.dart +++ b/lib/ui/views/installer/installer_viewmodel.dart @@ -159,7 +159,9 @@ class InstallerViewModel extends BaseViewModel { _app.packageName, ); await _managerAPI.setUsedPatches(_patches, _app.packageName); - _managerAPI.setLastUsedPatchesVersion(_managerAPI.patchesVersion!); + _managerAPI.setLastUsedPatchesVersion( + version: _managerAPI.patchesVersion, + ); } else if (value == -100.0) { isPatching = false; hasErrors = true; @@ -198,7 +200,9 @@ class InstallerViewModel extends BaseViewModel { _app.patchedFilePath = _patcherAPI.outFile!.path; } final homeViewModel = locator(); - _managerAPI.reAssessPatchedApps().then((_) => homeViewModel.getPatchedApps()); + _managerAPI + .reAssessPatchedApps() + .then((_) => homeViewModel.getPatchedApps()); } on Exception catch (e) { update( -100.0, diff --git a/lib/ui/views/settings/settingsFragment/settings_manage_sources.dart b/lib/ui/views/settings/settingsFragment/settings_manage_sources.dart index 514e77b6e7..2a7b2d4e43 100644 --- a/lib/ui/views/settings/settingsFragment/settings_manage_sources.dart +++ b/lib/ui/views/settings/settingsFragment/settings_manage_sources.dart @@ -129,6 +129,7 @@ class SManageSources extends BaseViewModel { ); _managerAPI.setCurrentPatchesVersion('0.0.0'); _managerAPI.setCurrentIntegrationsVersion('0.0.0'); + _managerAPI.setLastUsedPatchesVersion(); _toast.showBottom(t.settingsView.restartAppForChanges); Navigator.of(context).pop(); }, diff --git a/lib/ui/views/settings/settings_viewmodel.dart b/lib/ui/views/settings/settings_viewmodel.dart index 1323aaacba..c940f7fcae 100644 --- a/lib/ui/views/settings/settings_viewmodel.dart +++ b/lib/ui/views/settings/settings_viewmodel.dart @@ -57,6 +57,7 @@ class SettingsViewModel extends BaseViewModel { _managerAPI.useAlternativeSources(value); _managerAPI.setCurrentPatchesVersion('0.0.0'); _managerAPI.setCurrentIntegrationsVersion('0.0.0'); + _managerAPI.setLastUsedPatchesVersion(); notifyListeners(); }