Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions lib/services/github_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,25 +49,35 @@ class GithubAPI {
}
}

Future<String?> getManagerChangelogs() async {
Future<String?> 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;
}
if (release['prerelease']) {
continue;
}
buffer.writeln(release['body']);
releases++;
if (isPatches && releases == 10) {
break;
}
}
return buffer.toString();
} on Exception catch (e) {
Expand Down
33 changes: 28 additions & 5 deletions lib/services/manager_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
final PackageInfo packageInfo = await PackageInfo.fromPlatform();
String version = packageInfo.version;
Expand Down
10 changes: 2 additions & 8 deletions lib/ui/views/home/home_viewmodel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -478,14 +478,8 @@ class HomeViewModel extends BaseViewModel {
);
}

Future<String?> getManagerChangelogs() {
return _githubAPI.getManagerChangelogs();
}

Future<String?> getLatestPatchesChangelog() async {
final release =
await _githubAPI.getLatestRelease(_managerAPI.getPatchesRepo());
return release?['body'];
Future<String?> getChangelogs(bool isPatches) {
return _githubAPI.getChangelogs(isPatches);
}

Future<String?> getLatestPatchesReleaseTime() {
Expand Down
7 changes: 6 additions & 1 deletion lib/ui/views/installer/installer_viewmodel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,9 @@ class InstallerViewModel extends BaseViewModel {
_app.packageName,
);
await _managerAPI.setUsedPatches(_patches, _app.packageName);
_managerAPI.setLastUsedPatchesVersion(
version: _managerAPI.patchesVersion,
);
} else if (value == -100.0) {
isPatching = false;
hasErrors = true;
Expand Down Expand Up @@ -197,7 +200,9 @@ class InstallerViewModel extends BaseViewModel {
_app.patchedFilePath = _patcherAPI.outFile!.path;
}
final homeViewModel = locator<HomeViewModel>();
_managerAPI.reAssessPatchedApps().then((_) => homeViewModel.getPatchedApps());
_managerAPI
.reAssessPatchedApps()
.then((_) => homeViewModel.getPatchedApps());
} on Exception catch (e) {
update(
-100.0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
},
Expand Down
1 change: 1 addition & 0 deletions lib/ui/views/settings/settings_viewmodel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class SettingsViewModel extends BaseViewModel {
_managerAPI.useAlternativeSources(value);
_managerAPI.setCurrentPatchesVersion('0.0.0');
_managerAPI.setCurrentIntegrationsVersion('0.0.0');
_managerAPI.setLastUsedPatchesVersion();
notifyListeners();
}

Expand Down
5 changes: 1 addition & 4 deletions lib/ui/widgets/homeView/update_confirmation_sheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,7 @@ class UpdateConfirmationSheet extends StatelessWidget {
),
),
FutureBuilder<String?>(
future: !isPatches
? model.getManagerChangelogs()
: model.getLatestPatchesChangelog(),
future: model.getChangelogs(isPatches),
builder: (_, snapshot) {
if (!snapshot.hasData) {
return Padding(
Expand All @@ -117,7 +115,6 @@ class UpdateConfirmationSheet extends StatelessWidget {
),
);
}

return Container(
margin: const EdgeInsets.symmetric(horizontal: 24.0),
decoration: BoxDecoration(
Expand Down