mirror of
https://github.com/revanced/revanced-manager
synced 2024-05-14 13:56:57 +02:00
feat: add support for shared patches (#577)
* fix: avoid npe if a patch has empty compatible package. * feat: support for shared patches * fix: incorrect bool check and cleanup Co-authored-by: Aunali321 <aunvakil.aa@gmail.com>
This commit is contained in:
parent
4f8aec6a05
commit
ff90dae695
@ -174,7 +174,7 @@ class MainActivity : FlutterActivity() {
|
|||||||
javaClass.classLoader
|
javaClass.classLoader
|
||||||
)
|
)
|
||||||
).loadPatches().filter { patch ->
|
).loadPatches().filter { patch ->
|
||||||
patch.compatiblePackages!!.any { it.name == patcher.context.packageMetadata.packageName } &&
|
(patch.compatiblePackages?.any { it.name == patcher.context.packageMetadata.packageName } == true || patch.compatiblePackages.isNullOrEmpty()) &&
|
||||||
selectedPatches.any { it == patch.patchName }
|
selectedPatches.any { it == patch.patchName }
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -54,6 +54,25 @@ class PatcherAPI {
|
|||||||
|
|
||||||
Future<List<ApplicationWithIcon>> getFilteredInstalledApps() async {
|
Future<List<ApplicationWithIcon>> getFilteredInstalledApps() async {
|
||||||
List<ApplicationWithIcon> filteredApps = [];
|
List<ApplicationWithIcon> filteredApps = [];
|
||||||
|
bool? allAppsIncluded =
|
||||||
|
_patches.any((patch) => patch.compatiblePackages.isEmpty);
|
||||||
|
if (allAppsIncluded) {
|
||||||
|
var allPackages = await DeviceApps.getInstalledApplications(
|
||||||
|
includeAppIcons: true,
|
||||||
|
onlyAppsWithLaunchIntent: true,
|
||||||
|
);
|
||||||
|
allPackages.forEach((pkg) async {
|
||||||
|
if (!filteredApps.any((app) => app.packageName == pkg.packageName)) {
|
||||||
|
var appInfo = await DeviceApps.getApp(
|
||||||
|
pkg.packageName,
|
||||||
|
true,
|
||||||
|
) as ApplicationWithIcon?;
|
||||||
|
if (appInfo != null) {
|
||||||
|
filteredApps.add(appInfo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
for (Patch patch in _patches) {
|
for (Patch patch in _patches) {
|
||||||
for (Package package in patch.compatiblePackages) {
|
for (Package package in patch.compatiblePackages) {
|
||||||
try {
|
try {
|
||||||
@ -76,11 +95,19 @@ class PatcherAPI {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<List<Patch>> getFilteredPatches(String packageName) async {
|
Future<List<Patch>> getFilteredPatches(String packageName) async {
|
||||||
return _patches
|
List<Patch> filteredPatches = [];
|
||||||
.where((patch) =>
|
_patches.forEach((patch) {
|
||||||
!patch.name.contains('settings') &&
|
if (patch.compatiblePackages.isEmpty) {
|
||||||
patch.compatiblePackages.any((pack) => pack.name == packageName))
|
filteredPatches.add(patch);
|
||||||
.toList();
|
} else {
|
||||||
|
if (!patch.name.contains('settings') &&
|
||||||
|
patch.compatiblePackages.any((pack) => pack.name == packageName)
|
||||||
|
) {
|
||||||
|
filteredPatches.add(patch);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return filteredPatches;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<List<Patch>> getAppliedPatches(List<String> appliedPatches) async {
|
Future<List<Patch>> getAppliedPatches(List<String> appliedPatches) async {
|
||||||
@ -229,7 +256,6 @@ class PatcherAPI {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void exportPatchedFile(String appName, String version) {
|
void exportPatchedFile(String appName, String version) {
|
||||||
try {
|
try {
|
||||||
if (_outFile != null) {
|
if (_outFile != null) {
|
||||||
@ -238,13 +264,12 @@ class PatcherAPI {
|
|||||||
// This is temporary workaround to populate initial file name
|
// This is temporary workaround to populate initial file name
|
||||||
// ref: https://github.com/Cleveroad/cr_file_saver/issues/7
|
// ref: https://github.com/Cleveroad/cr_file_saver/issues/7
|
||||||
int lastSeparator = _outFile!.path.lastIndexOf('/');
|
int lastSeparator = _outFile!.path.lastIndexOf('/');
|
||||||
String newSourcePath = _outFile!.path.substring(0, lastSeparator + 1) + newName;
|
String newSourcePath =
|
||||||
|
_outFile!.path.substring(0, lastSeparator + 1) + newName;
|
||||||
_outFile!.copySync(newSourcePath);
|
_outFile!.copySync(newSourcePath);
|
||||||
|
|
||||||
CRFileSaver.saveFileWithDialog(SaveFileDialogParams(
|
CRFileSaver.saveFileWithDialog(SaveFileDialogParams(
|
||||||
sourceFilePath: newSourcePath,
|
sourceFilePath: newSourcePath, destinationFileName: newName));
|
||||||
destinationFileName: newName
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
} on Exception catch (e, s) {
|
} on Exception catch (e, s) {
|
||||||
Sentry.captureException(e, stackTrace: s);
|
Sentry.captureException(e, stackTrace: s);
|
||||||
@ -270,7 +295,6 @@ class PatcherAPI {
|
|||||||
String prefix = appName.toLowerCase().replaceAll(' ', '-');
|
String prefix = appName.toLowerCase().replaceAll(' ', '-');
|
||||||
String newName = '$prefix-revanced_v$version.apk';
|
String newName = '$prefix-revanced_v$version.apk';
|
||||||
return newName;
|
return newName;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> sharePatcherLog(String logs) async {
|
Future<void> sharePatcherLog(String logs) async {
|
||||||
|
@ -147,7 +147,7 @@ class PatchesSelectorViewModel extends BaseViewModel {
|
|||||||
|
|
||||||
bool isPatchSupported(Patch patch) {
|
bool isPatchSupported(Patch patch) {
|
||||||
PatchedApplication app = locator<PatcherViewModel>().selectedApp!;
|
PatchedApplication app = locator<PatcherViewModel>().selectedApp!;
|
||||||
return patch.compatiblePackages.any((pack) =>
|
return patch.compatiblePackages.isEmpty || patch.compatiblePackages.any((pack) =>
|
||||||
pack.name == app.packageName &&
|
pack.name == app.packageName &&
|
||||||
(pack.versions.isEmpty || pack.versions.contains(app.version)));
|
(pack.versions.isEmpty || pack.versions.contains(app.version)));
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user