From 8fd4fe0e5522e9723f1057d6c6814d2dd5b94753 Mon Sep 17 00:00:00 2001 From: Benjamin <73490201+BenjaminHalko@users.noreply.github.com> Date: Thu, 5 Oct 2023 09:16:20 -0700 Subject: [PATCH] feat(patcher): improve logs (#1299) Co-authored-by: Ushie Co-authored-by: oSumAtrIX --- assets/i18n/en_US.json | 3 + lib/services/patcher_api.dart | 2 +- .../views/installer/installer_viewmodel.dart | 83 +++++++++++++++++-- pubspec.yaml | 1 + 4 files changed, 83 insertions(+), 6 deletions(-) diff --git a/assets/i18n/en_US.json b/assets/i18n/en_US.json index d3fe112855..a7954b1bbc 100644 --- a/assets/i18n/en_US.json +++ b/assets/i18n/en_US.json @@ -158,6 +158,9 @@ "exportApkButtonTooltip": "Export patched APK", "exportLogButtonTooltip": "Export log", + "screenshotDetected": "A screenshot has been detected. If you are trying to share the log, please share a text copy instead.\n\nCopy log to clipboard?", + "copiedToClipboard": "Copied log to clipboard", + "noExit": "Installer is still running, cannot exit..." }, "settingsView": { diff --git a/lib/services/patcher_api.dart b/lib/services/patcher_api.dart index dc4ffabd20..0d648f6955 100644 --- a/lib/services/patcher_api.dart +++ b/lib/services/patcher_api.dart @@ -273,7 +273,7 @@ class PatcherAPI { .replaceAll(':', '') .replaceAll('T', '') .replaceAll('.', ''); - final String fileName = 'revanced-manager_patcher_$dateTime.log'; + final String fileName = 'revanced-manager_patcher_$dateTime.txt'; final File log = File('${logDir.path}/$fileName'); log.writeAsStringSync(logs); CRFileSaver.saveFileWithDialog( diff --git a/lib/ui/views/installer/installer_viewmodel.dart b/lib/ui/views/installer/installer_viewmodel.dart index 8d54987d7c..4ef037996d 100644 --- a/lib/ui/views/installer/installer_viewmodel.dart +++ b/lib/ui/views/installer/installer_viewmodel.dart @@ -15,6 +15,8 @@ import 'package:revanced_manager/services/root_api.dart'; import 'package:revanced_manager/services/toast.dart'; import 'package:revanced_manager/ui/views/patcher/patcher_viewmodel.dart'; import 'package:revanced_manager/ui/widgets/shared/custom_material_button.dart'; +import 'package:revanced_manager/utils/about_info.dart'; +import 'package:screenshot_callback/screenshot_callback.dart'; import 'package:stacked/stacked.dart'; import 'package:wakelock/wakelock.dart'; @@ -29,6 +31,7 @@ class InstallerViewModel extends BaseViewModel { 'app.revanced.manager.flutter/installer', ); final ScrollController scrollController = ScrollController(); + final ScreenshotCallback screenshotCallback = ScreenshotCallback(); double? progress = 0.0; String logs = ''; String headerLogs = ''; @@ -38,6 +41,7 @@ class InstallerViewModel extends BaseViewModel { bool hasErrors = false; bool isCanceled = false; bool cancel = false; + bool showPopupScreenshotWarning = true; Future initialize(BuildContext context) async { isRooted = await _rootAPI.isRooted(); @@ -64,6 +68,12 @@ class InstallerViewModel extends BaseViewModel { } // ignore } } + screenshotCallback.addListener(() { + if (showPopupScreenshotWarning) { + showPopupScreenshotWarning = false; + screenshotDetected(context); + } + }); await Wakelock.enable(); await handlePlatformChannelMethods(); await runPatcher(); @@ -169,6 +179,72 @@ class InstallerViewModel extends BaseViewModel { } } + Future copyLogs() async { + final info = await AboutInfo.getInfo(); + + final formattedLogs = [ + '```', + '~ Device Info', + 'ReVanced Manager: ${info['version']}', + 'Build: ${info['flavor']}', + 'Model: ${info['model']}', + 'Android version: ${info['androidVersion']}', + 'Supported architectures: ${info['supportedArch'].join(", ")}', + + '\n~ Patch Info', + 'App: ${_app.packageName} v${_app.version}', + 'Patches version: ${_managerAPI.patchesVersion}', + 'Patches: ${_patches.map((p) => p.name).toList().join(", ")}', + + '\n~ Settings', + 'Enabled changing patches: ${_managerAPI.isPatchesChangeEnabled()}', + 'Enabled universal patches: ${_managerAPI.areUniversalPatchesEnabled()}', + 'Enabled experimental patches: ${_managerAPI.areExperimentalPatchesEnabled()}', + 'Patches source: ${_managerAPI.getPatchesRepo()}', + 'Integration source: ${_managerAPI.getIntegrationsRepo()}', + + '\n~ Logs', + logs, + '```', + ]; + + Clipboard.setData(ClipboardData(text: formattedLogs.join('\n'))); + _toast.showBottom('installerView.copiedToClipboard'); + } + + Future screenshotDetected(BuildContext context) async { + await showDialog( + context: context, + builder: (context) => AlertDialog( + title: I18nText( + 'warning', + ), + backgroundColor: Theme.of(context).colorScheme.secondaryContainer, + icon: const Icon(Icons.warning), + content: SingleChildScrollView( + child: I18nText('installerView.screenshotDetected'), + ), + actions: [ + CustomMaterialButton( + isFilled: false, + label: I18nText('noButton'), + onPressed: () { + Navigator.of(context).pop(); + }, + ), + CustomMaterialButton( + label: I18nText('yesButton'), + onPressed: () { + copyLogs(); + showPopupScreenshotWarning = true; + Navigator.of(context).pop(); + }, + ), + ], + ), + ); + } + Future installTypeDialog(BuildContext context) async { final ValueNotifier installType = ValueNotifier(0); if (isRooted) { @@ -316,10 +392,6 @@ class InstallerViewModel extends BaseViewModel { } } - void exportLog() { - _patcherAPI.exportPatcherLog(logs); - } - Future cleanPatcher() async { try { _patcherAPI.cleanPatcher(); @@ -343,7 +415,7 @@ class InstallerViewModel extends BaseViewModel { exportResult(); break; case 1: - exportLog(); + copyLogs(); break; } } @@ -365,6 +437,7 @@ class InstallerViewModel extends BaseViewModel { } else { _patcherAPI.cleanPatcher(); } + screenshotCallback.dispose(); Navigator.of(context).pop(); return true; } diff --git a/pubspec.yaml b/pubspec.yaml index 1866ef3ef9..9c550f7f48 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -75,6 +75,7 @@ dependencies: flutter_markdown: ^0.6.14 dio_cache_interceptor: ^3.4.0 install_plugin: ^2.1.0 + screenshot_callback: ^3.0.1 synchronized: ^3.1.0 dev_dependencies: