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
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 529 additions and 448 deletions

View file

@ -180,6 +180,9 @@
"disablePatchesSelectionWarningText": "You are about to disable changing the selection of patches.\nThe default selection of patches will be restored.\n\nDisable anyways?", "disablePatchesSelectionWarningText": "You are about to disable changing the selection of patches.\nThe default selection of patches will be restored.\n\nDisable anyways?",
"autoUpdatePatchesLabel": "Auto update patches", "autoUpdatePatchesLabel": "Auto update patches",
"autoUpdatePatchesHint": "Automatically update patches to the latest version", "autoUpdatePatchesHint": "Automatically update patches to the latest version",
"usePrereleasesLabel": "Use pre-releases",
"usePrereleasesHint": "Use pre-release versions of ReVanced Manager and ReVanced Patches",
"usePrereleasesWarningText": "Using pre-release versions may cause unexpected issues.\n\nEnable anyways?",
"showUpdateDialogLabel": "Show update dialog", "showUpdateDialogLabel": "Show update dialog",
"showUpdateDialogHint": "Show a dialog when a new update is available", "showUpdateDialogHint": "Show a dialog when a new update is available",
"universalPatchesLabel": "Show universal patches", "universalPatchesLabel": "Show universal patches",

View file

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

View file

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

View file

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

View file

@ -82,10 +82,13 @@ class HomeViewModel extends BaseViewModel {
); );
flutterLocalNotificationsPlugin flutterLocalNotificationsPlugin
.resolvePlatformSpecificImplementation< .resolvePlatformSpecificImplementation<
AndroidFlutterLocalNotificationsPlugin>() AndroidFlutterLocalNotificationsPlugin
>()
?.requestNotificationsPermission(); ?.requestNotificationsPermission();
final bool isConnected = !(await Connectivity().checkConnectivity()) final bool isConnected =
.contains(ConnectivityResult.none); !(await Connectivity().checkConnectivity()).contains(
ConnectivityResult.none,
);
if (!isConnected) { if (!isConnected) {
_toast.showBottom(t.homeView.noConnection); _toast.showBottom(t.homeView.noConnection);
} }
@ -106,8 +109,10 @@ class HomeViewModel extends BaseViewModel {
void navigateToAppInfo(PatchedApplication app, bool isLastPatchedApp) { void navigateToAppInfo(PatchedApplication app, bool isLastPatchedApp) {
_navigationService.navigateTo( _navigationService.navigateTo(
Routes.appInfoView, Routes.appInfoView,
arguments: arguments: AppInfoViewArguments(
AppInfoViewArguments(app: app, isLastPatchedApp: isLastPatchedApp), app: app,
isLastPatchedApp: isLastPatchedApp,
),
); );
} }
@ -118,8 +123,8 @@ class HomeViewModel extends BaseViewModel {
Future<void> navigateToPatcher(PatchedApplication app) async { Future<void> navigateToPatcher(PatchedApplication app) async {
locator<PatcherViewModel>().selectedApp = app; locator<PatcherViewModel>().selectedApp = app;
locator<PatcherViewModel>().selectedPatches = locator<PatcherViewModel>().selectedPatches = await _patcherAPI
await _patcherAPI.getAppliedPatches(app.appliedPatches); .getAppliedPatches(app.appliedPatches);
locator<PatcherViewModel>().notifyListeners(); locator<PatcherViewModel>().notifyListeners();
locator<NavigationViewModel>().setIndex(1); locator<NavigationViewModel>().setIndex(1);
} }
@ -135,9 +140,6 @@ class HomeViewModel extends BaseViewModel {
} }
Future<bool> hasManagerUpdates() async { Future<bool> hasManagerUpdates() async {
if (!_managerAPI.releaseBuild) {
return false;
}
latestManagerVersion = latestManagerVersion =
await _managerAPI.getLatestManagerVersion() ?? _currentManagerVersion; await _managerAPI.getLatestManagerVersion() ?? _currentManagerVersion;
@ -151,10 +153,12 @@ class HomeViewModel extends BaseViewModel {
latestPatchesVersion = await _managerAPI.getLatestPatchesVersion(); latestPatchesVersion = await _managerAPI.getLatestPatchesVersion();
if (latestPatchesVersion != null) { if (latestPatchesVersion != null) {
try { try {
final int latestVersionInt = final int latestVersionInt = int.parse(
int.parse(latestPatchesVersion!.replaceAll(RegExp('[^0-9]'), '')); latestPatchesVersion!.replaceAll(RegExp('[^0-9]'), ''),
final int currentVersionInt = );
int.parse(_currentPatchesVersion.replaceAll(RegExp('[^0-9]'), '')); final int currentVersionInt = int.parse(
_currentPatchesVersion.replaceAll(RegExp('[^0-9]'), ''),
);
return latestVersionInt > currentVersionInt; return latestVersionInt > currentVersionInt;
} on Exception catch (e) { } on Exception catch (e) {
if (kDebugMode) { if (kDebugMode) {
@ -187,123 +191,128 @@ class HomeViewModel extends BaseViewModel {
await showDialog( await showDialog(
context: context, context: context,
barrierDismissible: false, barrierDismissible: false,
builder: (context) => PopScope( builder:
canPop: false, (context) => PopScope(
child: AlertDialog( canPop: false,
title: Text(t.homeView.downloadConsentDialogTitle), child: AlertDialog(
content: ValueListenableBuilder( title: Text(t.homeView.downloadConsentDialogTitle),
valueListenable: autoUpdate, content: ValueListenableBuilder(
builder: (context, value, child) { valueListenable: autoUpdate,
return Column( builder: (context, value, child) {
mainAxisSize: MainAxisSize.min, return Column(
crossAxisAlignment: CrossAxisAlignment.start, mainAxisSize: MainAxisSize.min,
children: [ crossAxisAlignment: CrossAxisAlignment.start,
Text( children: [
t.homeView.downloadConsentDialogText, Text(
style: TextStyle( t.homeView.downloadConsentDialogText,
fontSize: 16, style: TextStyle(
fontWeight: FontWeight.w500, fontSize: 16,
color: Theme.of(context).colorScheme.secondary, fontWeight: FontWeight.w500,
), color: Theme.of(context).colorScheme.secondary,
), ),
Padding(
padding: const EdgeInsets.symmetric(vertical: 10),
child: Text(
t.homeView.downloadConsentDialogText2(
url: _managerAPI.defaultApiUrl.split('/')[2],
), ),
style: TextStyle( Padding(
fontSize: 16, padding: const EdgeInsets.symmetric(vertical: 10),
fontWeight: FontWeight.w500, child: Text(
color: Theme.of(context).colorScheme.error, t.homeView.downloadConsentDialogText2(
url: _managerAPI.defaultApiUrl.split('/')[2],
),
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w500,
color: Theme.of(context).colorScheme.error,
),
),
), ),
), ],
), );
], },
); ),
}, actions: [
TextButton(
onPressed: () async {
_managerAPI.setDownloadConsent(false);
SystemNavigator.pop();
},
child: Text(t.quitButton),
),
FilledButton(
onPressed: () async {
_managerAPI.setDownloadConsent(true);
_managerAPI.setPatchesAutoUpdate(autoUpdate.value);
Navigator.of(context).pop();
},
child: Text(t.okButton),
),
],
),
), ),
actions: [
TextButton(
onPressed: () async {
_managerAPI.setDownloadConsent(false);
SystemNavigator.pop();
},
child: Text(t.quitButton),
),
FilledButton(
onPressed: () async {
_managerAPI.setDownloadConsent(true);
_managerAPI.setPatchesAutoUpdate(autoUpdate.value);
Navigator.of(context).pop();
},
child: Text(t.okButton),
),
],
),
),
); );
} }
void showUpdateDialog(BuildContext context, bool isPatches) { void showUpdateDialog(BuildContext context, bool isPatches) {
final ValueNotifier<bool> noShow = final ValueNotifier<bool> noShow = ValueNotifier(
ValueNotifier(!_managerAPI.showUpdateDialog()); !_managerAPI.showUpdateDialog(),
);
showDialog( showDialog(
context: context, context: context,
builder: (innerContext) => AlertDialog( builder:
title: Text(t.homeView.updateDialogTitle), (innerContext) => AlertDialog(
content: ValueListenableBuilder( title: Text(t.homeView.updateDialogTitle),
valueListenable: noShow, content: ValueListenableBuilder(
builder: (context, value, child) { valueListenable: noShow,
return Column( builder: (context, value, child) {
mainAxisSize: MainAxisSize.min, return Column(
crossAxisAlignment: CrossAxisAlignment.start, mainAxisSize: MainAxisSize.min,
children: [ crossAxisAlignment: CrossAxisAlignment.start,
Text( children: [
t.homeView.updateDialogText( Text(
file: isPatches ? 'ReVanced Patches' : 'ReVanced Manager', t.homeView.updateDialogText(
version: isPatches file:
? _currentPatchesVersion isPatches ? 'ReVanced Patches' : 'ReVanced Manager',
: _currentManagerVersion, version:
), isPatches
style: TextStyle( ? _currentPatchesVersion
fontSize: 16, : _currentManagerVersion,
fontWeight: FontWeight.w500, ),
color: Theme.of(context).colorScheme.secondary, style: TextStyle(
), fontSize: 16,
), fontWeight: FontWeight.w500,
const SizedBox(height: 10), color: Theme.of(context).colorScheme.secondary,
HapticCheckboxListTile( ),
value: value, ),
contentPadding: EdgeInsets.zero, const SizedBox(height: 10),
title: Text(t.noShowAgain), HapticCheckboxListTile(
subtitle: Text(t.homeView.changeLaterSubtitle), value: value,
onChanged: (selected) { contentPadding: EdgeInsets.zero,
noShow.value = selected!; title: Text(t.noShowAgain),
}, subtitle: Text(t.homeView.changeLaterSubtitle),
), onChanged: (selected) {
], noShow.value = selected!;
); },
}, ),
), ],
actions: [ );
TextButton( },
onPressed: () async { ),
_managerAPI.setShowUpdateDialog(!noShow.value); actions: [
Navigator.pop(innerContext); TextButton(
}, onPressed: () async {
child: Text(t.dismissButton), // Decide later _managerAPI.setShowUpdateDialog(!noShow.value);
Navigator.pop(innerContext);
},
child: Text(t.dismissButton), // Decide later
),
FilledButton(
onPressed: () async {
_managerAPI.setShowUpdateDialog(!noShow.value);
Navigator.pop(innerContext);
await showUpdateConfirmationDialog(context, isPatches);
},
child: Text(t.showUpdateButton),
),
],
), ),
FilledButton(
onPressed: () async {
_managerAPI.setShowUpdateDialog(!noShow.value);
Navigator.pop(innerContext);
await showUpdateConfirmationDialog(context, isPatches);
},
child: Text(t.showUpdateButton),
),
],
),
); );
} }
@ -326,94 +335,95 @@ class HomeViewModel extends BaseViewModel {
_toast.showBottom(t.homeView.downloadingMessage); _toast.showBottom(t.homeView.downloadingMessage);
showDialog( showDialog(
context: context, context: context,
builder: (context) => ValueListenableBuilder( builder:
valueListenable: downloaded, (context) => ValueListenableBuilder(
builder: (context, value, child) { valueListenable: downloaded,
return AlertDialog( builder: (context, value, child) {
title: Text( return AlertDialog(
!value title: Text(
? t.homeView.downloadingMessage !value
: t.homeView.downloadedMessage, ? t.homeView.downloadingMessage
), : t.homeView.downloadedMessage,
content: Column( ),
mainAxisSize: MainAxisSize.min, content: Column(
children: [ mainAxisSize: MainAxisSize.min,
if (!value) children: [
Column( if (!value)
crossAxisAlignment: CrossAxisAlignment.start, Column(
children: [ crossAxisAlignment: CrossAxisAlignment.start,
StreamBuilder<double>(
initialData: 0.0,
stream: _revancedAPI.managerUpdateProgress.stream,
builder: (context, snapshot) {
return LinearProgressIndicator(
value: snapshot.data! * 0.01,
valueColor: AlwaysStoppedAnimation<Color>(
Theme.of(context).colorScheme.secondary,
),
);
},
),
const SizedBox(height: 16.0),
Align(
alignment: Alignment.centerRight,
child: FilledButton(
onPressed: () {
_revancedAPI.disposeManagerUpdateProgress();
Navigator.of(context).pop();
},
child: Text(t.cancelButton),
),
),
],
),
if (value)
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
t.homeView.installUpdate,
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w500,
color: Theme.of(context).colorScheme.secondary,
),
),
const SizedBox(height: 16.0),
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [ children: [
StreamBuilder<double>(
initialData: 0.0,
stream: _revancedAPI.managerUpdateProgress.stream,
builder: (context, snapshot) {
return LinearProgressIndicator(
value: snapshot.data! * 0.01,
valueColor: AlwaysStoppedAnimation<Color>(
Theme.of(context).colorScheme.secondary,
),
);
},
),
const SizedBox(height: 16.0),
Align( Align(
alignment: Alignment.centerRight, alignment: Alignment.centerRight,
child: TextButton( child: FilledButton(
onPressed: () { onPressed: () {
_revancedAPI.disposeManagerUpdateProgress();
Navigator.of(context).pop(); Navigator.of(context).pop();
}, },
child: Text(t.cancelButton), child: Text(t.cancelButton),
), ),
), ),
const SizedBox(width: 8.0), ],
Align( ),
alignment: Alignment.centerRight, if (value)
child: FilledButton( Column(
onPressed: () async { crossAxisAlignment: CrossAxisAlignment.start,
await _patcherAPI.installApk( children: [
context, Text(
downloadedApk!.path, t.homeView.installUpdate,
); style: TextStyle(
}, fontSize: 16,
child: Text(t.updateButton), fontWeight: FontWeight.w500,
color: Theme.of(context).colorScheme.secondary,
), ),
), ),
const SizedBox(height: 16.0),
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Align(
alignment: Alignment.centerRight,
child: TextButton(
onPressed: () {
Navigator.of(context).pop();
},
child: Text(t.cancelButton),
),
),
const SizedBox(width: 8.0),
Align(
alignment: Alignment.centerRight,
child: FilledButton(
onPressed: () async {
await _patcherAPI.installApk(
context,
downloadedApk!.path,
);
},
child: Text(t.updateButton),
),
),
],
),
], ],
), ),
], ],
), ),
], );
), },
); ),
},
),
); );
final File? managerApk = await downloadManager(); final File? managerApk = await downloadManager();
if (managerApk != null) { if (managerApk != null) {
@ -468,10 +478,11 @@ class HomeViewModel extends BaseViewModel {
shape: const RoundedRectangleBorder( shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.vertical(top: Radius.circular(24.0)), borderRadius: BorderRadius.vertical(top: Radius.circular(24.0)),
), ),
builder: (context) => UpdateConfirmationSheet( builder:
isPatches: isPatches, (context) => UpdateConfirmationSheet(
changelog: changelog, isPatches: isPatches,
), changelog: changelog,
),
); );
} }

View file

@ -40,6 +40,10 @@ class SettingsViewModel extends BaseViewModel {
notifyListeners(); notifyListeners();
} }
bool usePrereleases() {
return _managerAPI.usePrereleases();
}
bool showUpdateDialog() { bool showUpdateDialog() {
return _managerAPI.showUpdateDialog(); return _managerAPI.showUpdateDialog();
} }
@ -64,6 +68,45 @@ class SettingsViewModel extends BaseViewModel {
return _managerAPI.isUsingAlternativeSources(); return _managerAPI.isUsingAlternativeSources();
} }
Future<void> showUsePrereleasesDialog(
BuildContext context,
bool value,
) async {
if (value) {
return showDialog(
context: context,
builder:
(context) => AlertDialog(
title: Text(t.warning),
content: Text(
t.settingsView.usePrereleasesWarningText,
style: const TextStyle(
fontSize: 16,
fontWeight: FontWeight.w500,
),
),
actions: [
TextButton(
onPressed: () {
_managerAPI.setPrereleases(true);
Navigator.of(context).pop();
},
child: Text(t.yesButton),
),
FilledButton(
onPressed: () {
Navigator.of(context).pop();
},
child: Text(t.noButton),
),
],
),
);
} else {
_managerAPI.setPrereleases(false);
}
}
Future<void> showPatchesChangeEnableDialog( Future<void> showPatchesChangeEnableDialog(
bool value, bool value,
BuildContext context, BuildContext context,
@ -71,63 +114,65 @@ class SettingsViewModel extends BaseViewModel {
if (value) { if (value) {
return showDialog( return showDialog(
context: context, context: context,
builder: (context) => AlertDialog( builder:
title: Text(t.warning), (context) => AlertDialog(
content: Text( title: Text(t.warning),
t.settingsView.enablePatchesSelectionWarningText, content: Text(
style: const TextStyle( t.settingsView.enablePatchesSelectionWarningText,
fontSize: 16, style: const TextStyle(
fontWeight: FontWeight.w500, fontSize: 16,
fontWeight: FontWeight.w500,
),
),
actions: [
TextButton(
onPressed: () {
_managerAPI.setChangingToggleModified(true);
_managerAPI.setPatchesChangeEnabled(true);
Navigator.of(context).pop();
},
child: Text(t.yesButton),
),
FilledButton(
onPressed: () {
Navigator.of(context).pop();
},
child: Text(t.noButton),
),
],
), ),
),
actions: [
TextButton(
onPressed: () {
_managerAPI.setChangingToggleModified(true);
_managerAPI.setPatchesChangeEnabled(true);
Navigator.of(context).pop();
},
child: Text(t.yesButton),
),
FilledButton(
onPressed: () {
Navigator.of(context).pop();
},
child: Text(t.noButton),
),
],
),
); );
} else { } else {
return showDialog( return showDialog(
context: context, context: context,
builder: (context) => AlertDialog( builder:
title: Text(t.warning), (context) => AlertDialog(
content: Text( title: Text(t.warning),
t.settingsView.disablePatchesSelectionWarningText, content: Text(
style: const TextStyle( t.settingsView.disablePatchesSelectionWarningText,
fontSize: 16, style: const TextStyle(
fontWeight: FontWeight.w500, fontSize: 16,
fontWeight: FontWeight.w500,
),
),
actions: [
TextButton(
onPressed: () {
Navigator.of(context).pop();
},
child: Text(t.noButton),
),
FilledButton(
onPressed: () {
_managerAPI.setChangingToggleModified(true);
_patchesSelectorViewModel.selectDefaultPatches();
_managerAPI.setPatchesChangeEnabled(false);
Navigator.of(context).pop();
},
child: Text(t.yesButton),
),
],
), ),
),
actions: [
TextButton(
onPressed: () {
Navigator.of(context).pop();
},
child: Text(t.noButton),
),
FilledButton(
onPressed: () {
_managerAPI.setChangingToggleModified(true);
_patchesSelectorViewModel.selectDefaultPatches();
_managerAPI.setPatchesChangeEnabled(false);
Navigator.of(context).pop();
},
child: Text(t.yesButton),
),
],
),
); );
} }
} }
@ -173,31 +218,32 @@ class SettingsViewModel extends BaseViewModel {
if (!value) { if (!value) {
return showDialog( return showDialog(
context: context, context: context,
builder: (context) => AlertDialog( builder:
title: Text(t.warning), (context) => AlertDialog(
content: Text( title: Text(t.warning),
t.settingsView.requireSuggestedAppVersionDialogText, content: Text(
style: const TextStyle( t.settingsView.requireSuggestedAppVersionDialogText,
fontSize: 16, style: const TextStyle(
fontWeight: FontWeight.w500, fontSize: 16,
fontWeight: FontWeight.w500,
),
),
actions: [
TextButton(
onPressed: () {
_managerAPI.enableRequireSuggestedAppVersionStatus(false);
Navigator.of(context).pop();
},
child: Text(t.yesButton),
),
FilledButton(
onPressed: () {
Navigator.of(context).pop();
},
child: Text(t.noButton),
),
],
), ),
),
actions: [
TextButton(
onPressed: () {
_managerAPI.enableRequireSuggestedAppVersionStatus(false);
Navigator.of(context).pop();
},
child: Text(t.yesButton),
),
FilledButton(
onPressed: () {
Navigator.of(context).pop();
},
child: Text(t.noButton),
),
],
),
); );
} else { } else {
_managerAPI.enableRequireSuggestedAppVersionStatus(true); _managerAPI.enableRequireSuggestedAppVersionStatus(true);
@ -249,9 +295,7 @@ class SettingsViewModel extends BaseViewModel {
Future<void> importSettings() async { Future<void> importSettings() async {
try { try {
final String? result = await FlutterFileDialog.pickFile( final String? result = await FlutterFileDialog.pickFile(
params: const OpenFileDialogParams( params: const OpenFileDialogParams(fileExtensionsFilter: ['json']),
fileExtensionsFilter: ['json'],
),
); );
if (result != null) { if (result != null) {
final File inFile = File(result); final File inFile = File(result);
@ -298,9 +342,7 @@ class SettingsViewModel extends BaseViewModel {
if (isPatchesChangeEnabled()) { if (isPatchesChangeEnabled()) {
try { try {
final String? result = await FlutterFileDialog.pickFile( final String? result = await FlutterFileDialog.pickFile(
params: const OpenFileDialogParams( params: const OpenFileDialogParams(fileExtensionsFilter: ['json']),
fileExtensionsFilter: ['json'],
),
); );
if (result != null) { if (result != null) {
final File inFile = File(result); final File inFile = File(result);
@ -393,8 +435,9 @@ class SettingsViewModel extends BaseViewModel {
.replaceAll(':', '') .replaceAll(':', '')
.replaceAll('T', '') .replaceAll('T', '')
.replaceAll('.', ''); .replaceAll('.', '');
final File logcat = final File logcat = File(
File('${logDir.path}/revanced-manager_logcat_$dateTime.log'); '${logDir.path}/revanced-manager_logcat_$dateTime.log',
);
final String logs = await Logcat.execute(); final String logs = await Logcat.execute();
logcat.writeAsStringSync(logs); logcat.writeAsStringSync(logs);
await Share.shareXFiles([XFile(logcat.path)]); await Share.shareXFiles([XFile(logcat.path)]);

View file

@ -5,6 +5,7 @@ import 'package:revanced_manager/gen/strings.g.dart';
import 'package:revanced_manager/ui/views/settings/settingsFragment/settings_manage_api_url.dart'; import 'package:revanced_manager/ui/views/settings/settingsFragment/settings_manage_api_url.dart';
import 'package:revanced_manager/ui/widgets/settingsView/settings_section.dart'; import 'package:revanced_manager/ui/widgets/settingsView/settings_section.dart';
import 'package:revanced_manager/ui/widgets/settingsView/settings_use_alternative_sources.dart'; import 'package:revanced_manager/ui/widgets/settingsView/settings_use_alternative_sources.dart';
import 'package:revanced_manager/ui/widgets/settingsView/settings_use_prereleases.dart';
class SDataSection extends StatelessWidget { class SDataSection extends StatelessWidget {
const SDataSection({super.key}); const SDataSection({super.key});
@ -15,6 +16,7 @@ class SDataSection extends StatelessWidget {
title: t.settingsView.dataSectionTitle, title: t.settingsView.dataSectionTitle,
children: const <Widget>[ children: const <Widget>[
SManageApiUrlUI(), SManageApiUrlUI(),
SUsePrereleases(),
SUseAlternativeSources(), SUseAlternativeSources(),
], ],
); );

View file

@ -0,0 +1,32 @@
import 'package:flutter/material.dart';
import 'package:revanced_manager/gen/strings.g.dart';
import 'package:revanced_manager/ui/views/settings/settings_viewmodel.dart';
import 'package:revanced_manager/ui/widgets/shared/haptics/haptic_switch_list_tile.dart';
class SUsePrereleases extends StatefulWidget {
const SUsePrereleases({super.key});
@override
State<SUsePrereleases> createState() => _SUsePrereleasesState();
}
final _settingsViewModel = SettingsViewModel();
class _SUsePrereleasesState extends State<SUsePrereleases> {
@override
Widget build(BuildContext context) {
return HapticSwitchListTile(
contentPadding: const EdgeInsets.symmetric(horizontal: 20.0),
title: Text(
t.settingsView.usePrereleasesLabel,
style: const TextStyle(fontSize: 20, fontWeight: FontWeight.w500),
),
subtitle: Text(t.settingsView.usePrereleasesHint),
value: _settingsViewModel.usePrereleases(),
onChanged: (value) async {
await _settingsViewModel.showUsePrereleasesDialog(context, value);
setState(() {});
},
);
}
}