refactor: Move some logic to ManagerAPI and PatcherAPI

This commit is contained in:
Alberto Ponces 2022-09-23 15:31:24 +01:00
parent 4609ed9eba
commit 6abb761724
2 changed files with 17 additions and 12 deletions

View File

@ -319,4 +319,14 @@ class ManagerAPI {
} }
return newCommits; return newCommits;
} }
Future<bool> isSplitApk(PatchedApplication patchedApp) async {
Application? app;
if (patchedApp.isFromStorage) {
app = await DeviceApps.getAppFromStorage(patchedApp.apkFilePath);
} else {
app = await DeviceApps.getApp(patchedApp.packageName);
}
return app != null && app.isSplit;
}
} }

View File

@ -1,4 +1,3 @@
import 'package:device_apps/device_apps.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_i18n/flutter_i18n.dart'; import 'package:flutter_i18n/flutter_i18n.dart';
import 'package:injectable/injectable.dart'; import 'package:injectable/injectable.dart';
@ -6,6 +5,7 @@ import 'package:revanced_manager/app/app.locator.dart';
import 'package:revanced_manager/app/app.router.dart'; import 'package:revanced_manager/app/app.router.dart';
import 'package:revanced_manager/models/patch.dart'; import 'package:revanced_manager/models/patch.dart';
import 'package:revanced_manager/models/patched_application.dart'; import 'package:revanced_manager/models/patched_application.dart';
import 'package:revanced_manager/services/manager_api.dart';
import 'package:revanced_manager/services/patcher_api.dart'; import 'package:revanced_manager/services/patcher_api.dart';
import 'package:revanced_manager/ui/widgets/shared/custom_material_button.dart'; import 'package:revanced_manager/ui/widgets/shared/custom_material_button.dart';
import 'package:stacked/stacked.dart'; import 'package:stacked/stacked.dart';
@ -14,6 +14,7 @@ import 'package:stacked_services/stacked_services.dart';
@lazySingleton @lazySingleton
class PatcherViewModel extends BaseViewModel { class PatcherViewModel extends BaseViewModel {
final NavigationService _navigationService = locator<NavigationService>(); final NavigationService _navigationService = locator<NavigationService>();
final ManagerAPI _managerAPI = locator<ManagerAPI>();
final PatcherAPI _patcherAPI = locator<PatcherAPI>(); final PatcherAPI _patcherAPI = locator<PatcherAPI>();
PatchedApplication? selectedApp; PatchedApplication? selectedApp;
List<Patch> selectedPatches = []; List<Patch> selectedPatches = [];
@ -39,18 +40,12 @@ class PatcherViewModel extends BaseViewModel {
} }
Future<bool> isValidPatchConfig() async { Future<bool> isValidPatchConfig() async {
bool needsResourcePatching = bool needsResourcePatching = await _patcherAPI.needsResourcePatching(
await _patcherAPI.needsResourcePatching(selectedPatches); selectedPatches,
);
if (needsResourcePatching && selectedApp != null) { if (needsResourcePatching && selectedApp != null) {
Application? app; bool isSplit = await _managerAPI.isSplitApk(selectedApp!);
if (selectedApp!.isFromStorage) { return !isSplit;
app = await DeviceApps.getAppFromStorage(selectedApp!.apkFilePath);
} else {
app = await DeviceApps.getApp(selectedApp!.packageName);
}
if (app != null && app.isSplit) {
return false;
}
} }
return true; return true;
} }