Skip to content

Commit

Permalink
feat(patcher): improve logs (ReVanced#1299)
Browse files Browse the repository at this point in the history
Co-authored-by: Ushie <[email protected]>
Co-authored-by: oSumAtrIX <[email protected]>
  • Loading branch information
3 people committed Oct 7, 2023
1 parent b1c9aed commit 8fd4fe0
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 6 deletions.
3 changes: 3 additions & 0 deletions assets/i18n/en_US.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
2 changes: 1 addition & 1 deletion lib/services/patcher_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
83 changes: 78 additions & 5 deletions lib/ui/views/installer/installer_viewmodel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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 = '';
Expand All @@ -38,6 +41,7 @@ class InstallerViewModel extends BaseViewModel {
bool hasErrors = false;
bool isCanceled = false;
bool cancel = false;
bool showPopupScreenshotWarning = true;

Future<void> initialize(BuildContext context) async {
isRooted = await _rootAPI.isRooted();
Expand All @@ -64,6 +68,12 @@ class InstallerViewModel extends BaseViewModel {
} // ignore
}
}
screenshotCallback.addListener(() {
if (showPopupScreenshotWarning) {
showPopupScreenshotWarning = false;
screenshotDetected(context);
}
});
await Wakelock.enable();
await handlePlatformChannelMethods();
await runPatcher();
Expand Down Expand Up @@ -169,6 +179,72 @@ class InstallerViewModel extends BaseViewModel {
}
}

Future<void> 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<void> 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: <Widget>[
CustomMaterialButton(
isFilled: false,
label: I18nText('noButton'),
onPressed: () {
Navigator.of(context).pop();
},
),
CustomMaterialButton(
label: I18nText('yesButton'),
onPressed: () {
copyLogs();
showPopupScreenshotWarning = true;
Navigator.of(context).pop();
},
),
],
),
);
}

Future<void> installTypeDialog(BuildContext context) async {
final ValueNotifier<int> installType = ValueNotifier(0);
if (isRooted) {
Expand Down Expand Up @@ -316,10 +392,6 @@ class InstallerViewModel extends BaseViewModel {
}
}

void exportLog() {
_patcherAPI.exportPatcherLog(logs);
}

Future<void> cleanPatcher() async {
try {
_patcherAPI.cleanPatcher();
Expand All @@ -343,7 +415,7 @@ class InstallerViewModel extends BaseViewModel {
exportResult();
break;
case 1:
exportLog();
copyLogs();
break;
}
}
Expand All @@ -365,6 +437,7 @@ class InstallerViewModel extends BaseViewModel {
} else {
_patcherAPI.cleanPatcher();
}
screenshotCallback.dispose();
Navigator.of(context).pop();
return true;
}
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 8fd4fe0

Please sign in to comment.