Skip to content

Commit

Permalink
feat: updated logs (ReVanced#1526)
Browse files Browse the repository at this point in the history
(cherry picked from commit 7931eb9)
  • Loading branch information
BenjaminHalko authored and kitadai31 committed Jul 28, 2024
1 parent 14b93cb commit 8eba6a6
Showing 1 changed file with 44 additions and 11 deletions.
55 changes: 44 additions & 11 deletions lib/ui/views/installer/installer_viewmodel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -179,17 +179,48 @@ class InstallerViewModel extends BaseViewModel {
}
}

void _trimLogs(List<String> logLines, String keyword, String? newString) {
final lineCount = logLines.where((line) => line.endsWith(keyword)).length;
final index = logLines.indexWhere((line) => line.endsWith(keyword));
if (newString != null && lineCount > 0) {
logLines.insert(index, newString.replaceAll('{lineCount}', lineCount.toString()));
}
logLines.removeWhere((lines) => lines.endsWith(keyword));
}

dynamic _getPatchOptionValue(String patchName, Option option) {
final Option? savedOption = _managerAPI.getPatchOption(_app.packageName, patchName, option.key);
if (savedOption != null) {
return savedOption.value;
} else {
return option.value;
}
}

String _formatPatches(List<Patch> patches) {
if (patches.isEmpty) {
return 'None';
}
return patches.map((p) => p.name + (p.options.isEmpty ? '' : ' [${p.options.map((o) => '${o.title}: ${_getPatchOptionValue(p.name, o)}').join(", ")}]')).toList().join(', ');
}

Future<void> copyLogs() async {
final info = await AboutInfo.getInfo();
dynamic getValue(String patchName, Option option) {
final Option? savedOption = _managerAPI.getPatchOption(_app.packageName, patchName, option.key);
if (savedOption != null) {
return savedOption.value;
} else {
return option.value;
}
}

// Trim out extra lines
final logsTrimmed = logs.split('\n');
_trimLogs(logsTrimmed, 'succeeded', 'Applied {lineCount} patches');
_trimLogs(logsTrimmed, '.dex', 'Compiled {lineCount} dex files');

// Get patches added / removed
final defaultPatches = _patcherAPI.getFilteredPatches(_app.packageName).where((p) => !p.excluded).toList();
final patchesAdded = _patches.where((p) => !defaultPatches.contains(p)).toList();
final patchesRemoved = defaultPatches.where((p) => !_patches.contains(p)).toList();

// Options changed
final patchesChanged = defaultPatches.where((p) => _patches.contains(p) && p.options.any((o) => _getPatchOptionValue(p.name, o) != o.value)).toList();

// Add Info
final formattedLogs = [
'- Device Info',
'ReVanced Manager: ${info['version']}',
Expand All @@ -202,8 +233,10 @@ class InstallerViewModel extends BaseViewModel {
'\n- Patch Info',
'App: ${_app.packageName} v${_app.version}',
'Patches version: ${_managerAPI.patchesVersion}',
'Patches: ${_patches.map((p) => p.name + (p.options.isEmpty ? '' : ' [${p.options.map((o) => '${o.title}: ${getValue(p.name, o)}').join(", ")}]')).toList().join(", ")}',

'Patches added: ${_formatPatches(patchesAdded)}',
'Patches removed: ${_formatPatches(patchesRemoved)}',
'Options changed: ${_formatPatches(patchesChanged)}',

'\n- Settings',
'Allow changing patch selection: ${_managerAPI.isPatchesChangeEnabled()}',
'Version compatibility check: ${_managerAPI.isVersionCompatibilityCheckEnabled()}',
Expand All @@ -213,7 +246,7 @@ class InstallerViewModel extends BaseViewModel {
'Integration source: ${_managerAPI.getIntegrationsRepo()}',

'\n- Logs',
logs,
logsTrimmed.join('\n'),
];

Clipboard.setData(ClipboardData(text: formattedLogs.join('\n')));
Expand Down

0 comments on commit 8eba6a6

Please sign in to comment.