mirror of
https://github.com/revanced/revanced-manager.git
synced 2025-06-13 04:57:37 +02:00
feat: get changelog from app's specific github path (ugly)
This commit is contained in:
@ -6,6 +6,16 @@ import 'package:timeago/timeago.dart';
|
||||
class GithubAPI {
|
||||
final GitHub _github = GitHub();
|
||||
|
||||
final Map<String, String> repoAppPath = {
|
||||
'com.google.android.youtube': 'youtube',
|
||||
'com.google.android.apps.youtube.music': 'music',
|
||||
'com.twitter.android': 'twitter',
|
||||
'com.reddit.frontpage': 'reddit',
|
||||
'com.zhiliaoapp.musically': 'tiktok',
|
||||
'de.dwd.warnapp': 'warnwetter',
|
||||
'com.garzotto.pflotsh.ecmwf_a': 'ecmwf',
|
||||
};
|
||||
|
||||
Future<String?> latestReleaseVersion(String org, String repoName) async {
|
||||
try {
|
||||
var latestRelease = await _github.repositories.getLatestRelease(
|
||||
@ -61,9 +71,19 @@ class GithubAPI {
|
||||
)).toList();
|
||||
}
|
||||
|
||||
Future<List<RepositoryCommit>> getCommits(String org, String repoName) async {
|
||||
return await (_github.repositories.listCommits(
|
||||
RepositorySlug(org, repoName),
|
||||
Future<List<RepositoryCommit>> getCommits(
|
||||
String packageName,
|
||||
String org,
|
||||
String repoName,
|
||||
) async {
|
||||
String path =
|
||||
'src/main/kotlin/app/revanced/patches/${repoAppPath[packageName]}';
|
||||
return await (PaginationHelper(_github)
|
||||
.objects<Map<String, dynamic>, RepositoryCommit>(
|
||||
'GET',
|
||||
'/repos/$org/$repoName/commits',
|
||||
(i) => RepositoryCommit.fromJson(i),
|
||||
params: <String, dynamic>{'path': path},
|
||||
)).toList();
|
||||
}
|
||||
}
|
||||
|
@ -15,11 +15,9 @@ class ManagerAPI {
|
||||
final GithubAPI _githubAPI = GithubAPI();
|
||||
final RootAPI _rootAPI = RootAPI();
|
||||
late SharedPreferences _prefs;
|
||||
late List<RepositoryCommit> _commits = [];
|
||||
|
||||
Future<void> initialize() async {
|
||||
_prefs = await SharedPreferences.getInstance();
|
||||
_commits = (await _githubAPI.getCommits(ghOrg, patchesRepo)).toList();
|
||||
}
|
||||
|
||||
Future<File?> downloadPatches(String extension) async {
|
||||
@ -62,16 +60,16 @@ class ManagerAPI {
|
||||
.toList();
|
||||
}
|
||||
|
||||
void setPatchedApps(List<PatchedApplication> patchedApps) {
|
||||
_prefs.setStringList('patchedApps',
|
||||
Future<void> setPatchedApps(List<PatchedApplication> patchedApps) async {
|
||||
await _prefs.setStringList('patchedApps',
|
||||
patchedApps.map((a) => json.encode(a.toJson())).toList());
|
||||
}
|
||||
|
||||
void savePatchedApp(PatchedApplication app) {
|
||||
Future<void> savePatchedApp(PatchedApplication app) async {
|
||||
List<PatchedApplication> patchedApps = getPatchedApps();
|
||||
patchedApps.removeWhere((a) => a.packageName == app.packageName);
|
||||
patchedApps.add(app);
|
||||
setPatchedApps(patchedApps);
|
||||
await setPatchedApps(patchedApps);
|
||||
}
|
||||
|
||||
Future<void> reAssessSavedApps() async {
|
||||
@ -83,20 +81,12 @@ class ManagerAPI {
|
||||
if (isRemove) {
|
||||
toRemove.add(app);
|
||||
} else {
|
||||
List<String> newChangelog = getAppChangelog(
|
||||
app.packageName,
|
||||
app.patchDate,
|
||||
);
|
||||
if (newChangelog.isNotEmpty) {
|
||||
app.changelog = newChangelog;
|
||||
app.hasUpdates = true;
|
||||
} else {
|
||||
app.hasUpdates = false;
|
||||
}
|
||||
app.hasUpdates = await hasAppUpdates(app.packageName, app.patchDate);
|
||||
app.changelog = await getAppChangelog(app.packageName, app.patchDate);
|
||||
}
|
||||
}
|
||||
patchedApps.removeWhere((a) => toRemove.contains(a));
|
||||
setPatchedApps(patchedApps);
|
||||
await setPatchedApps(patchedApps);
|
||||
}
|
||||
|
||||
Future<bool> isAppUninstalled(PatchedApplication app, bool isRoot) async {
|
||||
@ -108,24 +98,38 @@ class ManagerAPI {
|
||||
return !existsRoot && !existsNonRoot;
|
||||
}
|
||||
|
||||
List<String> getAppChangelog(String packageName, DateTime patchedDate) {
|
||||
List<String> newCommits = _commits
|
||||
Future<bool> hasAppUpdates(String packageName, DateTime patchDate) async {
|
||||
List<RepositoryCommit> commits =
|
||||
await _githubAPI.getCommits(packageName, ghOrg, patchesRepo);
|
||||
return commits.any((c) =>
|
||||
c.commit != null &&
|
||||
c.commit!.author != null &&
|
||||
c.commit!.author!.date != null &&
|
||||
c.commit!.author!.date!.isAfter(patchDate));
|
||||
}
|
||||
|
||||
Future<List<String>> getAppChangelog(
|
||||
String packageName,
|
||||
DateTime patchDate,
|
||||
) async {
|
||||
List<RepositoryCommit> commits =
|
||||
await _githubAPI.getCommits(packageName, ghOrg, patchesRepo);
|
||||
List<String> newCommits = commits
|
||||
.where((c) =>
|
||||
c.commit != null &&
|
||||
c.commit!.message != null &&
|
||||
c.commit!.author != null &&
|
||||
c.commit!.author!.date != null &&
|
||||
c.commit!.author!.date!.isAfter(patchedDate))
|
||||
c.commit!.author!.date!.isAfter(patchDate) &&
|
||||
c.commit!.message != null)
|
||||
.map((c) => c.commit!.message!)
|
||||
.toList();
|
||||
if (newCommits.isNotEmpty) {
|
||||
int firstChore = newCommits.indexWhere((c) => c.startsWith('chore'));
|
||||
int secondChore =
|
||||
newCommits.indexWhere((c) => c.startsWith('chore'), firstChore + 1);
|
||||
if (firstChore >= 0 && secondChore > firstChore) {
|
||||
return newCommits.sublist(firstChore + 1, secondChore);
|
||||
}
|
||||
if (newCommits.isEmpty) {
|
||||
newCommits = commits
|
||||
.where((c) => c.commit != null && c.commit!.message != null)
|
||||
.take(3)
|
||||
.map((c) => c.commit!.message!)
|
||||
.toList();
|
||||
}
|
||||
return List.empty();
|
||||
return newCommits;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user