mirror of
https://github.com/revanced/revanced-manager.git
synced 2025-05-01 14:34:24 +02:00
fix: patcher cleaning and improve patches load
This commit is contained in:
parent
af8e753ea6
commit
ea532b294e
@ -28,7 +28,9 @@ class PatcherAPI {
|
||||
File? _outFile;
|
||||
|
||||
Future<void> initPatcher() async {
|
||||
_tmpDir = await getTemporaryDirectory();
|
||||
Directory appCache = await getTemporaryDirectory();
|
||||
_tmpDir = Directory('$appCache/patcher');
|
||||
_tmpDir!.createSync();
|
||||
_workDir = _tmpDir!.createTempSync('tmp-');
|
||||
_inputFile = File('${_workDir!.path}/base.apk');
|
||||
_patchedFile = File('${_workDir!.path}/patched.apk');
|
||||
@ -37,13 +39,14 @@ class PatcherAPI {
|
||||
_cacheDir!.createSync();
|
||||
}
|
||||
|
||||
Future<void> loadPatches() async {
|
||||
if (_cacheDir == null) {
|
||||
Future<bool> loadPatches() async {
|
||||
if (_tmpDir == null) {
|
||||
await initPatcher();
|
||||
}
|
||||
if (_jarPatchBundleFile == null) {
|
||||
_jarPatchBundleFile = await _managerAPI.downloadPatches('.jar');
|
||||
if (_jarPatchBundleFile != null) {
|
||||
try {
|
||||
await patcherChannel.invokeMethod<bool>(
|
||||
'loadPatches',
|
||||
{
|
||||
@ -51,13 +54,18 @@ class PatcherAPI {
|
||||
'cacheDirPath': _cacheDir!.path,
|
||||
},
|
||||
);
|
||||
} on Exception {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return _jarPatchBundleFile != null;
|
||||
}
|
||||
|
||||
Future<List<ApplicationWithIcon>> getFilteredInstalledApps() async {
|
||||
List<ApplicationWithIcon> filteredPackages = [];
|
||||
if (_jarPatchBundleFile != null) {
|
||||
bool isLoaded = await loadPatches();
|
||||
if (isLoaded) {
|
||||
try {
|
||||
List<String>? patchesPackages = await patcherChannel
|
||||
.invokeListMethod<String>('getCompatiblePackages');
|
||||
@ -85,7 +93,9 @@ class PatcherAPI {
|
||||
PatchedApplication? selectedApp,
|
||||
) async {
|
||||
List<Patch> filteredPatches = [];
|
||||
if (_jarPatchBundleFile != null && selectedApp != null) {
|
||||
if (selectedApp != null) {
|
||||
bool isLoaded = await loadPatches();
|
||||
if (isLoaded) {
|
||||
try {
|
||||
var patches =
|
||||
await patcherChannel.invokeListMethod<Map<dynamic, dynamic>>(
|
||||
@ -120,6 +130,7 @@ class PatcherAPI {
|
||||
return List.empty();
|
||||
}
|
||||
}
|
||||
}
|
||||
return filteredPatches;
|
||||
}
|
||||
|
||||
@ -127,7 +138,9 @@ class PatcherAPI {
|
||||
PatchedApplication? selectedApp,
|
||||
) async {
|
||||
List<Patch> appliedPatches = [];
|
||||
if (_jarPatchBundleFile != null && selectedApp != null) {
|
||||
if (selectedApp != null) {
|
||||
bool isLoaded = await loadPatches();
|
||||
if (isLoaded) {
|
||||
try {
|
||||
var patches =
|
||||
await patcherChannel.invokeListMethod<Map<dynamic, dynamic>>(
|
||||
@ -161,6 +174,7 @@ class PatcherAPI {
|
||||
return List.empty();
|
||||
}
|
||||
}
|
||||
}
|
||||
return appliedPatches;
|
||||
}
|
||||
|
||||
@ -215,17 +229,16 @@ class PatcherAPI {
|
||||
}
|
||||
|
||||
void cleanPatcher() {
|
||||
if (_workDir != null) {
|
||||
_workDir!.deleteSync(recursive: true);
|
||||
if (_tmpDir != null) {
|
||||
_tmpDir!.deleteSync(recursive: true);
|
||||
_tmpDir = null;
|
||||
}
|
||||
}
|
||||
|
||||
bool sharePatchedFile(String appName, String version) {
|
||||
if (_outFile != null) {
|
||||
String path = _tmpDir!.path;
|
||||
String prefix = appName.toLowerCase().replaceAll(' ', '-');
|
||||
String sharePath = '$path/$prefix-revanced_v$version.apk';
|
||||
File share = _outFile!.copySync(sharePath);
|
||||
File share = _outFile!.renameSync('$prefix-revanced_v$version.apk');
|
||||
ShareExtend.share(share.path, 'file');
|
||||
return true;
|
||||
} else {
|
||||
|
@ -95,7 +95,7 @@ class InstallerView extends StatelessWidget {
|
||||
),
|
||||
onWillPop: () async {
|
||||
if (!model.isPatching) {
|
||||
model.cleanWorkplace();
|
||||
model.cleanPatcher();
|
||||
Navigator.of(context).pop();
|
||||
}
|
||||
return false;
|
||||
|
@ -162,7 +162,7 @@ class InstallerViewModel extends BaseViewModel {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> cleanWorkplace() async {
|
||||
Future<void> cleanPatcher() async {
|
||||
_patcherAPI.cleanPatcher();
|
||||
locator<PatcherViewModel>().selectedApp = null;
|
||||
locator<PatcherViewModel>().selectedPatches.clear();
|
||||
|
Loading…
x
Reference in New Issue
Block a user