feat: output suggested version into patch log (#1557)

Signed-off-by: validcube <pun.butrach@gmail.com>
This commit is contained in:
Pun Butrach 2023-12-11 11:26:52 +07:00 committed by GitHub
parent d9a316abbb
commit 637641cf54
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -183,13 +183,15 @@ class InstallerViewModel extends BaseViewModel {
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.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);
final Option? savedOption =
_managerAPI.getPatchOption(_app.packageName, patchName, option.key);
if (savedOption != null) {
return savedOption.value;
} else {
@ -201,7 +203,24 @@ class InstallerViewModel extends BaseViewModel {
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(', ');
return patches
.map((p) =>
p.name +
(p.options.isEmpty
? ''
: ' [${p.options.map((o) => '${o.title}: ${_getPatchOptionValue(p.name, o)}').join(", ")}]'))
.toList()
.join(', ');
}
String _getSuggestedVersion(String packageName) {
String suggestedVersion = _patcherAPI.getSuggestedVersion(_app.packageName);
if (suggestedVersion.isEmpty) {
suggestedVersion = 'Any';
} else {
suggestedVersion = 'v$suggestedVersion';
}
return suggestedVersion;
}
Future<void> copyLogs() async {
@ -213,12 +232,21 @@ class InstallerViewModel extends BaseViewModel {
_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();
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();
final patchesChanged = defaultPatches
.where((p) =>
_patches.contains(p) &&
p.options.any((o) => _getPatchOptionValue(p.name, o) != o.value))
.toList();
// Add Info
final formattedLogs = [
@ -228,21 +256,21 @@ class InstallerViewModel extends BaseViewModel {
'Model: ${info['model']}',
'Android version: ${info['androidVersion']}',
'Supported architectures: ${info['supportedArch'].join(", ")}',
'Root permissions: ${isRooted ? 'Yes' : 'No'}',
'Root permissions: ${isRooted ? 'Yes' : 'No'}', //
'\n- Patch Info',
'App: ${_app.packageName} v${_app.version}',
'App: ${_app.packageName} v${_app.version} (Suggested: ${_getSuggestedVersion(_app.packageName)})',
'Patches version: ${_managerAPI.patchesVersion}',
'Patches added: ${_formatPatches(patchesAdded)}',
'Patches removed: ${_formatPatches(patchesRemoved)}',
'Options changed: ${_formatPatches(patchesChanged)}',
'Options changed: ${_formatPatches(patchesChanged)}', //
'\n- Settings',
'Allow changing patch selection: ${_managerAPI.isPatchesChangeEnabled()}',
'Version compatibility check: ${_managerAPI.isVersionCompatibilityCheckEnabled()}',
'Show universal patches: ${_managerAPI.areUniversalPatchesEnabled()}',
'Patches source: ${_managerAPI.getPatchesRepo()}',
'Integration source: ${_managerAPI.getIntegrationsRepo()}',
'Integration source: ${_managerAPI.getIntegrationsRepo()}', //
'\n- Logs',
logsTrimmed.join('\n'),