2022-09-18 23:47:24 +02:00
|
|
|
// ignore_for_file: use_build_context_synchronously
|
2022-09-05 14:43:13 +02:00
|
|
|
import 'package:device_apps/device_apps.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:intl/intl.dart';
|
|
|
|
import 'package:revanced_manager/app/app.locator.dart';
|
2024-02-12 00:22:25 +01:00
|
|
|
import 'package:revanced_manager/gen/strings.g.dart';
|
2022-09-05 14:43:13 +02:00
|
|
|
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/root_api.dart';
|
2022-10-10 23:02:23 +02:00
|
|
|
import 'package:revanced_manager/services/toast.dart';
|
2022-09-11 03:01:06 +02:00
|
|
|
import 'package:revanced_manager/ui/views/home/home_viewmodel.dart';
|
2022-09-05 14:43:13 +02:00
|
|
|
import 'package:revanced_manager/ui/views/navigation/navigation_viewmodel.dart';
|
|
|
|
import 'package:revanced_manager/ui/views/patcher/patcher_viewmodel.dart';
|
|
|
|
import 'package:stacked/stacked.dart';
|
|
|
|
|
|
|
|
class AppInfoViewModel extends BaseViewModel {
|
|
|
|
final ManagerAPI _managerAPI = locator<ManagerAPI>();
|
|
|
|
final PatcherAPI _patcherAPI = locator<PatcherAPI>();
|
|
|
|
final RootAPI _rootAPI = RootAPI();
|
2022-10-10 23:02:23 +02:00
|
|
|
final Toast _toast = locator<Toast>();
|
2022-09-05 14:43:13 +02:00
|
|
|
|
2022-09-22 10:46:28 +02:00
|
|
|
Future<void> uninstallApp(
|
|
|
|
BuildContext context,
|
|
|
|
PatchedApplication app,
|
|
|
|
bool onlyUnpatch,
|
|
|
|
) async {
|
2023-12-23 20:53:51 +01:00
|
|
|
var isUninstalled = onlyUnpatch;
|
|
|
|
|
|
|
|
if (!onlyUnpatch) {
|
2023-12-23 21:11:24 +01:00
|
|
|
// TODO(Someone): Wait for the app to uninstall successfully.
|
2022-09-22 10:46:28 +02:00
|
|
|
isUninstalled = await DeviceApps.uninstallApp(app.packageName);
|
|
|
|
}
|
2023-12-23 20:53:51 +01:00
|
|
|
|
2024-02-12 00:22:25 +01:00
|
|
|
if (isUninstalled && app.isRooted && await _rootAPI.hasRootPermissions()) {
|
2023-12-23 20:53:51 +01:00
|
|
|
await _rootAPI.uninstall(app.packageName);
|
|
|
|
}
|
|
|
|
|
2022-09-22 10:46:28 +02:00
|
|
|
if (isUninstalled) {
|
|
|
|
await _managerAPI.deletePatchedApp(app);
|
|
|
|
locator<HomeViewModel>().initialize(context);
|
2022-09-05 14:43:13 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-30 13:35:06 +01:00
|
|
|
Future<void> navigateToPatcher(PatchedApplication app) async {
|
2022-09-05 14:43:13 +02:00
|
|
|
locator<PatcherViewModel>().selectedApp = app;
|
|
|
|
locator<PatcherViewModel>().selectedPatches =
|
|
|
|
await _patcherAPI.getAppliedPatches(app.appliedPatches);
|
|
|
|
locator<PatcherViewModel>().notifyListeners();
|
|
|
|
locator<NavigationViewModel>().setIndex(1);
|
|
|
|
}
|
|
|
|
|
2022-10-10 23:02:23 +02:00
|
|
|
void updateNotImplemented(BuildContext context) {
|
2024-02-12 00:22:25 +01:00
|
|
|
_toast.showBottom(t.appInfoView.updateNotImplemented);
|
2022-10-10 23:02:23 +02:00
|
|
|
}
|
|
|
|
|
2022-09-18 23:47:24 +02:00
|
|
|
Future<void> showUninstallDialog(
|
2022-09-05 14:43:13 +02:00
|
|
|
BuildContext context,
|
|
|
|
PatchedApplication app,
|
2022-09-17 15:45:43 +02:00
|
|
|
bool onlyUnpatch,
|
2022-09-05 14:43:13 +02:00
|
|
|
) async {
|
2023-01-30 13:35:06 +01:00
|
|
|
final bool hasRootPermissions = await _rootAPI.hasRootPermissions();
|
2022-09-17 15:45:43 +02:00
|
|
|
if (app.isRooted && !hasRootPermissions) {
|
|
|
|
return showDialog(
|
|
|
|
context: context,
|
|
|
|
builder: (context) => AlertDialog(
|
2024-02-12 00:22:25 +01:00
|
|
|
title: Text(t.appInfoView.rootDialogTitle),
|
|
|
|
content: Text(t.appInfoView.rootDialogText),
|
2022-09-17 15:45:43 +02:00
|
|
|
actions: <Widget>[
|
2023-12-22 14:34:03 +01:00
|
|
|
FilledButton(
|
2022-09-17 15:45:43 +02:00
|
|
|
onPressed: () => Navigator.of(context).pop(),
|
2024-02-12 00:22:25 +01:00
|
|
|
child: Text(t.okButton),
|
2023-08-06 09:39:46 +02:00
|
|
|
),
|
2022-09-17 15:45:43 +02:00
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
2022-09-05 14:43:13 +02:00
|
|
|
} else {
|
2022-09-18 23:47:24 +02:00
|
|
|
if (onlyUnpatch) {
|
|
|
|
return showDialog(
|
|
|
|
context: context,
|
|
|
|
builder: (context) => AlertDialog(
|
2024-02-12 00:22:25 +01:00
|
|
|
title: Text(t.appInfoView.unmountButton),
|
|
|
|
content: Text(t.appInfoView.unmountDialogText),
|
2022-09-18 23:47:24 +02:00
|
|
|
actions: <Widget>[
|
2023-12-22 14:34:03 +01:00
|
|
|
TextButton(
|
2022-09-18 23:47:24 +02:00
|
|
|
onPressed: () => Navigator.of(context).pop(),
|
2024-02-12 00:22:25 +01:00
|
|
|
child: Text(t.noButton),
|
2022-09-18 23:47:24 +02:00
|
|
|
),
|
2023-12-22 14:34:03 +01:00
|
|
|
FilledButton(
|
2022-09-18 23:47:24 +02:00
|
|
|
onPressed: () {
|
2023-12-23 21:11:24 +01:00
|
|
|
uninstallApp(context, app, true);
|
2022-09-18 23:47:24 +02:00
|
|
|
Navigator.of(context).pop();
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
},
|
2024-02-12 00:22:25 +01:00
|
|
|
child: Text(t.yesButton),
|
2023-08-06 09:39:46 +02:00
|
|
|
),
|
2022-09-18 23:47:24 +02:00
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
} else {
|
2023-12-23 21:11:24 +01:00
|
|
|
return showDialog(
|
|
|
|
context: context,
|
|
|
|
builder: (context) => AlertDialog(
|
2024-02-12 00:22:25 +01:00
|
|
|
title: Text(t.appInfoView.uninstallButton),
|
|
|
|
content: Text(t.appInfoView.uninstallDialogText),
|
2023-12-23 21:11:24 +01:00
|
|
|
actions: <Widget>[
|
|
|
|
TextButton(
|
|
|
|
onPressed: () => Navigator.of(context).pop(),
|
2024-02-12 00:22:25 +01:00
|
|
|
child: Text(t.noButton),
|
2023-12-23 21:11:24 +01:00
|
|
|
),
|
|
|
|
FilledButton(
|
|
|
|
onPressed: () {
|
|
|
|
uninstallApp(context, app, false);
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
},
|
2024-02-12 00:22:25 +01:00
|
|
|
child: Text(t.yesButton),
|
2023-12-23 21:11:24 +01:00
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
2022-09-18 23:47:24 +02:00
|
|
|
}
|
2022-09-05 14:43:13 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
String getPrettyDate(BuildContext context, DateTime dateTime) {
|
|
|
|
return DateFormat.yMMMMd(Localizations.localeOf(context).languageCode)
|
|
|
|
.format(dateTime);
|
|
|
|
}
|
|
|
|
|
|
|
|
String getPrettyTime(BuildContext context, DateTime dateTime) {
|
|
|
|
return DateFormat.jm(Localizations.localeOf(context).languageCode)
|
|
|
|
.format(dateTime);
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<void> showAppliedPatchesDialog(
|
|
|
|
BuildContext context,
|
|
|
|
PatchedApplication app,
|
|
|
|
) async {
|
|
|
|
return showDialog(
|
|
|
|
context: context,
|
|
|
|
builder: (context) => AlertDialog(
|
2024-02-12 00:22:25 +01:00
|
|
|
title: Text(t.appInfoView.appliedPatchesLabel),
|
2022-10-10 23:25:35 +02:00
|
|
|
content: SingleChildScrollView(
|
2023-01-30 13:35:06 +01:00
|
|
|
child: Text(getAppliedPatchesString(app.appliedPatches)),
|
|
|
|
),
|
2022-09-12 15:20:25 +02:00
|
|
|
actions: <Widget>[
|
2023-12-22 14:34:03 +01:00
|
|
|
FilledButton(
|
2022-09-05 14:43:13 +02:00
|
|
|
onPressed: () => Navigator.of(context).pop(),
|
2024-02-12 00:22:25 +01:00
|
|
|
child: Text(t.okButton),
|
2023-08-06 09:39:46 +02:00
|
|
|
),
|
2022-09-05 14:43:13 +02:00
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
String getAppliedPatchesString(List<String> appliedPatches) {
|
2023-10-12 02:00:39 +02:00
|
|
|
return '• ${appliedPatches.join('\n• ')}';
|
2022-09-05 14:43:13 +02:00
|
|
|
}
|
2022-09-06 15:40:49 +02:00
|
|
|
|
|
|
|
void openApp(PatchedApplication app) {
|
|
|
|
DeviceApps.openApp(app.packageName);
|
|
|
|
}
|
2022-09-05 14:43:13 +02:00
|
|
|
}
|