Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Adding support for Exporting APK #439

Merged
merged 2 commits into from
Nov 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions assets/i18n/en_US.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
"notificationTitle": "ReVanced Manager is patching",
"notificationText": "Tap to return to the installer",
"shareApkMenuOption": "Share APK",
"exportApkMenuOption": "Export APK",
"shareLogMenuOption": "Share log",
"installErrorDialogTitle": "Error",
"installErrorDialogText1": "Root install is not possible with the current patches selection.\nRepatch your app or choose non-root install.",
Expand Down
33 changes: 31 additions & 2 deletions lib/services/patcher_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
Expand All @@ -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');
Expand Down
11 changes: 10 additions & 1 deletion lib/ui/views/installer/installer_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,16 @@ class InstallerView extends StatelessWidget {
),
),
),
1: I18nText(
1: I18nText(
'installerView.exportApkMenuOption',
child: const Text(
'',
style: TextStyle(
fontWeight: FontWeight.bold,
),
),
),
2: I18nText(
'installerView.shareLogMenuOption',
child: const Text(
'',
Expand Down
11 changes: 11 additions & 0 deletions lib/ui/views/installer/installer_viewmodel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,14 @@ class InstallerViewModel extends BaseViewModel {
}
}

void exportResult() {
try {
_patcherAPI.exportPatchedFile(_app.name, _app.version);
} on Exception catch (e, s) {
Sentry.captureException(e, stackTrace: s);
}
}

void shareResult() {
try {
_patcherAPI.sharePatchedFile(_app.name, _app.version);
Expand Down Expand Up @@ -250,6 +258,9 @@ class InstallerViewModel extends BaseViewModel {
shareResult();
break;
case 1:
exportResult();
break;
case 2:
shareLog();
break;
}
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ dependencies:
app_installer: ^1.1.0
collection: ^1.16.0
cross_connectivity: ^3.0.5
cr_file_saver: ^0.0.1+2
device_apps:
git:
url: https://github.com/ponces/flutter_plugin_device_apps
Expand Down