From 8f739d9e0b2ac3c04d3348f0238b71d22182062a Mon Sep 17 00:00:00 2001 From: Imran Remtulla Date: Mon, 28 Aug 2023 20:24:15 -0400 Subject: [PATCH] WiFi only BG update toggle (#819) + typo fix --- assets/translations/bs.json | 3 ++- assets/translations/de.json | 3 ++- assets/translations/en.json | 3 ++- assets/translations/es.json | 3 ++- assets/translations/fa.json | 3 ++- assets/translations/fr.json | 3 ++- assets/translations/hu.json | 3 ++- assets/translations/it.json | 3 ++- assets/translations/ja.json | 3 ++- assets/translations/pl.json | 3 ++- assets/translations/ru.json | 3 ++- assets/translations/zh.json | 3 ++- lib/pages/settings.dart | 27 ++++++++++++++++++++++++++- lib/providers/apps_provider.dart | 14 +++++++++++--- lib/providers/settings_provider.dart | 9 +++++++++ lib/providers/source_provider.dart | 4 ++-- pubspec.lock | 24 ++++++++++++++++++++++++ pubspec.yaml | 1 + 18 files changed, 97 insertions(+), 18 deletions(-) diff --git a/assets/translations/bs.json b/assets/translations/bs.json index 7a928a6..533ad5a 100644 --- a/assets/translations/bs.json +++ b/assets/translations/bs.json @@ -247,7 +247,8 @@ "backgroundUpdateReqsExplanation": "Background updates may not be possible for all apps.", "backgroundUpdateLimitsExplanation": "The success of a background install can only be determined when Obtainium is opened.", "verifyLatestTag": "Verify the 'latest' tag", - "examptFromBackgroundUpdates": "Exempt from background updates (if enabled)", + "exemptFromBackgroundUpdates": "Exempt from background updates (if enabled)", + "bgUpdatesOnWiFiOnly": "Disable background updates when not on WiFi", "removeAppQuestion": { "one": "Želite li ukloniti aplikaciju?", "other": "Želite li ukloniti aplikacije?" diff --git a/assets/translations/de.json b/assets/translations/de.json index 1c588a6..2233355 100644 --- a/assets/translations/de.json +++ b/assets/translations/de.json @@ -247,7 +247,8 @@ "backgroundUpdateReqsExplanation": "Background updates may not be possible for all apps.", "backgroundUpdateLimitsExplanation": "The success of a background install can only be determined when Obtainium is opened.", "verifyLatestTag": "Verify the 'latest' tag", - "examptFromBackgroundUpdates": "Exempt from background updates (if enabled)", + "exemptFromBackgroundUpdates": "Exempt from background updates (if enabled)", + "bgUpdatesOnWiFiOnly": "Disable background updates when not on WiFi", "removeAppQuestion": { "one": "App entfernen?", "other": "Apps entfernen?" diff --git a/assets/translations/en.json b/assets/translations/en.json index bbebf39..afb64d2 100644 --- a/assets/translations/en.json +++ b/assets/translations/en.json @@ -250,7 +250,8 @@ "verifyLatestTag": "Verify the 'latest' tag", "intermediateLinkRegex": "Filter for an 'Intermediate' Link to Visit First", "intermediateLinkNotFound": "Intermediate link not found", - "examptFromBackgroundUpdates": "Exempt from background updates (if enabled)", + "exemptFromBackgroundUpdates": "Exempt from background updates (if enabled)", + "bgUpdatesOnWiFiOnly": "Disable background updates when not on WiFi", "removeAppQuestion": { "one": "Remove App?", "other": "Remove Apps?" diff --git a/assets/translations/es.json b/assets/translations/es.json index 95626c1..6c07acc 100644 --- a/assets/translations/es.json +++ b/assets/translations/es.json @@ -247,7 +247,8 @@ "backgroundUpdateReqsExplanation": "Background updates may not be possible for all apps.", "backgroundUpdateLimitsExplanation": "The success of a background install can only be determined when Obtainium is opened.", "verifyLatestTag": "Verify the 'latest' tag", - "examptFromBackgroundUpdates": "Exempt from background updates (if enabled)", + "exemptFromBackgroundUpdates": "Exempt from background updates (if enabled)", + "bgUpdatesOnWiFiOnly": "Disable background updates when not on WiFi", "removeAppQuestion": { "one": "¿Eliminar Aplicación?", "other": "¿Eliminar Aplicaciones?" diff --git a/assets/translations/fa.json b/assets/translations/fa.json index b2bb37a..a35fb49 100644 --- a/assets/translations/fa.json +++ b/assets/translations/fa.json @@ -247,7 +247,8 @@ "backgroundUpdateReqsExplanation": "Background updates may not be possible for all apps.", "backgroundUpdateLimitsExplanation": "The success of a background install can only be determined when Obtainium is opened.", "verifyLatestTag": "Verify the 'latest' tag", - "examptFromBackgroundUpdates": "Exempt from background updates (if enabled)", + "exemptFromBackgroundUpdates": "Exempt from background updates (if enabled)", + "bgUpdatesOnWiFiOnly": "Disable background updates when not on WiFi", "removeAppQuestion": { "one": "برنامه حذف شود؟", "other": "برنامه ها حذف شوند؟" diff --git a/assets/translations/fr.json b/assets/translations/fr.json index 0b0a4d3..83a1d60 100644 --- a/assets/translations/fr.json +++ b/assets/translations/fr.json @@ -247,7 +247,8 @@ "backgroundUpdateReqsExplanation": "Background updates may not be possible for all apps.", "backgroundUpdateLimitsExplanation": "The success of a background install can only be determined when Obtainium is opened.", "verifyLatestTag": "Verify the 'latest' tag", - "examptFromBackgroundUpdates": "Exempt from background updates (if enabled)", + "exemptFromBackgroundUpdates": "Exempt from background updates (if enabled)", + "bgUpdatesOnWiFiOnly": "Disable background updates when not on WiFi", "removeAppQuestion": { "one": "Supprimer l'application ?", "other": "Supprimer les applications ?" diff --git a/assets/translations/hu.json b/assets/translations/hu.json index 80db119..54ca69b 100644 --- a/assets/translations/hu.json +++ b/assets/translations/hu.json @@ -246,7 +246,8 @@ "backgroundUpdateReqsExplanation": "Background updates may not be possible for all apps.", "backgroundUpdateLimitsExplanation": "The success of a background install can only be determined when Obtainium is opened.", "verifyLatestTag": "Verify the 'latest' tag", - "examptFromBackgroundUpdates": "Exempt from background updates (if enabled)", + "exemptFromBackgroundUpdates": "Exempt from background updates (if enabled)", + "bgUpdatesOnWiFiOnly": "Disable background updates when not on WiFi", "removeAppQuestion": { "one": "Eltávolítja az alkalmazást?", "other": "Eltávolítja az alkalmazást?" diff --git a/assets/translations/it.json b/assets/translations/it.json index addad9e..210bce0 100644 --- a/assets/translations/it.json +++ b/assets/translations/it.json @@ -247,7 +247,8 @@ "backgroundUpdateReqsExplanation": "Background updates may not be possible for all apps.", "backgroundUpdateLimitsExplanation": "The success of a background install can only be determined when Obtainium is opened.", "verifyLatestTag": "Verify the 'latest' tag", - "examptFromBackgroundUpdates": "Exempt from background updates (if enabled)", + "exemptFromBackgroundUpdates": "Exempt from background updates (if enabled)", + "bgUpdatesOnWiFiOnly": "Disable background updates when not on WiFi", "removeAppQuestion": { "one": "Rimuovere l'app?", "other": "Rimuovere le app?" diff --git a/assets/translations/ja.json b/assets/translations/ja.json index 1366fd0..fc11db1 100644 --- a/assets/translations/ja.json +++ b/assets/translations/ja.json @@ -248,7 +248,8 @@ "backgroundUpdateReqsExplanation": "バックグラウンドアップデートは、すべてのアプリで可能とは限りません。", "backgroundUpdateLimitsExplanation": "バックグラウンドアップデートが成功したかどうかは、Obtainiumを起動したときにしか判断できません。", "verifyLatestTag": "'latest'タグを確認する", - "examptFromBackgroundUpdates": "Exempt from background updates (if enabled)", + "exemptFromBackgroundUpdates": "Exempt from background updates (if enabled)", + "bgUpdatesOnWiFiOnly": "Disable background updates when not on WiFi", "removeAppQuestion": { "one": "アプリを削除しますか?", "other": "アプリを削除しますか?" diff --git a/assets/translations/pl.json b/assets/translations/pl.json index eacaa63..e3c4d34 100644 --- a/assets/translations/pl.json +++ b/assets/translations/pl.json @@ -253,7 +253,8 @@ "backgroundUpdateReqsExplanation": "Aktualizacje w tle mogą nie być możliwe dla wszystkich aplikacji.", "backgroundUpdateLimitsExplanation": "Powodzenie instalacji w tle można określić dopiero po otwarciu Obtainium.", "verifyLatestTag": "Zweryfikuj najnowszy tag", - "examptFromBackgroundUpdates": "Exempt from background updates (if enabled)", + "exemptFromBackgroundUpdates": "Exempt from background updates (if enabled)", + "bgUpdatesOnWiFiOnly": "Disable background updates when not on WiFi", "removeAppQuestion": { "one": "Usunąć aplikację?", "few": "Usunąć aplikacje?", diff --git a/assets/translations/ru.json b/assets/translations/ru.json index 48f47f3..91c5572 100644 --- a/assets/translations/ru.json +++ b/assets/translations/ru.json @@ -247,7 +247,8 @@ "backgroundUpdateReqsExplanation": "Background updates may not be possible for all apps.", "backgroundUpdateLimitsExplanation": "The success of a background install can only be determined when Obtainium is opened.", "verifyLatestTag": "Verify the 'latest' tag", - "examptFromBackgroundUpdates": "Exempt from background updates (if enabled)", + "exemptFromBackgroundUpdates": "Exempt from background updates (if enabled)", + "bgUpdatesOnWiFiOnly": "Disable background updates when not on WiFi", "removeAppQuestion": { "one": "Удалить приложение?", "other": "Удалить приложения?" diff --git a/assets/translations/zh.json b/assets/translations/zh.json index 9457fe1..6ab56a0 100644 --- a/assets/translations/zh.json +++ b/assets/translations/zh.json @@ -247,8 +247,9 @@ "enableBackgroundUpdates": "启用后台更新", "backgroundUpdateReqsExplanation": "后台更新未必适用于所有的应用。", "backgroundUpdateLimitsExplanation": "只有在启动 Obtainium 时才能确认安装是否成功。", - "examptFromBackgroundUpdates": "Exempt from background updates (if enabled)", "verifyLatestTag": "验证“Latest”标签", + "exemptFromBackgroundUpdates": "Exempt from background updates (if enabled)", + "bgUpdatesOnWiFiOnly": "Disable background updates when not on WiFi", "removeAppQuestion": { "one": "是否删除应用?", "other": "是否删除应用?" diff --git a/lib/pages/settings.dart b/lib/pages/settings.dart index cd5ce5a..ec19efb 100644 --- a/lib/pages/settings.dart +++ b/lib/pages/settings.dart @@ -252,7 +252,32 @@ class _SettingsPageState extends State { style: Theme.of(context) .textTheme .labelSmall), - height8 + height8, + if (settingsProvider + .enableBackgroundUpdates) + Column( + children: [ + height16, + Row( + mainAxisAlignment: + MainAxisAlignment + .spaceBetween, + children: [ + Flexible( + child: Text(tr( + 'bgUpdatesOnWiFiOnly'))), + Switch( + value: settingsProvider + .bgUpdatesOnWiFiOnly, + onChanged: (value) { + settingsProvider + .bgUpdatesOnWiFiOnly = + value; + }) + ], + ), + ], + ), ], ) : const SizedBox.shrink(); diff --git a/lib/providers/apps_provider.dart b/lib/providers/apps_provider.dart index 08523c4..5017e26 100644 --- a/lib/providers/apps_provider.dart +++ b/lib/providers/apps_provider.dart @@ -9,6 +9,7 @@ import 'package:android_alarm_manager_plus/android_alarm_manager_plus.dart'; import 'package:android_intent_plus/flag.dart'; import 'package:android_package_installer/android_package_installer.dart'; import 'package:android_package_manager/android_package_manager.dart'; +import 'package:connectivity_plus/connectivity_plus.dart'; import 'package:device_info_plus/device_info_plus.dart'; import 'package:easy_localization/easy_localization.dart'; import 'package:flutter/material.dart'; @@ -366,7 +367,7 @@ class AppsProvider with ChangeNotifier { if (!settingsProvider.enableBackgroundUpdates) { return false; } - if (app.additionalSettings['examptFromBackgroundUpdates'] == true) { + if (app.additionalSettings['exemptFromBackgroundUpdates'] == true) { return false; } if (app.apkUrls.length > 1) { @@ -1323,6 +1324,12 @@ Future bgUpdateCheck(int taskId, Map? params) async { // If in update mode... var didCompleteChecking = false; CheckingUpdatesNotification? notif; + var networkRestricted = false; + if (settingsProvider.bgUpdatesOnWiFiOnly) { + var netResult = await (Connectivity().checkConnectivity()); + networkRestricted = (netResult != ConnectivityResult.wifi) && + (netResult != ConnectivityResult.ethernet); + } // Loop through all updates and check each for (int i = 0; i < toCheck.length; i++) { var appId = toCheck[i].key; @@ -1335,8 +1342,9 @@ Future bgUpdateCheck(int taskId, Map? params) async { cancelExisting: true); App? newApp = await appsProvider.checkUpdate(appId); if (newApp != null) { - if (!(await appsProvider.canInstallSilently( - app!.app, settingsProvider))) { + if (networkRestricted || + !(await appsProvider.canInstallSilently( + app!.app, settingsProvider))) { notificationsProvider.notify( UpdateNotification([newApp], id: newApp.id.hashCode - 1)); } else { diff --git a/lib/providers/settings_provider.dart b/lib/providers/settings_provider.dart index 7495c9b..0ccae4a 100644 --- a/lib/providers/settings_provider.dart +++ b/lib/providers/settings_provider.dart @@ -319,6 +319,15 @@ class SettingsProvider with ChangeNotifier { notifyListeners(); } + bool get bgUpdatesOnWiFiOnly { + return prefs?.getBool('bgUpdatesOnWiFiOnly') ?? false; + } + + set bgUpdatesOnWiFiOnly(bool val) { + prefs?.setBool('bgUpdatesOnWiFiOnly', val); + notifyListeners(); + } + DateTime get lastBGCheckTime { int? temp = prefs?.getInt('lastBGCheckTime'); return temp != null diff --git a/lib/providers/source_provider.dart b/lib/providers/source_provider.dart index e0e11e7..5494362 100644 --- a/lib/providers/source_provider.dart +++ b/lib/providers/source_provider.dart @@ -427,8 +427,8 @@ abstract class AppSource { ], [GeneratedFormTextField('appName', label: tr('appName'), required: false)], [ - GeneratedFormSwitch('examptFromBackgroundUpdates', - label: tr('examptFromBackgroundUpdates')) + GeneratedFormSwitch('exemptFromBackgroundUpdates', + label: tr('exemptFromBackgroundUpdates')) ] ]; diff --git a/pubspec.lock b/pubspec.lock index b717324..a9d3711 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -114,6 +114,22 @@ packages: url: "https://pub.dev" source: hosted version: "1.17.2" + connectivity_plus: + dependency: "direct main" + description: + name: connectivity_plus + sha256: "77a180d6938f78ca7d2382d2240eb626c0f6a735d0bfdce227d8ffb80f95c48b" + url: "https://pub.dev" + source: hosted + version: "4.0.2" + connectivity_plus_platform_interface: + dependency: transitive + description: + name: connectivity_plus_platform_interface + sha256: cf1d1c28f4416f8c654d7dc3cd638ec586076255d407cef3ddbdaf178272a71a + url: "https://pub.dev" + source: hosted + version: "1.2.4" convert: dependency: transitive description: @@ -454,6 +470,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.0.0" + nm: + dependency: transitive + description: + name: nm + sha256: "2c9aae4127bdc8993206464fcc063611e0e36e72018696cd9631023a31b24254" + url: "https://pub.dev" + source: hosted + version: "0.5.0" path: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 60254c0..3810687 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -64,6 +64,7 @@ dependencies: flutter_markdown: ^0.6.14 flutter_archive: ^5.0.0 hsluv: ^1.1.3 + connectivity_plus: ^4.0.2 dev_dependencies: flutter_test: