feat: Save last patched app (#1414)

Co-authored-by: aAbed <39409020+TheAabedKhan@users.noreply.github.com>
Co-authored-by: Ushie <ushiekane@gmail.com>
Co-authored-by: oSumAtrIX <johan.melkonyan1@web.de>
Co-authored-by: Mr. X <79870712+n30mrx@users.noreply.github.com>
Co-authored-by: festry0 <153519925+festry0@users.noreply.github.com>
This commit is contained in:
Benjamin
2024-06-29 05:38:00 -07:00
committed by GitHub
parent b26760b216
commit 77204087bb
16 changed files with 448 additions and 46 deletions

View File

@ -5,6 +5,7 @@ import 'package:revanced_manager/gen/strings.g.dart';
import 'package:revanced_manager/ui/views/home/home_viewmodel.dart';
import 'package:revanced_manager/ui/widgets/homeView/installed_apps_card.dart';
import 'package:revanced_manager/ui/widgets/homeView/latest_commit_card.dart';
import 'package:revanced_manager/ui/widgets/homeView/last_patched_app_card.dart';
import 'package:revanced_manager/ui/widgets/shared/custom_sliver_app_bar.dart';
import 'package:stacked/stacked.dart';
@ -44,6 +45,22 @@ class HomeView extends StatelessWidget {
const SizedBox(height: 10),
LatestCommitCard(model: model, parentContext: context),
const SizedBox(height: 23),
Visibility(
visible: model.isLastPatchedAppEnabled(),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
t.homeView.lastPatchedAppSubtitle,
style: Theme.of(context).textTheme.titleLarge,
),
const SizedBox(height: 10),
LastPatchedAppCard(),
const SizedBox(height: 10),
],
),
),
Text(
t.homeView.patchedSubtitle,
style: Theme.of(context).textTheme.titleLarge,

View File

@ -35,6 +35,7 @@ class HomeViewModel extends BaseViewModel {
final Toast _toast = locator<Toast>();
final flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin();
bool showUpdatableApps = false;
PatchedApplication? lastPatchedApp;
bool releaseBuild = false;
List<PatchedApplication> patchedInstalledApps = [];
String _currentManagerVersion = '';
@ -102,10 +103,10 @@ class HomeViewModel extends BaseViewModel {
}
}
void navigateToAppInfo(PatchedApplication app) {
void navigateToAppInfo(PatchedApplication app, bool isLastPatchedApp) {
_navigationService.navigateTo(
Routes.appInfoView,
arguments: AppInfoViewArguments(app: app),
arguments: AppInfoViewArguments(app: app, isLastPatchedApp: isLastPatchedApp),
);
}
@ -123,10 +124,15 @@ class HomeViewModel extends BaseViewModel {
}
void getPatchedApps() {
lastPatchedApp = _managerAPI.getLastPatchedApp();
patchedInstalledApps = _managerAPI.getPatchedApps().toList();
notifyListeners();
}
bool isLastPatchedAppEnabled() {
return _managerAPI.isLastPatchedAppEnabled();
}
Future<bool> hasManagerUpdates() async {
if (!_managerAPI.releaseBuild) {
return false;

View File

@ -123,7 +123,7 @@ class InstallerViewModel extends BaseViewModel {
});
await WakelockPlus.enable();
await handlePlatformChannelMethods();
await runPatcher();
await runPatcher(context);
}
Future<dynamic> handlePlatformChannelMethods() async {
@ -182,13 +182,20 @@ class InstallerViewModel extends BaseViewModel {
notifyListeners();
}
Future<void> runPatcher() async {
Future<void> runPatcher(BuildContext context) async {
try {
await _patcherAPI.runPatcher(
_app.packageName,
_app.apkFilePath,
_patches,
);
_app.appliedPatches = _patches.map((p) => p.name).toList();
if (_managerAPI.isLastPatchedAppEnabled()) {
await _managerAPI.setLastPatchedApp(_app, _patcherAPI.outFile!);
} else {
_app.patchedFilePath = _patcherAPI.outFile!.path;
}
locator<HomeViewModel>().initialize(context);
} on Exception catch (e) {
update(
-100.0,
@ -488,7 +495,7 @@ class InstallerViewModel extends BaseViewModel {
Future<void> installResult(BuildContext context, bool installAsRoot) async {
isInstalling = true;
try {
_app.isRooted = installAsRoot;
_app.isRooted = await _managerAPI.installTypeDialog(context);
if (headerLogs != 'Installing...') {
update(
.85,
@ -501,17 +508,15 @@ class InstallerViewModel extends BaseViewModel {
isInstalled = true;
_app.isFromStorage = false;
_app.patchDate = DateTime.now();
_app.appliedPatches = _patches.map((p) => p.name).toList();
// In case a patch changed the app name or package name,
// update the app info.
final app =
await DeviceApps.getAppFromStorage(_patcherAPI.outFile!.path);
await DeviceApps.getAppFromStorage(_patcherAPI.outFile!.path);
if (app != null) {
_app.name = app.appName;
_app.packageName = app.packageName;
}
await _managerAPI.savePatchedApp(_app);
_managerAPI
@ -544,7 +549,7 @@ class InstallerViewModel extends BaseViewModel {
void exportResult() {
try {
_patcherAPI.exportPatchedFile(_app.name, _app.version);
_patcherAPI.exportPatchedFile(_app);
} on Exception catch (e) {
if (kDebugMode) {
print(e);

View File

@ -141,6 +141,18 @@ class SettingsViewModel extends BaseViewModel {
notifyListeners();
}
bool isLastPatchedAppEnabled() {
return _managerAPI.isLastPatchedAppEnabled();
}
void useLastPatchedApp(bool value) {
_managerAPI.enableLastPatchedAppStatus(value);
if (!value) {
_managerAPI.deleteLastPatchedApp();
}
notifyListeners();
}
bool isVersionCompatibilityCheckEnabled() {
return _managerAPI.isVersionCompatibilityCheckEnabled();
}