feat: Show changelogs from the latest to the last used patches version (#2219)

This commit is contained in:
aAbed 2024-10-21 16:02:23 +05:45 committed by GitHub
parent bd96701103
commit daba737ecb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 54 additions and 23 deletions

View File

@ -49,18 +49,24 @@ class GithubAPI {
} }
} }
Future<String?> getManagerChangelogs() async { Future<String?> getChangelogs(bool isPatches) async {
final String repoName = isPatches
? _managerAPI.getPatchesRepo()
: _managerAPI.defaultManagerRepo;
try { try {
final response = await _dioGetSynchronously( final response = await _dioGetSynchronously(
'/repos/${_managerAPI.defaultManagerRepo}/releases?per_page=50', '/repos/$repoName/releases?per_page=50',
); );
final buffer = StringBuffer(); final buffer = StringBuffer();
final String currentVersion = final String version = isPatches
await _managerAPI.getCurrentManagerVersion(); ? _managerAPI.getLastUsedPatchesVersion()
: await _managerAPI.getCurrentManagerVersion();
int releases = 0;
for (final release in response.data) { for (final release in response.data) {
if (release['tag_name'] == currentVersion) { if (release['tag_name'] == version) {
if (buffer.isEmpty) { if (buffer.isEmpty) {
buffer.writeln(release['body']); buffer.writeln(release['body']);
releases++;
} }
break; break;
} }
@ -68,6 +74,10 @@ class GithubAPI {
continue; continue;
} }
buffer.writeln(release['body']); buffer.writeln(release['body']);
releases++;
if (isPatches && releases == 10) {
break;
}
} }
return buffer.toString(); return buffer.toString();
} on Exception catch (e) { } on Exception catch (e) {

View File

@ -367,7 +367,8 @@ class ManagerAPI {
) async { ) async {
deleteLastPatchedApp(); deleteLastPatchedApp();
final Directory appCache = await getApplicationSupportDirectory(); 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(); app.fileSize = outFile.lengthSync();
await _prefs.setString( await _prefs.setString(
'lastPatchedApp', 'lastPatchedApp',
@ -511,8 +512,7 @@ class ManagerAPI {
defaultPatchesRepo, defaultPatchesRepo,
); );
} else { } else {
final release = final release = await _githubAPI.getLatestRelease(getPatchesRepo());
await _githubAPI.getLatestRelease(getPatchesRepo());
if (release != null) { if (release != null) {
final DateTime timestamp = final DateTime timestamp =
DateTime.parse(release['created_at'] as String); DateTime.parse(release['created_at'] as String);
@ -560,8 +560,7 @@ class ManagerAPI {
defaultPatchesRepo, defaultPatchesRepo,
); );
} else { } else {
final release = final release = await _githubAPI.getLatestRelease(getPatchesRepo());
await _githubAPI.getLatestRelease(getPatchesRepo());
if (release != null) { if (release != null) {
return release['tag_name']; return release['tag_name'];
} else { } else {
@ -570,6 +569,30 @@ class ManagerAPI {
} }
} }
String getLastUsedPatchesVersion() {
final String lastPatchesVersions =
_prefs.getString('lastUsedPatchesVersion') ?? '{}';
final Map<String, dynamic> 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<String, dynamic> lastPatchesVersionMap =
jsonDecode(lastPatchesVersions);
final repo = getPatchesRepo();
final String lastPatchesVersion =
version ?? lastPatchesVersionMap[repo] ?? '0.0.0';
lastPatchesVersionMap[repo] = lastPatchesVersion;
_prefs.setString(
'lastUsedPatchesVersion',
jsonEncode(lastPatchesVersionMap),
);
}
Future<String> getCurrentManagerVersion() async { Future<String> getCurrentManagerVersion() async {
final PackageInfo packageInfo = await PackageInfo.fromPlatform(); final PackageInfo packageInfo = await PackageInfo.fromPlatform();
String version = packageInfo.version; String version = packageInfo.version;

View File

@ -478,14 +478,8 @@ class HomeViewModel extends BaseViewModel {
); );
} }
Future<String?> getManagerChangelogs() { Future<String?> getChangelogs(bool isPatches) {
return _githubAPI.getManagerChangelogs(); return _githubAPI.getChangelogs(isPatches);
}
Future<String?> getLatestPatchesChangelog() async {
final release =
await _githubAPI.getLatestRelease(_managerAPI.getPatchesRepo());
return release?['body'];
} }
Future<String?> getLatestPatchesReleaseTime() { Future<String?> getLatestPatchesReleaseTime() {

View File

@ -159,6 +159,9 @@ class InstallerViewModel extends BaseViewModel {
_app.packageName, _app.packageName,
); );
await _managerAPI.setUsedPatches(_patches, _app.packageName); await _managerAPI.setUsedPatches(_patches, _app.packageName);
_managerAPI.setLastUsedPatchesVersion(
version: _managerAPI.patchesVersion,
);
} else if (value == -100.0) { } else if (value == -100.0) {
isPatching = false; isPatching = false;
hasErrors = true; hasErrors = true;
@ -197,7 +200,9 @@ class InstallerViewModel extends BaseViewModel {
_app.patchedFilePath = _patcherAPI.outFile!.path; _app.patchedFilePath = _patcherAPI.outFile!.path;
} }
final homeViewModel = locator<HomeViewModel>(); final homeViewModel = locator<HomeViewModel>();
_managerAPI.reAssessPatchedApps().then((_) => homeViewModel.getPatchedApps()); _managerAPI
.reAssessPatchedApps()
.then((_) => homeViewModel.getPatchedApps());
} on Exception catch (e) { } on Exception catch (e) {
update( update(
-100.0, -100.0,

View File

@ -129,6 +129,7 @@ class SManageSources extends BaseViewModel {
); );
_managerAPI.setCurrentPatchesVersion('0.0.0'); _managerAPI.setCurrentPatchesVersion('0.0.0');
_managerAPI.setCurrentIntegrationsVersion('0.0.0'); _managerAPI.setCurrentIntegrationsVersion('0.0.0');
_managerAPI.setLastUsedPatchesVersion();
_toast.showBottom(t.settingsView.restartAppForChanges); _toast.showBottom(t.settingsView.restartAppForChanges);
Navigator.of(context).pop(); Navigator.of(context).pop();
}, },

View File

@ -57,6 +57,7 @@ class SettingsViewModel extends BaseViewModel {
_managerAPI.useAlternativeSources(value); _managerAPI.useAlternativeSources(value);
_managerAPI.setCurrentPatchesVersion('0.0.0'); _managerAPI.setCurrentPatchesVersion('0.0.0');
_managerAPI.setCurrentIntegrationsVersion('0.0.0'); _managerAPI.setCurrentIntegrationsVersion('0.0.0');
_managerAPI.setLastUsedPatchesVersion();
notifyListeners(); notifyListeners();
} }

View File

@ -105,9 +105,7 @@ class UpdateConfirmationSheet extends StatelessWidget {
), ),
), ),
FutureBuilder<String?>( FutureBuilder<String?>(
future: !isPatches future: model.getChangelogs(isPatches),
? model.getManagerChangelogs()
: model.getLatestPatchesChangelog(),
builder: (_, snapshot) { builder: (_, snapshot) {
if (!snapshot.hasData) { if (!snapshot.hasData) {
return Padding( return Padding(
@ -117,7 +115,6 @@ class UpdateConfirmationSheet extends StatelessWidget {
), ),
); );
} }
return Container( return Container(
margin: const EdgeInsets.symmetric(horizontal: 24.0), margin: const EdgeInsets.symmetric(horizontal: 24.0),
decoration: BoxDecoration( decoration: BoxDecoration(