mirror of
https://github.com/ReVanced/revanced-manager.git
synced 2024-11-10 01:01:56 +01:00
feat: use github to get latest patches version if custom sources are used.
This commit is contained in:
parent
6e05120aa5
commit
b0c4567cb8
2 changed files with 28 additions and 3 deletions
|
@ -130,4 +130,18 @@ class GithubAPI {
|
|||
}
|
||||
return patches;
|
||||
}
|
||||
|
||||
Future<String> getLastestReleaseVersion(String repoName) async {
|
||||
try {
|
||||
Map<String, dynamic>? release = await _getLatestRelease(repoName);
|
||||
if (release != null) {
|
||||
return release['tag_name'];
|
||||
} else {
|
||||
return 'Unknown';
|
||||
}
|
||||
} on Exception catch (e, s) {
|
||||
await Sentry.captureException(e, stackTrace: s);
|
||||
return '';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ import 'package:flutter_i18n/widgets/I18nText.dart';
|
|||
import 'package:revanced_manager/app/app.locator.dart';
|
||||
import 'package:revanced_manager/models/patch.dart';
|
||||
import 'package:revanced_manager/models/patched_application.dart';
|
||||
import 'package:revanced_manager/services/github_api.dart';
|
||||
import 'package:revanced_manager/services/manager_api.dart';
|
||||
import 'package:revanced_manager/services/patcher_api.dart';
|
||||
import 'package:revanced_manager/services/toast.dart';
|
||||
|
@ -14,10 +15,14 @@ import 'package:flutter/material.dart';
|
|||
class PatchesSelectorViewModel extends BaseViewModel {
|
||||
final PatcherAPI _patcherAPI = locator<PatcherAPI>();
|
||||
final ManagerAPI _managerAPI = locator<ManagerAPI>();
|
||||
final GithubAPI _githubAPI = locator<GithubAPI>();
|
||||
final List<Patch> patches = [];
|
||||
final List<Patch> selectedPatches =
|
||||
locator<PatcherViewModel>().selectedPatches;
|
||||
String? patchesVersion = '';
|
||||
bool isDefaultPatchesRepo() {
|
||||
return _managerAPI.getPatchesRepo() == 'revanced/revanced-patches';
|
||||
}
|
||||
|
||||
Future<void> initialize() async {
|
||||
getPatchesVersion();
|
||||
|
@ -104,9 +109,15 @@ class PatchesSelectorViewModel extends BaseViewModel {
|
|||
}
|
||||
|
||||
Future<String?> getPatchesVersion() async {
|
||||
patchesVersion = await _managerAPI.getLatestPatchesVersion();
|
||||
// print('Patches version: $patchesVersion');
|
||||
return patchesVersion ?? '0.0.0';
|
||||
if (isDefaultPatchesRepo()) {
|
||||
patchesVersion = await _managerAPI.getLatestPatchesVersion();
|
||||
// print('Patches version: $patchesVersion');
|
||||
return patchesVersion ?? '0.0.0';
|
||||
} else {
|
||||
// fetch from github
|
||||
patchesVersion = await _githubAPI
|
||||
.getLastestReleaseVersion(_managerAPI.getPatchesRepo());
|
||||
}
|
||||
}
|
||||
|
||||
List<Patch> getQueriedPatches(String query) {
|
||||
|
|
Loading…
Reference in a new issue