mirror of
https://github.com/ReVanced/revanced-manager.git
synced 2025-05-11 13:05:37 +02:00
feat: update rules of analysis_options.yaml. and solved all problems (#665)
* update rules of analysis_options.yaml. and solved all problems * refactor: fix remaining problems --------- Co-authored-by: Ushie <ushiekane@gmail.com>
This commit is contained in:
parent
f5bc1a996f
commit
a54ca799b9
62 changed files with 804 additions and 643 deletions
|
@ -1,7 +1,10 @@
|
|||
import 'dart:io';
|
||||
|
||||
import 'package:app_installer/app_installer.dart';
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:cr_file_saver/file_saver.dart';
|
||||
import 'package:device_apps/device_apps.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:injectable/injectable.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
|
@ -12,7 +15,6 @@ 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 {
|
||||
|
@ -29,7 +31,7 @@ class PatcherAPI {
|
|||
|
||||
Future<void> initialize() async {
|
||||
await _loadPatches();
|
||||
Directory appCache = await getTemporaryDirectory();
|
||||
final Directory appCache = await getTemporaryDirectory();
|
||||
_dataDir = await getExternalStorageDirectory() ?? appCache;
|
||||
_tmpDir = Directory('${appCache.path}/patcher');
|
||||
_keyStoreFile = File('${_dataDir.path}/revanced-manager.keystore');
|
||||
|
@ -53,18 +55,21 @@ class PatcherAPI {
|
|||
}
|
||||
}
|
||||
|
||||
Future<List<ApplicationWithIcon>> getFilteredInstalledApps(bool showUniversalPatches) async {
|
||||
List<ApplicationWithIcon> filteredApps = [];
|
||||
bool? allAppsIncluded =
|
||||
_patches.any((patch) => patch.compatiblePackages.isEmpty) && showUniversalPatches;
|
||||
Future<List<ApplicationWithIcon>> getFilteredInstalledApps(
|
||||
bool showUniversalPatches,
|
||||
) async {
|
||||
final List<ApplicationWithIcon> filteredApps = [];
|
||||
final bool allAppsIncluded =
|
||||
_patches.any((patch) => patch.compatiblePackages.isEmpty) &&
|
||||
showUniversalPatches;
|
||||
if (allAppsIncluded) {
|
||||
var allPackages = await DeviceApps.getInstalledApplications(
|
||||
final allPackages = await DeviceApps.getInstalledApplications(
|
||||
includeAppIcons: true,
|
||||
onlyAppsWithLaunchIntent: true,
|
||||
);
|
||||
allPackages.forEach((pkg) async {
|
||||
for (final pkg in allPackages) {
|
||||
if (!filteredApps.any((app) => app.packageName == pkg.packageName)) {
|
||||
var appInfo = await DeviceApps.getApp(
|
||||
final appInfo = await DeviceApps.getApp(
|
||||
pkg.packageName,
|
||||
true,
|
||||
) as ApplicationWithIcon?;
|
||||
|
@ -72,13 +77,13 @@ class PatcherAPI {
|
|||
filteredApps.add(appInfo);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
for (Patch patch in _patches) {
|
||||
for (Package package in patch.compatiblePackages) {
|
||||
for (final Patch patch in _patches) {
|
||||
for (final Package package in patch.compatiblePackages) {
|
||||
try {
|
||||
if (!filteredApps.any((app) => app.packageName == package.name)) {
|
||||
ApplicationWithIcon? app = await DeviceApps.getApp(
|
||||
final ApplicationWithIcon? app = await DeviceApps.getApp(
|
||||
package.name,
|
||||
true,
|
||||
) as ApplicationWithIcon?;
|
||||
|
@ -97,12 +102,14 @@ class PatcherAPI {
|
|||
|
||||
List<Patch> getFilteredPatches(String packageName) {
|
||||
if (!filteredPatches.keys.contains(packageName)) {
|
||||
List<Patch> patches = _patches
|
||||
.where((patch) =>
|
||||
patch.compatiblePackages.isEmpty ||
|
||||
!patch.name.contains('settings') &&
|
||||
patch.compatiblePackages
|
||||
.any((pack) => pack.name == packageName))
|
||||
final List<Patch> patches = _patches
|
||||
.where(
|
||||
(patch) =>
|
||||
patch.compatiblePackages.isEmpty ||
|
||||
!patch.name.contains('settings') &&
|
||||
patch.compatiblePackages
|
||||
.any((pack) => pack.name == packageName),
|
||||
)
|
||||
.toList();
|
||||
filteredPatches[packageName] = patches;
|
||||
}
|
||||
|
@ -155,7 +162,7 @@ class PatcherAPI {
|
|||
String originalFilePath,
|
||||
) async {
|
||||
try {
|
||||
bool hasRootPermissions = await _rootAPI.hasRootPermissions();
|
||||
final bool hasRootPermissions = await _rootAPI.hasRootPermissions();
|
||||
if (hasRootPermissions) {
|
||||
originalFilePath = await _rootAPI.getOriginalFilePath(
|
||||
packageName,
|
||||
|
@ -174,11 +181,11 @@ class PatcherAPI {
|
|||
String originalFilePath,
|
||||
List<Patch> selectedPatches,
|
||||
) async {
|
||||
bool mergeIntegrations = await needsIntegrations(selectedPatches);
|
||||
bool includeSettings = await needsSettingsPatch(selectedPatches);
|
||||
final bool mergeIntegrations = await needsIntegrations(selectedPatches);
|
||||
final bool includeSettings = await needsSettingsPatch(selectedPatches);
|
||||
if (includeSettings) {
|
||||
try {
|
||||
Patch? settingsPatch = _patches.firstWhereOrNull(
|
||||
final Patch? settingsPatch = _patches.firstWhereOrNull(
|
||||
(patch) =>
|
||||
patch.name.contains('settings') &&
|
||||
patch.compatiblePackages.any((pack) => pack.name == packageName),
|
||||
|
@ -191,7 +198,7 @@ class PatcherAPI {
|
|||
// ignore
|
||||
}
|
||||
}
|
||||
File? patchBundleFile = await _managerAPI.downloadPatches();
|
||||
final File? patchBundleFile = await _managerAPI.downloadPatches();
|
||||
File? integrationsFile;
|
||||
if (mergeIntegrations) {
|
||||
integrationsFile = await _managerAPI.downloadIntegrations();
|
||||
|
@ -199,11 +206,11 @@ class PatcherAPI {
|
|||
if (patchBundleFile != null) {
|
||||
_dataDir.createSync();
|
||||
_tmpDir.createSync();
|
||||
Directory workDir = _tmpDir.createTempSync('tmp-');
|
||||
File inputFile = File('${workDir.path}/base.apk');
|
||||
File patchedFile = File('${workDir.path}/patched.apk');
|
||||
final Directory workDir = _tmpDir.createTempSync('tmp-');
|
||||
final File inputFile = File('${workDir.path}/base.apk');
|
||||
final File patchedFile = File('${workDir.path}/patched.apk');
|
||||
_outFile = File('${workDir.path}/out.apk');
|
||||
Directory cacheDir = Directory('${workDir.path}/cache');
|
||||
final Directory cacheDir = Directory('${workDir.path}/cache');
|
||||
cacheDir.createSync();
|
||||
try {
|
||||
await patcherChannel.invokeMethod(
|
||||
|
@ -225,7 +232,9 @@ class PatcherAPI {
|
|||
},
|
||||
);
|
||||
} on Exception catch (e, s) {
|
||||
print(e);
|
||||
if (kDebugMode) {
|
||||
print(e);
|
||||
}
|
||||
throw await Sentry.captureException(e, stackTrace: s);
|
||||
}
|
||||
}
|
||||
|
@ -235,7 +244,7 @@ class PatcherAPI {
|
|||
if (_outFile != null) {
|
||||
try {
|
||||
if (patchedApp.isRooted) {
|
||||
bool hasRootPermissions = await _rootAPI.hasRootPermissions();
|
||||
final bool hasRootPermissions = await _rootAPI.hasRootPermissions();
|
||||
if (hasRootPermissions) {
|
||||
return _rootAPI.installApp(
|
||||
patchedApp.packageName,
|
||||
|
@ -258,9 +267,9 @@ class PatcherAPI {
|
|||
void exportPatchedFile(String appName, String version) {
|
||||
try {
|
||||
if (_outFile != null) {
|
||||
String newName = _getFileName(appName, version);
|
||||
final String newName = _getFileName(appName, version);
|
||||
CRFileSaver.saveFileWithDialog(SaveFileDialogParams(
|
||||
sourceFilePath: _outFile!.path, destinationFileName: newName));
|
||||
sourceFilePath: _outFile!.path, destinationFileName: newName,),);
|
||||
}
|
||||
} on Exception catch (e, s) {
|
||||
Sentry.captureException(e, stackTrace: s);
|
||||
|
@ -270,11 +279,11 @@ class PatcherAPI {
|
|||
void sharePatchedFile(String appName, String version) {
|
||||
try {
|
||||
if (_outFile != null) {
|
||||
String newName = _getFileName(appName, version);
|
||||
int lastSeparator = _outFile!.path.lastIndexOf('/');
|
||||
String newPath =
|
||||
final String newName = _getFileName(appName, version);
|
||||
final int lastSeparator = _outFile!.path.lastIndexOf('/');
|
||||
final String newPath =
|
||||
_outFile!.path.substring(0, lastSeparator + 1) + newName;
|
||||
File shareFile = _outFile!.copySync(newPath);
|
||||
final File shareFile = _outFile!.copySync(newPath);
|
||||
ShareExtend.share(shareFile.path, 'file');
|
||||
}
|
||||
} on Exception catch (e, s) {
|
||||
|
@ -283,34 +292,35 @@ class PatcherAPI {
|
|||
}
|
||||
|
||||
String _getFileName(String appName, String version) {
|
||||
String prefix = appName.toLowerCase().replaceAll(' ', '-');
|
||||
String newName = '$prefix-revanced_v$version.apk';
|
||||
final String prefix = appName.toLowerCase().replaceAll(' ', '-');
|
||||
final 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');
|
||||
final Directory appCache = await getTemporaryDirectory();
|
||||
final Directory logDir = Directory('${appCache.path}/logs');
|
||||
logDir.createSync();
|
||||
String dateTime = DateTime.now()
|
||||
final String dateTime = DateTime.now()
|
||||
.toIso8601String()
|
||||
.replaceAll('-', '')
|
||||
.replaceAll(':', '')
|
||||
.replaceAll('T', '')
|
||||
.replaceAll('.', '');
|
||||
File log = File('${logDir.path}/revanced-manager_patcher_$dateTime.log');
|
||||
final File log =
|
||||
File('${logDir.path}/revanced-manager_patcher_$dateTime.log');
|
||||
log.writeAsStringSync(logs);
|
||||
ShareExtend.share(log.path, 'file');
|
||||
}
|
||||
|
||||
String getRecommendedVersion(String packageName) {
|
||||
Map<String, int> versions = {};
|
||||
for (Patch patch in _patches) {
|
||||
Package? package = patch.compatiblePackages.firstWhereOrNull(
|
||||
final Map<String, int> versions = {};
|
||||
for (final Patch patch in _patches) {
|
||||
final Package? package = patch.compatiblePackages.firstWhereOrNull(
|
||||
(pack) => pack.name == packageName,
|
||||
);
|
||||
if (package != null) {
|
||||
for (String version in package.versions) {
|
||||
for (final String version in package.versions) {
|
||||
versions.update(
|
||||
version,
|
||||
(value) => versions[version]! + 1,
|
||||
|
@ -320,7 +330,7 @@ class PatcherAPI {
|
|||
}
|
||||
}
|
||||
if (versions.isNotEmpty) {
|
||||
var entries = versions.entries.toList()
|
||||
final entries = versions.entries.toList()
|
||||
..sort((a, b) => a.value.compareTo(b.value));
|
||||
versions
|
||||
..clear()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue