mirror of
https://github.com/revanced/revanced-manager.git
synced 2025-06-12 04:37:37 +02:00
feat: allow control over patches update (#1063)
Co-authored-by: oSumAtrIX <johan.melkonyan1@web.de>
This commit is contained in:
@ -4,6 +4,7 @@ import 'dart:io';
|
||||
import 'package:cross_connectivity/cross_connectivity.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_i18n/flutter_i18n.dart';
|
||||
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
|
||||
import 'package:injectable/injectable.dart';
|
||||
@ -42,6 +43,10 @@ class HomeViewModel extends BaseViewModel {
|
||||
|
||||
Future<void> initialize(BuildContext context) async {
|
||||
_latestManagerVersion = await _managerAPI.getLatestManagerVersion();
|
||||
if(!_managerAPI.getPatchesConsent()){
|
||||
await showPatchesConsent(context);
|
||||
}
|
||||
await _patcherAPI.initialize();
|
||||
await flutterLocalNotificationsPlugin.initialize(
|
||||
const InitializationSettings(
|
||||
android: AndroidInitializationSettings('ic_notification'),
|
||||
@ -129,13 +134,13 @@ class HomeViewModel extends BaseViewModel {
|
||||
|
||||
Future<bool> hasPatchesUpdates() async {
|
||||
final String? latestVersion = await _managerAPI.getLatestPatchesVersion();
|
||||
final String? currentVersion = await _managerAPI.getCurrentPatchesVersion();
|
||||
final String currentVersion = await _managerAPI.getCurrentPatchesVersion();
|
||||
if (latestVersion != null) {
|
||||
try {
|
||||
final int latestVersionInt =
|
||||
int.parse(latestVersion.replaceAll(RegExp('[^0-9]'), ''));
|
||||
final int currentVersionInt =
|
||||
int.parse(currentVersion!.replaceAll(RegExp('[^0-9]'), ''));
|
||||
int.parse(currentVersion.replaceAll(RegExp('[^0-9]'), ''));
|
||||
return latestVersionInt > currentVersionInt;
|
||||
} on Exception catch (e) {
|
||||
if (kDebugMode) {
|
||||
@ -163,6 +168,94 @@ class HomeViewModel extends BaseViewModel {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> showPatchesConsent(BuildContext context) async{
|
||||
final ValueNotifier<bool> autoUpdate = ValueNotifier(true);
|
||||
await showDialog(
|
||||
context: context,
|
||||
barrierDismissible: false,
|
||||
builder: (context) => AlertDialog(
|
||||
title: const Text('ReVanced Patches'),
|
||||
content: ValueListenableBuilder(
|
||||
valueListenable: autoUpdate,
|
||||
builder: (context, value, child) {
|
||||
return Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
I18nText(
|
||||
'homeView.patchesConsentDialogText',
|
||||
child: Text(
|
||||
'',
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: Theme.of(context).colorScheme.secondary,
|
||||
),
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 10),
|
||||
child: I18nText(
|
||||
'homeView.patchesConsentDialogText2',
|
||||
translationParams: {'url': _managerAPI.defaultApiUrl.split('/')[2]},
|
||||
child: Text(
|
||||
'',
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: Theme.of(context).colorScheme.error,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
CheckboxListTile(
|
||||
value: value,
|
||||
contentPadding: EdgeInsets.zero,
|
||||
title: I18nText('homeView.patchesConsentDialogText3',),
|
||||
subtitle: I18nText('homeView.patchesConsentDialogText3Sub',),
|
||||
onChanged: (selected) {
|
||||
autoUpdate.value = selected!;
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
actions: [
|
||||
CustomMaterialButton(
|
||||
isFilled: false,
|
||||
onPressed: () async {
|
||||
await _managerAPI.setPatchesConsent(false);
|
||||
SystemNavigator.pop();
|
||||
},
|
||||
label: I18nText('quitButton'),
|
||||
),
|
||||
CustomMaterialButton(
|
||||
onPressed: () async {
|
||||
await _managerAPI.setPatchesConsent(true);
|
||||
await _managerAPI.setPatchesAutoUpdate(autoUpdate.value);
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
label: I18nText('okButton'),
|
||||
)
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> updatePatches(BuildContext context) async {
|
||||
_toast.showBottom('homeView.downloadingMessage');
|
||||
final String patchesVersion =
|
||||
await _managerAPI.getLatestPatchesVersion() ?? '0.0.0';
|
||||
if (patchesVersion != '0.0.0') {
|
||||
_toast.showBottom('homeView.downloadedMessage');
|
||||
await _managerAPI.setCurrentPatchesVersion(patchesVersion);
|
||||
forceRefresh(context);
|
||||
} else {
|
||||
_toast.showBottom('homeView.errorDownloadMessage');
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> updateManager(BuildContext context) async {
|
||||
final ValueNotifier<bool> downloaded = ValueNotifier(false);
|
||||
try {
|
||||
@ -336,6 +429,7 @@ class HomeViewModel extends BaseViewModel {
|
||||
|
||||
Future<void> showUpdateConfirmationDialog(
|
||||
BuildContext parentContext,
|
||||
bool isPatches,
|
||||
) {
|
||||
return showModalBottomSheet(
|
||||
context: parentContext,
|
||||
@ -343,7 +437,9 @@ class HomeViewModel extends BaseViewModel {
|
||||
shape: const RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.vertical(top: Radius.circular(24.0)),
|
||||
),
|
||||
builder: (context) => const UpdateConfirmationDialog(),
|
||||
builder: (context) => UpdateConfirmationDialog(
|
||||
isPatches: isPatches,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@ -351,8 +447,12 @@ class HomeViewModel extends BaseViewModel {
|
||||
return _githubAPI.getLatestManagerRelease(_managerAPI.defaultManagerRepo);
|
||||
}
|
||||
|
||||
Future<String?> getLatestPatcherReleaseTime() {
|
||||
return _managerAPI.getLatestPatcherReleaseTime();
|
||||
Future<Map<String, dynamic>?> getLatestPatchesRelease() {
|
||||
return _githubAPI.getLatestPatchesRelease(_managerAPI.defaultPatchesRepo);
|
||||
}
|
||||
|
||||
Future<String?> getLatestPatchesReleaseTime() {
|
||||
return _managerAPI.getLatestPatchesReleaseTime();
|
||||
}
|
||||
|
||||
Future<String?> getLatestManagerReleaseTime() {
|
||||
|
Reference in New Issue
Block a user