diff --git a/assets/i18n/en.json b/assets/i18n/en.json index 9ec665ad..3c49988e 100644 --- a/assets/i18n/en.json +++ b/assets/i18n/en.json @@ -25,7 +25,8 @@ "downloadingMessage": "Downloading update!", "installingMessage": "Installing update!", "errorDownloadMessage": "Unable to download update!", - "errorInstallMessage": "Unable to download update!" + "errorInstallMessage": "Unable to download update!", + "noConnection": "No internet connection" }, "applicationItem": { "patchButton": "Patch", diff --git a/lib/ui/views/home/home_view.dart b/lib/ui/views/home/home_view.dart index 495aaf80..46c2b038 100644 --- a/lib/ui/views/home/home_view.dart +++ b/lib/ui/views/home/home_view.dart @@ -17,13 +17,13 @@ class HomeView extends StatelessWidget { Widget build(BuildContext context) { return ViewModelBuilder.reactive( disposeViewModel: false, - onModelReady: (model) => model.initialize(), + onModelReady: (model) => model.initialize(context), viewModelBuilder: () => locator(), builder: (context, model, child) => Scaffold( body: RefreshIndicator( color: Theme.of(context).colorScheme.secondary, backgroundColor: Theme.of(context).colorScheme.secondaryContainer, - onRefresh: () => model.forceRefresh(), + onRefresh: () => model.forceRefresh(context), child: CustomScrollView( slivers: [ CustomSliverAppBar( diff --git a/lib/ui/views/home/home_viewmodel.dart b/lib/ui/views/home/home_viewmodel.dart index 67ceb469..77fd2341 100644 --- a/lib/ui/views/home/home_viewmodel.dart +++ b/lib/ui/views/home/home_viewmodel.dart @@ -1,6 +1,7 @@ // ignore_for_file: use_build_context_synchronously import 'dart:io'; import 'package:app_installer/app_installer.dart'; +import 'package:cross_connectivity/cross_connectivity.dart'; import 'package:device_apps/device_apps.dart'; import 'package:flutter/material.dart'; import 'package:flutter_i18n/flutter_i18n.dart'; @@ -29,13 +30,24 @@ class HomeViewModel extends BaseViewModel { List patchedInstalledApps = []; List patchedUpdatableApps = []; - Future initialize() async { + Future initialize(BuildContext context) async { await flutterLocalNotificationsPlugin.initialize( const InitializationSettings( android: AndroidInitializationSettings('ic_notification'), ), onSelectNotification: (p) => DeviceApps.openApp('app.revanced.manager'), ); + bool isConnected = await Connectivity().checkConnection(); + if (!isConnected) { + Fluttertoast.showToast( + msg: FlutterI18n.translate( + context, + 'homeView.noConnection', + ), + toastLength: Toast.LENGTH_LONG, + gravity: ToastGravity.CENTER, + ); + } _getPatchedApps(); _managerAPI.reAssessSavedApps().then((_) => _getPatchedApps()); } @@ -176,12 +188,12 @@ class HomeViewModel extends BaseViewModel { return _managerAPI.getLatestManagerReleaseTime(); } - Future forceRefresh() async { + Future forceRefresh(BuildContext context) async { await Future.delayed(const Duration(seconds: 1)); if (_lastUpdate == null || _lastUpdate!.difference(DateTime.now()).inSeconds > 60) { _managerAPI.clearAllData(); } - initialize(); + initialize(context); } } diff --git a/lib/ui/widgets/appInfoView/app_info_viewmodel.dart b/lib/ui/widgets/appInfoView/app_info_viewmodel.dart index 97da896f..3059aa4c 100644 --- a/lib/ui/widgets/appInfoView/app_info_viewmodel.dart +++ b/lib/ui/widgets/appInfoView/app_info_viewmodel.dart @@ -74,7 +74,7 @@ class AppInfoViewModel extends BaseViewModel { label: I18nText('okButton'), onPressed: () { uninstallApp(app); - locator().initialize(); + locator().initialize(context); Navigator.of(context).pop(); Navigator.of(context).pop(); }, diff --git a/pubspec.yaml b/pubspec.yaml index 0fb0768e..f9572626 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -12,6 +12,7 @@ environment: dependencies: animations: ^2.0.4 app_installer: ^1.1.0 + cross_connectivity: ^3.0.5 device_apps: git: url: https://github.com/ponces/flutter_plugin_device_apps