feat: Add toggle to use pre-releases (#2485)

Co-authored-by: oSumAtrIX <johan.melkonyan1@web.de>
This commit is contained in:
aAbed
2025-05-05 19:45:41 +05:45
committed by GitHub
parent dedcb3c51a
commit 89b48cebcf
8 changed files with 529 additions and 448 deletions

View File

@@ -33,13 +33,16 @@ class GithubAPI {
});
}
Future<Map<String, dynamic>?> getLatestRelease(
String repoName,
) async {
Future<Map<String, dynamic>?> getLatestRelease(String repoName) async {
final String target =
_managerAPI.usePrereleases() ? '?per_page=1' : '/latest';
try {
final response = await _dioGetSynchronously(
'/repos/$repoName/releases/latest',
'/repos/$repoName/releases$target',
);
if (_managerAPI.usePrereleases()) {
return response.data.first;
}
return response.data;
} on Exception catch (e) {
if (kDebugMode) {
@@ -50,17 +53,19 @@ class GithubAPI {
}
Future<String?> getChangelogs(bool isPatches) async {
final String repoName = isPatches
? _managerAPI.getPatchesRepo()
: _managerAPI.defaultManagerRepo;
final String repoName =
isPatches
? _managerAPI.getPatchesRepo()
: _managerAPI.defaultManagerRepo;
try {
final response = await _dioGetSynchronously(
'/repos/$repoName/releases?per_page=50',
);
final buffer = StringBuffer();
final String version = isPatches
? _managerAPI.getLastUsedPatchesVersion()
: 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'] == version) {
@@ -70,7 +75,7 @@ class GithubAPI {
}
break;
}
if (release['prerelease']) {
if (!_managerAPI.usePrereleases() && release['prerelease']) {
continue;
}
buffer.writeln(release['body']);
@@ -96,25 +101,21 @@ class GithubAPI {
) async {
try {
if (url.isNotEmpty) {
return await _downloadManager.getSingleFile(
url,
);
return await _downloadManager.getSingleFile(url);
}
final response = await _dioGetSynchronously(
'/repos/$repoName/releases/tags/$version',
);
final Map<String, dynamic>? release = response.data;
if (release != null) {
final Map<String, dynamic>? asset =
(release['assets'] as List<dynamic>).firstWhereOrNull(
(asset) => (asset['name'] as String).endsWith(extension),
);
final Map<String, dynamic>? asset = (release['assets'] as List<dynamic>)
.firstWhereOrNull(
(asset) => (asset['name'] as String).endsWith(extension),
);
if (asset != null) {
final String downloadUrl = asset['browser_download_url'];
_managerAPI.setPatchesDownloadURL(downloadUrl);
return await _downloadManager.getSingleFile(
downloadUrl,
);
return await _downloadManager.getSingleFile(downloadUrl);
}
}
} on Exception catch (e) {

View File

@@ -36,7 +36,6 @@ class ManagerAPI {
Patch? selectedPatch;
BuildContext? ctx;
bool isRooted = false;
bool releaseBuild = false;
bool suggestedAppVersionSelected = true;
bool isDynamicThemeAvailable = false;
bool isScopedStorageAvailable = false;
@@ -63,11 +62,9 @@ class ManagerAPI {
isScopedStorageAvailable = sdkVersion >= 30; // ANDROID_11_SDK_VERSION = 30
storedPatchesFile =
(await getApplicationDocumentsDirectory()).path + storedPatchesFile;
if (kReleaseMode) {
releaseBuild = !(await getCurrentManagerVersion()).contains('-dev');
}
final hasMigratedToNewMigrationSystem = _prefs.getBool('migratedToNewApiPrefSystem') ?? false;
final hasMigratedToNewMigrationSystem =
_prefs.getBool('migratedToNewApiPrefSystem') ?? false;
if (!hasMigratedToNewMigrationSystem) {
final apiUrl = getApiUrl().toLowerCase();
@@ -168,6 +165,18 @@ class ManagerAPI {
return _prefs.getBool('patchesAutoUpdate') ?? false;
}
bool usePrereleases() {
return _prefs.getBool('usePrereleases') ?? false;
}
void setPrereleases(bool value) {
_prefs.setBool('usePrereleases', value);
if (isPatchesAutoUpdate()) {
setCurrentPatchesVersion('0.0.0');
_toast.showBottom(t.settingsView.restartAppForChanges);
}
}
bool isPatchesChangeEnabled() {
return _prefs.getBool('patchesChangeEnabled') ?? false;
}
@@ -207,32 +216,36 @@ class ManagerAPI {
List<Patch> getSavedPatches(String packageName) {
final List<String> patchesJson =
_prefs.getStringList('savedPatches-$packageName') ?? [];
final List<Patch> patches = patchesJson.map((String patchJson) {
return Patch.fromJson(jsonDecode(patchJson));
}).toList();
final List<Patch> patches =
patchesJson.map((String patchJson) {
return Patch.fromJson(jsonDecode(patchJson));
}).toList();
return patches;
}
Future<void> savePatches(List<Patch> patches, String packageName) async {
final List<String> patchesJson = patches.map((Patch patch) {
return jsonEncode(patch.toJson());
}).toList();
final List<String> patchesJson =
patches.map((Patch patch) {
return jsonEncode(patch.toJson());
}).toList();
await _prefs.setStringList('savedPatches-$packageName', patchesJson);
}
List<Patch> getUsedPatches(String packageName) {
final List<String> patchesJson =
_prefs.getStringList('usedPatches-$packageName') ?? [];
final List<Patch> patches = patchesJson.map((String patchJson) {
return Patch.fromJson(jsonDecode(patchJson));
}).toList();
final List<Patch> patches =
patchesJson.map((String patchJson) {
return Patch.fromJson(jsonDecode(patchJson));
}).toList();
return patches;
}
Future<void> setUsedPatches(List<Patch> patches, String packageName) async {
final List<String> patchesJson = patches.map((Patch patch) {
return jsonEncode(patch.toJson());
}).toList();
final List<String> patchesJson =
patches.map((Patch patch) {
return jsonEncode(patch.toJson());
}).toList();
await _prefs.setStringList('usedPatches-$packageName', patchesJson);
}
@@ -246,8 +259,9 @@ class ManagerAPI {
}
Option? getPatchOption(String packageName, String patchName, String key) {
final String? optionJson =
_prefs.getString('patchOption-$packageName-$patchName-$key');
final String? optionJson = _prefs.getString(
'patchOption-$packageName-$patchName-$key',
);
if (optionJson != null) {
final Option option = Option.fromJson(jsonDecode(optionJson));
return option;
@@ -340,9 +354,7 @@ class ManagerAPI {
}
Future<void> deleteKeystore() async {
final File keystore = File(
keystoreFile,
);
final File keystore = File(keystoreFile);
if (await keystore.exists()) {
await keystore.delete();
}
@@ -364,16 +376,14 @@ class ManagerAPI {
Future<void> setLastPatchedApp(
PatchedApplication app,
File outFile,
File outFile
) async {
deleteLastPatchedApp();
final Directory appCache = await getApplicationSupportDirectory();
app.patchedFilePath =
outFile.copySync('${appCache.path}/lastPatchedApp.apk').path;
app.fileSize = outFile.lengthSync();
await _prefs.setString(
'lastPatchedApp',
json.encode(app.toJson()),
);
await _prefs.setString('lastPatchedApp', json.encode(app.toJson()));
}
List<PatchedApplication> getPatchedApps() {
@@ -381,9 +391,7 @@ class ManagerAPI {
return apps.map((a) => PatchedApplication.fromJson(jsonDecode(a))).toList();
}
Future<void> setPatchedApps(
List<PatchedApplication> patchedApps,
) async {
Future<void> setPatchedApps(List<PatchedApplication> patchedApps) async {
if (patchedApps.length > 1) {
patchedApps.sort((a, b) => a.name.compareTo(b.name));
}
@@ -396,10 +404,8 @@ class ManagerAPI {
Future<void> savePatchedApp(PatchedApplication app) async {
final List<PatchedApplication> patchedApps = getPatchedApps();
patchedApps.removeWhere((a) => a.packageName == app.packageName);
final ApplicationWithIcon? installed = await DeviceApps.getApp(
app.packageName,
true,
) as ApplicationWithIcon?;
final ApplicationWithIcon? installed =
await DeviceApps.getApp(app.packageName, true) as ApplicationWithIcon?;
if (installed != null) {
app.name = installed.appName;
app.version = installed.versionName!;
@@ -439,14 +445,13 @@ class ManagerAPI {
try {
final String patchesJson = await PatcherAPI.patcherChannel.invokeMethod(
'getPatches',
{
'patchBundleFilePath': patchBundleFile.path,
},
{'patchBundleFilePath': patchBundleFile.path},
);
final List<dynamic> patchesJsonList = jsonDecode(patchesJson);
patches = patchesJsonList
.map((patchJson) => Patch.fromJson(patchJson))
.toList();
patches =
patchesJsonList
.map((patchJson) => Patch.fromJson(patchJson))
.toList();
return patches;
} on Exception catch (e) {
if (kDebugMode) {
@@ -491,8 +496,9 @@ class ManagerAPI {
} else {
final release = await _githubAPI.getLatestRelease(getPatchesRepo());
if (release != null) {
final DateTime timestamp =
DateTime.parse(release['created_at'] as String);
final DateTime timestamp = DateTime.parse(
release['created_at'] as String,
);
return format(timestamp, locale: 'en_short');
} else {
return null;
@@ -501,22 +507,16 @@ class ManagerAPI {
}
Future<String?> getLatestManagerReleaseTime() async {
return await _revancedAPI.getLatestReleaseTime(
'manager',
);
return await _revancedAPI.getLatestReleaseTime('manager');
}
Future<String?> getLatestManagerVersion() async {
return await _revancedAPI.getLatestReleaseVersion(
'manager',
);
return await _revancedAPI.getLatestReleaseVersion('manager');
}
Future<String?> getLatestPatchesVersion() async {
if (!isUsingAlternativeSources()) {
return await _revancedAPI.getLatestReleaseVersion(
'patches',
);
return await _revancedAPI.getLatestReleaseVersion('patches');
} else {
final release = await _githubAPI.getLatestRelease(getPatchesRepo());
if (release != null) {
@@ -530,8 +530,9 @@ class ManagerAPI {
String getLastUsedPatchesVersion() {
final String lastPatchesVersions =
_prefs.getString('lastUsedPatchesVersion') ?? '{}';
final Map<String, dynamic> lastPatchesVersionMap =
jsonDecode(lastPatchesVersions);
final Map<String, dynamic> lastPatchesVersionMap = jsonDecode(
lastPatchesVersions,
);
final String repo = getPatchesRepo();
return lastPatchesVersionMap[repo] ?? '0.0.0';
}
@@ -539,8 +540,9 @@ class ManagerAPI {
void setLastUsedPatchesVersion({String? version}) {
final String lastPatchesVersions =
_prefs.getString('lastUsedPatchesVersion') ?? '{}';
final Map<String, dynamic> lastPatchesVersionMap =
jsonDecode(lastPatchesVersions);
final Map<String, dynamic> lastPatchesVersionMap = jsonDecode(
lastPatchesVersions,
);
final repo = getPatchesRepo();
final String lastPatchesVersion =
version ?? lastPatchesVersionMap[repo] ?? '0.0.0';
@@ -597,10 +599,8 @@ class ManagerAPI {
if (hasRootPermissions) {
final List<String> installedApps = await _rootAPI.getInstalledApps();
for (final String packageName in installedApps) {
final ApplicationWithIcon? application = await DeviceApps.getApp(
packageName,
true,
) as ApplicationWithIcon?;
final ApplicationWithIcon? application =
await DeviceApps.getApp(packageName, true) as ApplicationWithIcon?;
if (application != null) {
mountedApps.add(
PatchedApplication(
@@ -621,55 +621,55 @@ class ManagerAPI {
}
Future<void> showPatchesChangeWarningDialog(BuildContext context) {
final ValueNotifier<bool> noShow =
ValueNotifier(!showPatchesChangeWarning());
final ValueNotifier<bool> noShow = ValueNotifier(
!showPatchesChangeWarning(),
);
return showDialog(
barrierDismissible: false,
context: context,
builder: (context) => PopScope(
canPop: false,
child: AlertDialog(
title: Text(t.warning),
content: ValueListenableBuilder(
valueListenable: noShow,
builder: (context, value, child) {
return Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
t.patchItem.patchesChangeWarningDialogText,
style: const TextStyle(
fontSize: 16,
fontWeight: FontWeight.w500,
),
),
const SizedBox(height: 8),
HapticCheckboxListTile(
value: value,
contentPadding: EdgeInsets.zero,
title: Text(
t.noShowAgain,
),
onChanged: (selected) {
noShow.value = selected!;
},
),
],
);
},
),
actions: [
FilledButton(
onPressed: () {
setPatchesChangeWarning(noShow.value);
Navigator.of(context).pop();
},
child: Text(t.okButton),
builder:
(context) => PopScope(
canPop: false,
child: AlertDialog(
title: Text(t.warning),
content: ValueListenableBuilder(
valueListenable: noShow,
builder: (context, value, child) {
return Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
t.patchItem.patchesChangeWarningDialogText,
style: const TextStyle(
fontSize: 16,
fontWeight: FontWeight.w500,
),
),
const SizedBox(height: 8),
HapticCheckboxListTile(
value: value,
contentPadding: EdgeInsets.zero,
title: Text(t.noShowAgain),
onChanged: (selected) {
noShow.value = selected!;
},
),
],
);
},
),
actions: [
FilledButton(
onPressed: () {
setPatchesChangeWarning(noShow.value);
Navigator.of(context).pop();
},
child: Text(t.okButton),
),
],
),
],
),
),
),
);
}
@@ -677,15 +677,17 @@ class ManagerAPI {
final List<PatchedApplication> patchedApps = getPatchedApps();
// Remove apps that are not installed anymore.
final List<PatchedApplication> toRemove =
await getAppsToRemove(patchedApps);
final List<PatchedApplication> toRemove = await getAppsToRemove(
patchedApps,
);
patchedApps.removeWhere((a) => toRemove.contains(a));
// Determine all apps that are installed by mounting.
final List<PatchedApplication> mountedApps = await getMountedApps();
mountedApps.removeWhere(
(app) => patchedApps
.any((patchedApp) => patchedApp.packageName == app.packageName),
(app) => patchedApps.any(
(patchedApp) => patchedApp.packageName == app.packageName,
),
);
patchedApps.addAll(mountedApps);
@@ -715,10 +717,7 @@ class ManagerAPI {
return app != null && app.isSplit;
}
Future<void> setSelectedPatches(
String app,
List<String> patches,
) async {
Future<void> setSelectedPatches(String app, List<String> patches) async {
final File selectedPatchesFile = File(storedPatchesFile);
final Map<String, dynamic> patchesMap = await readSelectedPatchesFile();
if (patches.isEmpty) {
@@ -774,9 +773,9 @@ class ManagerAPI {
final Map<String, dynamic> settings = _prefs
.getKeys()
.fold<Map<String, dynamic>>({}, (Map<String, dynamic> map, String key) {
map[key] = _prefs.get(key);
return map;
});
map[key] = _prefs.get(key);
return map;
});
return jsonEncode(settings);
}
@@ -801,11 +800,11 @@ class ManagerAPI {
}
void resetAllOptions() {
_prefs.getKeys().where((key) => key.startsWith('patchOption-')).forEach(
(key) {
_prefs.remove(key);
},
);
_prefs.getKeys().where((key) => key.startsWith('patchOption-')).forEach((
key,
) {
_prefs.remove(key);
});
}
Future<void> resetLastSelectedPatches() async {

View File

@@ -14,6 +14,7 @@ import 'package:timeago/timeago.dart';
class RevancedAPI {
late final Dio _dio;
late final DownloadManager _downloadManager = locator<DownloadManager>();
late final ManagerAPI _managerAPI = locator<ManagerAPI>();
final Lock getToolsLock = Lock();
@@ -43,15 +44,15 @@ class RevancedAPI {
return contributors;
}
Future<Map<String, dynamic>?> _getLatestRelease(
String toolName,
) {
Future<Map<String, dynamic>?> _getLatestRelease(String toolName) {
if (!locator<ManagerAPI>().getDownloadConsent()) {
return Future(() => null);
}
return getToolsLock.synchronized(() async {
try {
final response = await _dio.get('/$toolName');
final response = await _dio.get(
'/$toolName?prerelease=${_managerAPI.usePrereleases()}',
);
return response.data;
} on Exception catch (e) {
if (kDebugMode) {
@@ -62,13 +63,9 @@ class RevancedAPI {
});
}
Future<String?> getLatestReleaseVersion(
String toolName,
) async {
Future<String?> getLatestReleaseVersion(String toolName) async {
try {
final Map<String, dynamic>? release = await _getLatestRelease(
toolName,
);
final Map<String, dynamic>? release = await _getLatestRelease(toolName);
if (release != null) {
return release['version'];
}
@@ -81,13 +78,9 @@ class RevancedAPI {
return null;
}
Future<File?> getLatestReleaseFile(
String toolName,
) async {
Future<File?> getLatestReleaseFile(String toolName) async {
try {
final Map<String, dynamic>? release = await _getLatestRelease(
toolName,
);
final Map<String, dynamic>? release = await _getLatestRelease(toolName);
if (release != null) {
final String url = release['download_url'];
return await _downloadManager.getSingleFile(url);
@@ -136,16 +129,13 @@ class RevancedAPI {
return outputFile;
}
Future<String?> getLatestReleaseTime(
String toolName,
) async {
Future<String?> getLatestReleaseTime(String toolName) async {
try {
final Map<String, dynamic>? release = await _getLatestRelease(
toolName,
);
final Map<String, dynamic>? release = await _getLatestRelease(toolName);
if (release != null) {
final DateTime timestamp =
DateTime.parse(release['created_at'] as String);
final DateTime timestamp = DateTime.parse(
release['created_at'] as String,
);
return format(timestamp, locale: 'en_short');
}
} on Exception catch (e) {