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:flutter_i18n/flutter_i18n.dart';
|
|
|
|
import 'package:intl/intl.dart';
|
|
|
|
import 'package:revanced_manager/app/app.locator.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/root_api.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:revanced_manager/ui/widgets/installerView/custom_material_button.dart';
|
|
|
|
import 'package:revanced_manager/utils/string.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-09-17 15:45:43 +02:00
|
|
|
Future<void> uninstallApp(PatchedApplication app, bool onlyUnpatch) async {
|
2022-09-05 14:43:13 +02:00
|
|
|
if (app.isRooted) {
|
2022-09-13 17:54:43 +02:00
|
|
|
bool hasRootPermissions = await _rootAPI.hasRootPermissions();
|
|
|
|
if (hasRootPermissions) {
|
|
|
|
_rootAPI.deleteApp(app.packageName, app.apkFilePath);
|
|
|
|
_managerAPI.deletePatchedApp(app);
|
2022-09-17 15:45:43 +02:00
|
|
|
if (!onlyUnpatch) {
|
|
|
|
DeviceApps.uninstallApp(app.packageName);
|
|
|
|
}
|
2022-09-13 17:54:43 +02:00
|
|
|
}
|
2022-09-05 14:43:13 +02:00
|
|
|
} else {
|
2022-09-18 06:06:23 +02:00
|
|
|
DeviceApps.uninstallApp(app.packageName).then(
|
|
|
|
(value) => _managerAPI.deletePatchedApp(app),
|
|
|
|
);
|
2022-09-05 14:43:13 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void navigateToPatcher(PatchedApplication app) async {
|
|
|
|
locator<PatcherViewModel>().selectedApp = app;
|
|
|
|
locator<PatcherViewModel>().selectedPatches =
|
|
|
|
await _patcherAPI.getAppliedPatches(app.appliedPatches);
|
|
|
|
locator<PatcherViewModel>().notifyListeners();
|
|
|
|
locator<NavigationViewModel>().setIndex(1);
|
|
|
|
}
|
|
|
|
|
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 {
|
2022-09-17 15:45:43 +02:00
|
|
|
bool hasRootPermissions = await _rootAPI.hasRootPermissions();
|
|
|
|
if (app.isRooted && !hasRootPermissions) {
|
|
|
|
return showDialog(
|
|
|
|
context: context,
|
|
|
|
builder: (context) => AlertDialog(
|
|
|
|
title: I18nText('appInfoView.rootDialogTitle'),
|
|
|
|
backgroundColor: Theme.of(context).colorScheme.secondaryContainer,
|
|
|
|
content: I18nText('appInfoView.rootDialogText'),
|
|
|
|
actions: <Widget>[
|
|
|
|
CustomMaterialButton(
|
|
|
|
label: I18nText('okButton'),
|
|
|
|
onPressed: () => Navigator.of(context).pop(),
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
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(
|
|
|
|
title: I18nText(
|
|
|
|
'appInfoView.unpatchButton',
|
2022-09-05 14:43:13 +02:00
|
|
|
),
|
2022-09-18 23:47:24 +02:00
|
|
|
backgroundColor: Theme.of(context).colorScheme.secondaryContainer,
|
|
|
|
content: I18nText(
|
|
|
|
'appInfoView.unpatchDialogText',
|
|
|
|
),
|
|
|
|
actions: <Widget>[
|
|
|
|
CustomMaterialButton(
|
|
|
|
isFilled: false,
|
|
|
|
label: I18nText('cancelButton'),
|
|
|
|
onPressed: () => Navigator.of(context).pop(),
|
|
|
|
),
|
|
|
|
CustomMaterialButton(
|
|
|
|
label: I18nText('okButton'),
|
|
|
|
onPressed: () {
|
|
|
|
uninstallApp(app, onlyUnpatch);
|
|
|
|
locator<HomeViewModel>().initialize(context);
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
},
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
uninstallApp(app, onlyUnpatch);
|
|
|
|
locator<HomeViewModel>().initialize(context);
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
}
|
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(
|
|
|
|
title: I18nText('appInfoView.appliedPatchesLabel'),
|
2022-09-07 13:01:04 +02:00
|
|
|
backgroundColor: Theme.of(context).colorScheme.secondaryContainer,
|
2022-09-05 14:43:13 +02:00
|
|
|
content: Text(getAppliedPatchesString(app.appliedPatches)),
|
2022-09-12 15:20:25 +02:00
|
|
|
actions: <Widget>[
|
2022-09-05 14:43:13 +02:00
|
|
|
CustomMaterialButton(
|
|
|
|
label: I18nText('okButton'),
|
|
|
|
onPressed: () => Navigator.of(context).pop(),
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
String getAppliedPatchesString(List<String> appliedPatches) {
|
|
|
|
List<String> names = appliedPatches
|
|
|
|
.map((p) => p
|
|
|
|
.replaceAll('-', ' ')
|
|
|
|
.split('-')
|
|
|
|
.join(' ')
|
|
|
|
.toTitleCase()
|
|
|
|
.replaceFirst('Microg', 'MicroG'))
|
|
|
|
.toList();
|
|
|
|
return '\u2022 ${names.join('\n\u2022 ')}';
|
|
|
|
}
|
2022-09-06 15:40:49 +02:00
|
|
|
|
|
|
|
void openApp(PatchedApplication app) {
|
|
|
|
DeviceApps.openApp(app.packageName);
|
|
|
|
}
|
2022-09-05 14:43:13 +02:00
|
|
|
}
|