Skip to content

Commit

Permalink
fix: pair integrations and patches updates (#1102)
Browse files Browse the repository at this point in the history
  • Loading branch information
TheAabedKhan authored Aug 8, 2023
1 parent 1714c3f commit 722a585
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 10 deletions.
51 changes: 42 additions & 9 deletions lib/services/manager_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,15 @@ class ManagerAPI {
String defaultCliRepo = 'revanced/revanced-cli';
String defaultManagerRepo = 'revanced/revanced-manager';
String? patchesVersion = '';
String? integrationsVersion = '';
bool isDefaultPatchesRepo() {
return getPatchesRepo() == 'revanced/revanced-patches';
}

bool isDefaultIntegrationsRepo() {
return getIntegrationsRepo() == 'revanced/revanced-integrations';
}

Future<void> initialize() async {
_prefs = await SharedPreferences.getInstance();
isRooted = await _rootAPI.isRooted();
Expand Down Expand Up @@ -267,14 +272,12 @@ class ManagerAPI {
Future<File?> downloadIntegrations() async {
try {
final String repoName = getIntegrationsRepo();
if (repoName == defaultIntegrationsRepo) {
return await _revancedAPI.getLatestReleaseFile(
'.apk',
defaultIntegrationsRepo,
);
} else {
return await _githubAPI.getLatestReleaseFile('.apk', repoName);
}
final String currentVersion = await getCurrentIntegrationsVersion();
return await _githubAPI.getPatchesReleaseFile(
'.apk',
repoName,
currentVersion,
);
} on Exception catch (e) {
if (kDebugMode) {
print(e);
Expand Down Expand Up @@ -323,14 +326,31 @@ class ManagerAPI {
);
}

Future<String?> getLatestIntegrationsVersion() async {
if (isDefaultIntegrationsRepo()) {
return await _revancedAPI.getLatestReleaseVersion(
'.apk',
defaultIntegrationsRepo,
);
} else {
final release = await _githubAPI.getLatestRelease(getIntegrationsRepo());
if (release != null) {
return release['tag_name'];
} else {
return null;
}
}
}

Future<String?> getLatestPatchesVersion() async {
if (isDefaultPatchesRepo()) {
return await _revancedAPI.getLatestReleaseVersion(
'.json',
defaultPatchesRepo,
);
} else {
final release = await _githubAPI.getLatestPatchesRelease(getPatchesRepo());
final release =
await _githubAPI.getLatestPatchesRelease(getPatchesRepo());
if (release != null) {
return release['tag_name'];
} else {
Expand All @@ -357,6 +377,19 @@ class ManagerAPI {
await _prefs.setString('patchesVersion', version);
}

Future<String> getCurrentIntegrationsVersion() async {
integrationsVersion = _prefs.getString('integrationsVersion') ?? '0.0.0';
if (integrationsVersion == '0.0.0' || isPatchesAutoUpdate()) {
integrationsVersion = await getLatestIntegrationsVersion() ?? '0.0.0';
await setCurrentIntegrationsVersion(integrationsVersion!);
}
return integrationsVersion!;
}

Future<void> setCurrentIntegrationsVersion(String version) async {
await _prefs.setString('integrationsVersion', version);
}

Future<List<PatchedApplication>> getAppsToRemove(
List<PatchedApplication> patchedApps,
) async {
Expand Down
5 changes: 4 additions & 1 deletion lib/ui/views/home/home_viewmodel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -253,9 +253,12 @@ class HomeViewModel extends BaseViewModel {
_toast.showBottom('homeView.downloadingMessage');
final String patchesVersion =
await _managerAPI.getLatestPatchesVersion() ?? '0.0.0';
if (patchesVersion != '0.0.0') {
final String integrationsVersion =
await _managerAPI.getLatestIntegrationsVersion() ?? '0.0.0';
if (patchesVersion != '0.0.0' && integrationsVersion != '0.0.0') {
_toast.showBottom('homeView.downloadedMessage');
await _managerAPI.setCurrentPatchesVersion(patchesVersion);
await _managerAPI.setCurrentIntegrationsVersion(integrationsVersion);
forceRefresh(context);
} else {
_toast.showBottom('homeView.errorDownloadMessage');
Expand Down

0 comments on commit 722a585

Please sign in to comment.