mirror of
https://github.com/revanced/revanced-manager
synced 2024-05-14 13:56:57 +02:00
fix: Fix Update Manager's button
This commit is contained in:
parent
7231d44e02
commit
207e94de5a
@ -9,6 +9,7 @@ import 'package:revanced_manager/services/revanced_api.dart';
|
|||||||
import 'package:revanced_manager/ui/theme/dynamic_theme_builder.dart';
|
import 'package:revanced_manager/ui/theme/dynamic_theme_builder.dart';
|
||||||
import 'package:revanced_manager/ui/views/navigation/navigation_view.dart';
|
import 'package:revanced_manager/ui/views/navigation/navigation_view.dart';
|
||||||
import 'package:stacked_themes/stacked_themes.dart';
|
import 'package:stacked_themes/stacked_themes.dart';
|
||||||
|
import 'package:timezone/data/latest.dart' as tz;
|
||||||
|
|
||||||
Future main() async {
|
Future main() async {
|
||||||
await ThemeManager.initialise();
|
await ThemeManager.initialise();
|
||||||
@ -19,6 +20,7 @@ Future main() async {
|
|||||||
await locator<RevancedAPI>().initialize(apiUrl);
|
await locator<RevancedAPI>().initialize(apiUrl);
|
||||||
locator<GithubAPI>().initialize();
|
locator<GithubAPI>().initialize();
|
||||||
await locator<PatcherAPI>().initialize();
|
await locator<PatcherAPI>().initialize();
|
||||||
|
tz.initializeTimeZones();
|
||||||
runApp(const MyApp());
|
runApp(const MyApp());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,6 +18,7 @@ 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/ui/widgets/installerView/custom_material_button.dart';
|
||||||
import 'package:stacked/stacked.dart';
|
import 'package:stacked/stacked.dart';
|
||||||
import 'package:stacked_services/stacked_services.dart';
|
import 'package:stacked_services/stacked_services.dart';
|
||||||
|
import 'package:timezone/timezone.dart' as tz;
|
||||||
|
|
||||||
@lazySingleton
|
@lazySingleton
|
||||||
class HomeViewModel extends BaseViewModel {
|
class HomeViewModel extends BaseViewModel {
|
||||||
@ -38,6 +39,10 @@ class HomeViewModel extends BaseViewModel {
|
|||||||
onSelectNotification: (p) =>
|
onSelectNotification: (p) =>
|
||||||
DeviceApps.openApp('app.revanced.manager.flutter'),
|
DeviceApps.openApp('app.revanced.manager.flutter'),
|
||||||
);
|
);
|
||||||
|
flutterLocalNotificationsPlugin
|
||||||
|
.resolvePlatformSpecificImplementation<
|
||||||
|
AndroidFlutterLocalNotificationsPlugin>()
|
||||||
|
?.requestPermission();
|
||||||
bool isConnected = await Connectivity().checkConnection();
|
bool isConnected = await Connectivity().checkConnection();
|
||||||
if (!isConnected) {
|
if (!isConnected) {
|
||||||
Fluttertoast.showToast(
|
Fluttertoast.showToast(
|
||||||
@ -102,35 +107,42 @@ class HomeViewModel extends BaseViewModel {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void updateManager(BuildContext context) async {
|
Future<void> updateManager(BuildContext context) async {
|
||||||
Fluttertoast.showToast(
|
try {
|
||||||
msg: FlutterI18n.translate(
|
Fluttertoast.showToast(
|
||||||
context,
|
msg: FlutterI18n.translate(
|
||||||
'homeView.downloadingMessage',
|
|
||||||
),
|
|
||||||
toastLength: Toast.LENGTH_LONG,
|
|
||||||
gravity: ToastGravity.CENTER,
|
|
||||||
);
|
|
||||||
File? managerApk = await _managerAPI.downloadManager();
|
|
||||||
if (managerApk != null) {
|
|
||||||
flutterLocalNotificationsPlugin.show(
|
|
||||||
0,
|
|
||||||
FlutterI18n.translate(
|
|
||||||
context,
|
context,
|
||||||
'homeView.notificationTitle',
|
'homeView.downloadingMessage',
|
||||||
),
|
|
||||||
FlutterI18n.translate(
|
|
||||||
context,
|
|
||||||
'homeView.notificationText',
|
|
||||||
),
|
|
||||||
const NotificationDetails(
|
|
||||||
android: AndroidNotificationDetails(
|
|
||||||
'revanced_manager_channel',
|
|
||||||
'ReVanced Manager Channel',
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
|
toastLength: Toast.LENGTH_LONG,
|
||||||
|
gravity: ToastGravity.CENTER,
|
||||||
);
|
);
|
||||||
try {
|
File? managerApk = await _managerAPI.downloadManager();
|
||||||
|
if (managerApk != null) {
|
||||||
|
await flutterLocalNotificationsPlugin.zonedSchedule(
|
||||||
|
0,
|
||||||
|
FlutterI18n.translate(
|
||||||
|
context,
|
||||||
|
'homeView.notificationTitle',
|
||||||
|
),
|
||||||
|
FlutterI18n.translate(
|
||||||
|
context,
|
||||||
|
'homeView.notificationText',
|
||||||
|
),
|
||||||
|
tz.TZDateTime.now(tz.local).add(const Duration(seconds: 5)),
|
||||||
|
const NotificationDetails(
|
||||||
|
android: AndroidNotificationDetails(
|
||||||
|
'revanced_manager_channel',
|
||||||
|
'ReVanced Manager Channel',
|
||||||
|
importance: Importance.max,
|
||||||
|
priority: Priority.high,
|
||||||
|
ticker: 'ticker',
|
||||||
|
),
|
||||||
|
),
|
||||||
|
androidAllowWhileIdle: true,
|
||||||
|
uiLocalNotificationDateInterpretation:
|
||||||
|
UILocalNotificationDateInterpretation.absoluteTime,
|
||||||
|
);
|
||||||
Fluttertoast.showToast(
|
Fluttertoast.showToast(
|
||||||
msg: FlutterI18n.translate(
|
msg: FlutterI18n.translate(
|
||||||
context,
|
context,
|
||||||
@ -140,21 +152,21 @@ class HomeViewModel extends BaseViewModel {
|
|||||||
gravity: ToastGravity.CENTER,
|
gravity: ToastGravity.CENTER,
|
||||||
);
|
);
|
||||||
await AppInstaller.installApk(managerApk.path);
|
await AppInstaller.installApk(managerApk.path);
|
||||||
} on Exception {
|
} else {
|
||||||
Fluttertoast.showToast(
|
Fluttertoast.showToast(
|
||||||
msg: FlutterI18n.translate(
|
msg: FlutterI18n.translate(
|
||||||
context,
|
context,
|
||||||
'homeView.errorInstallMessage',
|
'homeView.errorDownloadMessage',
|
||||||
),
|
),
|
||||||
toastLength: Toast.LENGTH_LONG,
|
toastLength: Toast.LENGTH_LONG,
|
||||||
gravity: ToastGravity.CENTER,
|
gravity: ToastGravity.CENTER,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} else {
|
} on Exception {
|
||||||
Fluttertoast.showToast(
|
Fluttertoast.showToast(
|
||||||
msg: FlutterI18n.translate(
|
msg: FlutterI18n.translate(
|
||||||
context,
|
context,
|
||||||
'homeView.errorDownloadMessage',
|
'homeView.errorInstallMessage',
|
||||||
),
|
),
|
||||||
toastLength: Toast.LENGTH_LONG,
|
toastLength: Toast.LENGTH_LONG,
|
||||||
gravity: ToastGravity.CENTER,
|
gravity: ToastGravity.CENTER,
|
||||||
@ -162,9 +174,9 @@ class HomeViewModel extends BaseViewModel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> showUpdateConfirmationDialog(BuildContext context) async {
|
Future<void> showUpdateConfirmationDialog(BuildContext parentContext) async {
|
||||||
return showDialog(
|
return showDialog(
|
||||||
context: context,
|
context: parentContext,
|
||||||
builder: (context) => AlertDialog(
|
builder: (context) => AlertDialog(
|
||||||
title: I18nText('homeView.updateDialogTitle'),
|
title: I18nText('homeView.updateDialogTitle'),
|
||||||
backgroundColor: Theme.of(context).colorScheme.secondaryContainer,
|
backgroundColor: Theme.of(context).colorScheme.secondaryContainer,
|
||||||
@ -179,7 +191,7 @@ class HomeViewModel extends BaseViewModel {
|
|||||||
label: I18nText('yesButton'),
|
label: I18nText('yesButton'),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
Navigator.of(context).pop();
|
Navigator.of(context).pop();
|
||||||
updateManager(context);
|
updateManager(parentContext);
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
|
@ -63,6 +63,7 @@ dependencies:
|
|||||||
stacked_services: ^0.9.3
|
stacked_services: ^0.9.3
|
||||||
stacked_themes: ^0.3.9
|
stacked_themes: ^0.3.9
|
||||||
timeago: ^3.2.2
|
timeago: ^3.2.2
|
||||||
|
timezone: ^0.8.0
|
||||||
url_launcher: ^6.1.5
|
url_launcher: ^6.1.5
|
||||||
wakelock: ^0.6.2
|
wakelock: ^0.6.2
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user