fix: no need to bundle assets on manager's side anymore

This commit is contained in:
Alberto Ponces 2022-08-20 11:40:53 +01:00
parent 81107970d1
commit 2abe051483
3 changed files with 20 additions and 48 deletions

View File

@ -41,10 +41,10 @@ class MainActivity : FlutterActivity() {
mainChannel.setMethodCallHandler { call, result ->
when (call.method) {
"loadPatches" -> {
val zipPatchBundlePath = call.argument<String>("zipPatchBundlePath")
val jarPatchBundlePath = call.argument<String>("jarPatchBundlePath")
val cacheDirPath = call.argument<String>("cacheDirPath")
if (zipPatchBundlePath != null && cacheDirPath != null) {
loadPatches(result, zipPatchBundlePath, cacheDirPath)
if (jarPatchBundlePath != null && cacheDirPath != null) {
loadPatches(result, jarPatchBundlePath, cacheDirPath)
} else {
result.notImplemented()
}
@ -103,16 +103,16 @@ class MainActivity : FlutterActivity() {
fun loadPatches(
result: MethodChannel.Result,
zipPatchBundlePath: String,
jarPatchBundlePath: String,
cacheDirPath: String
) {
Thread(
Runnable {
patches.addAll(
DexPatchBundle(
zipPatchBundlePath,
jarPatchBundlePath,
DexClassLoader(
zipPatchBundlePath,
jarPatchBundlePath,
cacheDirPath,
null,
javaClass.classLoader

View File

@ -2,7 +2,6 @@ import 'dart:io';
import 'package:app_installer/app_installer.dart';
import 'package:device_apps/device_apps.dart';
import 'package:flutter/services.dart';
import 'package:flutter_archive/flutter_archive.dart';
import 'package:injectable/injectable.dart';
import 'package:path_provider/path_provider.dart';
import 'package:revanced_manager/models/patch.dart';
@ -22,7 +21,7 @@ class PatcherAPI {
Directory? _tmpDir;
Directory? _workDir;
Directory? _cacheDir;
File? _zipPatchBundleFile;
File? _jarPatchBundleFile;
File? _integrations;
File? _inputFile;
File? _patchedFile;
@ -42,27 +41,23 @@ class PatcherAPI {
if (_cacheDir == null) {
await initPatcher();
}
if (_zipPatchBundleFile == null) {
File? patchBundleDexFile = await _managerAPI.downloadPatches('.dex');
File? patchBundleJarFile = await _managerAPI.downloadPatches('.jar');
if (patchBundleDexFile != null && patchBundleJarFile != null) {
await joinPatchBundleFiles(patchBundleDexFile, patchBundleJarFile);
if (_zipPatchBundleFile != null) {
await patcherChannel.invokeMethod<bool>(
'loadPatches',
{
'zipPatchBundlePath': _zipPatchBundleFile!.path,
'cacheDirPath': _cacheDir!.path,
},
);
}
if (_jarPatchBundleFile == null) {
_jarPatchBundleFile = await _managerAPI.downloadPatches('.jar');
if (_jarPatchBundleFile != null) {
await patcherChannel.invokeMethod<bool>(
'loadPatches',
{
'jarPatchBundlePath': _jarPatchBundleFile!.path,
'cacheDirPath': _cacheDir!.path,
},
);
}
}
}
Future<List<ApplicationWithIcon>> getFilteredInstalledApps() async {
List<ApplicationWithIcon> filteredPackages = [];
if (_zipPatchBundleFile != null) {
if (_jarPatchBundleFile != null) {
try {
List<String>? patchesPackages = await patcherChannel
.invokeListMethod<String>('getCompatiblePackages');
@ -90,7 +85,7 @@ class PatcherAPI {
PatchedApplication? selectedApp,
) async {
List<Patch> filteredPatches = [];
if (_zipPatchBundleFile != null && selectedApp != null) {
if (_jarPatchBundleFile != null && selectedApp != null) {
try {
var patches =
await patcherChannel.invokeListMethod<Map<dynamic, dynamic>>(
@ -131,7 +126,7 @@ class PatcherAPI {
PatchedApplication? selectedApp,
) async {
List<Patch> appliedPatches = [];
if (_zipPatchBundleFile != null && selectedApp != null) {
if (_jarPatchBundleFile != null && selectedApp != null) {
try {
var patches =
await patcherChannel.invokeListMethod<Map<dynamic, dynamic>>(
@ -248,26 +243,4 @@ class PatcherAPI {
await _rootAPI.deleteApp(patchedApp.packageName, patchedApp.apkFilePath);
}
}
Future<void> joinPatchBundleFiles(
File patchBundleDexFile,
File patchBundleJarFile,
) async {
_zipPatchBundleFile = File('${_workDir!.path}/join.zip');
Directory joinDir = Directory('${_cacheDir!.path}/join');
try {
await ZipFile.extractToDirectory(
zipFile: patchBundleJarFile,
destinationDir: joinDir,
);
patchBundleDexFile.copySync('${joinDir.path}/classes.dex');
await ZipFile.createFromDirectory(
sourceDir: joinDir,
zipFile: _zipPatchBundleFile!,
recurseSubDirs: true,
);
} on Exception {
_zipPatchBundleFile = null;
}
}
}

View File

@ -21,7 +21,6 @@ dependencies:
file_picker: ^5.0.1
flutter:
sdk: flutter
flutter_archive: ^5.0.0
flutter_background: ^1.1.0
flutter_cache_manager: ^3.3.0
flutter_i18n: ^0.32.4