feat: Adding support for Exporting APK (#439)

* feat: Adding Export APK support

* Using cr_file_saver to simplify export
This commit is contained in:
nkitsaini
2022-11-02 17:22:40 +05:30
committed by GitHub
parent 6b999b0a0c
commit dc47da75f2
5 changed files with 54 additions and 3 deletions

View File

@ -12,6 +12,7 @@ import 'package:revanced_manager/services/manager_api.dart';
import 'package:revanced_manager/services/root_api.dart';
import 'package:sentry_flutter/sentry_flutter.dart';
import 'package:share_extend/share_extend.dart';
import 'package:cr_file_saver/file_saver.dart';
@lazySingleton
class PatcherAPI {
@ -228,11 +229,32 @@ class PatcherAPI {
return false;
}
void exportPatchedFile(String appName, String version) {
try {
if (_outFile != null) {
String newName = _getFileName(appName, version);
// This is temporary workaround to populate initial file name
// ref: https://github.com/Cleveroad/cr_file_saver/issues/7
int lastSeparator = _outFile!.path.lastIndexOf('/');
String newSourcePath = _outFile!.path.substring(0, lastSeparator + 1) + newName;
_outFile!.copySync(newSourcePath);
CRFileSaver.saveFileWithDialog(SaveFileDialogParams(
sourceFilePath: newSourcePath,
destinationFileName: newName
));
}
} on Exception catch (e, s) {
Sentry.captureException(e, stackTrace: s);
}
}
void sharePatchedFile(String appName, String version) {
try {
if (_outFile != null) {
String prefix = appName.toLowerCase().replaceAll(' ', '-');
String newName = '$prefix-revanced_v$version.apk';
String newName = _getFileName(appName, version);
int lastSeparator = _outFile!.path.lastIndexOf('/');
String newPath =
_outFile!.path.substring(0, lastSeparator + 1) + newName;
@ -244,6 +266,13 @@ class PatcherAPI {
}
}
String _getFileName(String appName, String version) {
String prefix = appName.toLowerCase().replaceAll(' ', '-');
String newName = '$prefix-revanced_v$version.apk';
return newName;
}
Future<void> sharePatcherLog(String logs) async {
Directory appCache = await getTemporaryDirectory();
Directory logDir = Directory('${appCache.path}/logs');