Skip to content

Commit

Permalink
Merge pull request #1916 from ImranR98/dev
Browse files Browse the repository at this point in the history
- APKPure: Fix issue with characters in URLs (#1912)
- APKPure: Fix bug with versionCode not found
- Optional "when charging only" toggle for BG updates (#1914)
  • Loading branch information
ImranR98 authored Oct 20, 2024
2 parents ba8ef7e + ea239ff commit 09f1f27
Show file tree
Hide file tree
Showing 29 changed files with 124 additions and 45 deletions.
1 change: 1 addition & 0 deletions assets/translations/bs.json
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@
"intermediateLink": "Intermediate veza",
"exemptFromBackgroundUpdates": "Izuzmi iz ažuriranja u pozadini (ako su uključeni)",
"bgUpdatesOnWiFiOnly": "Isključite ažuriranje u pozadini kada niste na WiFi-ju",
"bgUpdatesWhileChargingOnly": "Disable background updates when not charging",
"autoSelectHighestVersionCode": "Automatski izaberite najveću (verziju) versionCode APK-a",
"versionExtractionRegEx": "RegEx ekstrakcija verzije",
"trimVersionString": "Trim Version String With RegEx",
Expand Down
1 change: 1 addition & 0 deletions assets/translations/cs.json
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@
"intermediateLink": "Připojený odkaz",
"exemptFromBackgroundUpdates": "Vyloučit z aktualizací na pozadí (je-li povoleno)",
"bgUpdatesOnWiFiOnly": "Deaktivovat aktualizace na pozadí, pokud není k dispozici Wi-Fi",
"bgUpdatesWhileChargingOnly": "Zakázat aktualizace na pozadí, když se nenabíjí",
"autoSelectHighestVersionCode": "Automaticky vybrat nejvyšší verzi APK",
"versionExtractionRegEx": "Extrakce verze pomocí RegEx",
"trimVersionString": "Oříznutí řetězce verze pomocí příkazu RegEx",
Expand Down
1 change: 1 addition & 0 deletions assets/translations/da.json
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@
"intermediateLink": "Mellemliggende link",
"exemptFromBackgroundUpdates": "Undtag fra baggrundsopdateringer (hvis aktiveret)",
"bgUpdatesOnWiFiOnly": "Deaktivér baggrundsopdateringer, når du ikke er på WiFi",
"bgUpdatesWhileChargingOnly": "Deaktiver baggrundsopdateringer, når der ikke oplades",
"autoSelectHighestVersionCode": "Auto-vælg højeste versionKode af APK",
"versionExtractionRegEx": "RegEx for versionsstrengsudtrækning",
"trimVersionString": "Trim versionsstrengen med RegEx",
Expand Down
1 change: 1 addition & 0 deletions assets/translations/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@
"intermediateLink": "„Zwischen“-Link",
"exemptFromBackgroundUpdates": "Ausschluss von Hintergrundaktualisierungen (falls aktiviert)",
"bgUpdatesOnWiFiOnly": "Hintergrundaktualisierungen deaktivieren, wenn kein WLAN vorhanden ist",
"bgUpdatesWhileChargingOnly": "Hintergrundaktualisierungen deaktivieren, wenn nicht geladen wird",
"autoSelectHighestVersionCode": "Automatisch höchste APK-Version auswählen",
"versionExtractionRegEx": "Versionsextraktion per RegEx",
"trimVersionString": "Versionszeichenfolge mit RegEx kürzen",
Expand Down
1 change: 1 addition & 0 deletions assets/translations/en-EO.json
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@
"intermediateLink": "Pera ligilo",
"exemptFromBackgroundUpdates": "Escepti el la fonaj ĝisdatigoj (se aktiva)",
"bgUpdatesOnWiFiOnly": "Malaktivigi fonajn ĝisdatigojn se sen vifio",
"bgUpdatesWhileChargingOnly": "Disable background updates when not charging",
"autoSelectHighestVersionCode": "Aŭtomate selekti la plej ĵusan version de la APK-kodo",
"versionExtractionRegEx": "Ekstrakti la versioĉenon per regula esprimo",
"trimVersionString": "Mallongigi la versioĉenon per regula esprimo",
Expand Down
1 change: 1 addition & 0 deletions assets/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@
"intermediateLink": "Intermediate link",
"exemptFromBackgroundUpdates": "Exempt from background updates (if enabled)",
"bgUpdatesOnWiFiOnly": "Disable background updates when not on WiFi",
"bgUpdatesWhileChargingOnly": "Disable background updates when not charging",
"autoSelectHighestVersionCode": "Auto-select highest versionCode APK",
"versionExtractionRegEx": "Version String Extraction RegEx",
"trimVersionString": "Trim Version String With RegEx",
Expand Down
1 change: 1 addition & 0 deletions assets/translations/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@
"intermediateLink": "Enlace intermedio",
"exemptFromBackgroundUpdates": "Exenta de actualizciones en segundo plano (si están habilitadas)",
"bgUpdatesOnWiFiOnly": "Deshabilitar las actualizaciones en segundo plano sin WiFi",
"bgUpdatesWhileChargingOnly": "Desactiva las actualizaciones en segundo plano cuando no estés cargando",
"autoSelectHighestVersionCode": "Auto selección del paquete APK con versión más reciente",
"versionExtractionRegEx": "Versión de extracción regex",
"trimVersionString": "Recortar cadena de versión con RegEx",
Expand Down
1 change: 1 addition & 0 deletions assets/translations/fa.json
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@
"intermediateLink": "پیوند میانی",
"exemptFromBackgroundUpdates": "معاف از به‌روزرسانی‌های پس‌زمینه (در صورت فعال بودن)",
"bgUpdatesOnWiFiOnly": "به‌روزرسانی‌های پس‌زمینه را در صورت عدم اتصال به WiFi غیرفعال کنید",
"bgUpdatesWhileChargingOnly": "Disable background updates when not charging",
"autoSelectHighestVersionCode": "انتخاب خودکار بالاترین نسخه کد APK",
"versionExtractionRegEx": "نسخه استخراج RegEx",
"trimVersionString": "برش رشته نسخه با RegEx",
Expand Down
1 change: 1 addition & 0 deletions assets/translations/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@
"intermediateLink": "Lien intermédiaire",
"exemptFromBackgroundUpdates": "Exclure de la mise à jour en arrière-plan (si activé)",
"bgUpdatesOnWiFiOnly": "Désactiver les mises à jour en arrière-plan lorsque vous n'êtes pas en WiFi",
"bgUpdatesWhileChargingOnly": "Désactiver les mises à jour en arrière-plan lorsque le véhicule n'est pas en charge",
"autoSelectHighestVersionCode": "Sélectionner automatiquement la version la plus récente du code APK",
"versionExtractionRegEx": "Extraire la version par Expression régulière",
"trimVersionString": "Découper la version par Expression régulière",
Expand Down
1 change: 1 addition & 0 deletions assets/translations/hu.json
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@
"intermediateLink": "Köztes hivatkozás",
"exemptFromBackgroundUpdates": "Mentes a háttérben történő frissítések alól (ha engedélyezett)",
"bgUpdatesOnWiFiOnly": "A háttérben történő frissítések letiltása, ha nincs Wi-Fi",
"bgUpdatesWhileChargingOnly": "Háttérfrissítések letiltása, ha nincs töltés",
"autoSelectHighestVersionCode": "A legmagasabb verziókódú APK automatikus kiválasztása",
"versionExtractionRegEx": "Verzió-karakterlánc kivonatolása reguláris kifejezéssel",
"trimVersionString": "Verzió-karakterlánc levágása reguláris kifejezéssel",
Expand Down
1 change: 1 addition & 0 deletions assets/translations/id.json
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@
"intermediateLink": "Tautan perantara",
"exemptFromBackgroundUpdates": "Dikecualikan dari pembaruan latar belakang (jika diaktifkan)",
"bgUpdatesOnWiFiOnly": "Nonaktifkan pembaruan latar belakang saat tidak menggunakan WiFi",
"bgUpdatesWhileChargingOnly": "Menonaktifkan pembaruan latar belakang saat tidak mengisi daya",
"autoSelectHighestVersionCode": "Pilih otomatis APK dengan versi kode tertinggi",
"versionExtractionRegEx": "Reguler ekspresi terkait ekstraksi versi string",
"trimVersionString": "Potong versi string dengan reguler ekspresi",
Expand Down
1 change: 1 addition & 0 deletions assets/translations/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@
"intermediateLink": "Collegamento intermedio",
"exemptFromBackgroundUpdates": "Esente da aggiornamenti in secondo piano (se attivo)",
"bgUpdatesOnWiFiOnly": "Disattiva aggiornamenti in secondo piano quando non si usa il WiFi",
"bgUpdatesWhileChargingOnly": "Disabilita gli aggiornamenti in background quando non è in carica",
"autoSelectHighestVersionCode": "Auto-seleziona APK con versionCode più alto",
"versionExtractionRegEx": "RegEx di estrazione versione",
"trimVersionString": "Tagliare la stringa della versione con RegEx",
Expand Down
1 change: 1 addition & 0 deletions assets/translations/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@
"intermediateLink": "中間リンク",
"exemptFromBackgroundUpdates": "バックグラウンドアップデートを行わない (有効な場合)",
"bgUpdatesOnWiFiOnly": "WiFiを使用していない場合、バックグラウンドアップデートを無効にする",
"bgUpdatesWhileChargingOnly": "非充電時にバックグラウンド更新を無効にする",
"autoSelectHighestVersionCode": "最も高いバージョンコードのAPKを自動で選択する",
"versionExtractionRegEx": "バージョン抽出の正規表現",
"trimVersionString": "正規表現でバージョン文字列をトリムする",
Expand Down
1 change: 1 addition & 0 deletions assets/translations/nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@
"intermediateLink": "Intermediaire link",
"exemptFromBackgroundUpdates": "Vrijgesteld van achtergrond-updates (indien ingeschakeld)",
"bgUpdatesOnWiFiOnly": "Achtergrond-updates uitschakelen wanneer niet verbonden met WiFi",
"bgUpdatesWhileChargingOnly": "Achtergrondupdates uitschakelen als er niet wordt opgeladen",
"autoSelectHighestVersionCode": "De APK met de hoogste versiecode automatisch selecteren",
"versionExtractionRegEx": "Reguliere expressie voor versie-extractie",
"trimVersionString": "Versie string trimmen met RegEx",
Expand Down
1 change: 1 addition & 0 deletions assets/translations/pl.json
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@
"intermediateLink": "Łącze pośrednie",
"exemptFromBackgroundUpdates": "Wyklucz z uaktualnień w tle (jeśli są włączone)",
"bgUpdatesOnWiFiOnly": "Wyłącz aktualizacje w tle, gdy nie ma połączenia z Wi-Fi",
"bgUpdatesWhileChargingOnly": "Wyłącz aktualizacje w tle, gdy urządzenie nie jest ładowane",
"autoSelectHighestVersionCode": "Automatycznie wybierz najwyższy kod wersji APK",
"versionExtractionRegEx": "Wyrażenie regularne wyodrębniające wersję",
"trimVersionString": "Przycinanie łańcucha wersji za pomocą RegEx",
Expand Down
1 change: 1 addition & 0 deletions assets/translations/pt.json
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@
"intermediateLink": "Link intermediário",
"exemptFromBackgroundUpdates": "Isento de atualizações em segundo-plano (se ativadas)",
"bgUpdatesOnWiFiOnly": "Desative as atualizações em segundo-plano quando não estiver conectado no Wi-Fi",
"bgUpdatesWhileChargingOnly": "Desativar actualizações em segundo plano quando não estiver a carregar",
"autoSelectHighestVersionCode": "Auto-selecionar a versão mais recente",
"versionExtractionRegEx": "Regex de extração de versão",
"trimVersionString": "Cortar a cadeia de caracteres da versão com RegEx",
Expand Down
1 change: 1 addition & 0 deletions assets/translations/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@
"intermediateLink": "Промежуточная ссылка",
"exemptFromBackgroundUpdates": "Исключить из фоновых обновлений (если включено)",
"bgUpdatesOnWiFiOnly": "Отключить фоновые обновления, если нет соединения с Wi-Fi",
"bgUpdatesWhileChargingOnly": "Отключение фоновых обновлений при отсутствии зарядки",
"autoSelectHighestVersionCode": "Автоматически выбирать APK с актуальной версией кода",
"versionExtractionRegEx": "Регулярное выражение для извлечения версии",
"trimVersionString": "Обрезка строки версии с помощью RegEx",
Expand Down
1 change: 1 addition & 0 deletions assets/translations/sv.json
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@
"intermediateLink": "Mellanlänk",
"exemptFromBackgroundUpdates": "Undta från bakgrundsuppdateringar (om aktiverad)",
"bgUpdatesOnWiFiOnly": "Inaktivera Bakgrundsuppdateringar utan WiFi",
"bgUpdatesWhileChargingOnly": "Inaktivera bakgrundsuppdateringar när du inte laddar",
"autoSelectHighestVersionCode": "Välj automatiskt högsta versionskod APK",
"versionExtractionRegEx": "Version Extraction RegEx",
"trimVersionString": "Trimma versionssträng med RegEx",
Expand Down
1 change: 1 addition & 0 deletions assets/translations/tr.json
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@
"intermediateLink": "Ara bağlantı",
"exemptFromBackgroundUpdates": "Arka plan güncellemelerinden muaf tut (etkinse)",
"bgUpdatesOnWiFiOnly": "WiFi olmadığında arka plan güncellemelerini devre dışı bırak",
"bgUpdatesWhileChargingOnly": "Şarj olmadığında arka plan güncellemelerini devre dışı bırakma",
"autoSelectHighestVersionCode": "Otomatik olarak en yüksek sürüm kodunu seç",
"versionExtractionRegEx": "Sürüm Çıkarma Düzenli İfade",
"trimVersionString": "RegEx ile Sürüm Dizesini Kırpma",
Expand Down
1 change: 1 addition & 0 deletions assets/translations/uk.json
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@
"intermediateLink": "Проміжне посилання",
"exemptFromBackgroundUpdates": "Виключено з фонових оновлень (якщо ввімкнено)",
"bgUpdatesOnWiFiOnly": "Вимкнути фонові оновлення поза Wi-Fi",
"bgUpdatesWhileChargingOnly": "Вимкнути фонові оновлення, коли не заряджається",
"autoSelectHighestVersionCode": "Автоматичний вибір APK з найвищим кодом версії",
"versionExtractionRegEx": "Регулярний вираз для вилучення рядка версії",
"trimVersionString": "Обрізати рядок версії за допомогою RegEx",
Expand Down
1 change: 1 addition & 0 deletions assets/translations/vi.json
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@
"intermediateLink": "Liên kết trung gian",
"exemptFromBackgroundUpdates": "Miễn cập nhật nền (nếu được bật)",
"bgUpdatesOnWiFiOnly": "Tắt cập nhật nền khi không có WiFi",
"bgUpdatesWhileChargingOnly": "Disable background updates when not charging",
"autoSelectHighestVersionCode": "Tự động chọn APK mã phiên bản cao nhất",
"versionExtractionRegEx": "Trích xuất phiên bản RegEx",
"trimVersionString": "Trim Version String With RegEx",
Expand Down
1 change: 1 addition & 0 deletions assets/translations/zh-Hant-TW.json
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@
"intermediateLink": "中間連結",
"exemptFromBackgroundUpdates": "免除背景更新(若已啟用)",
"bgUpdatesOnWiFiOnly": "停用非 WiFi 的背景更新",
"bgUpdatesWhileChargingOnly": "Disable background updates when not charging",
"autoSelectHighestVersionCode": "自動選擇最高 versionCode 的 APK",
"versionExtractionRegEx": "版本字串提取正則表達式",
"trimVersionString": "用正則表達式修剪版本字串",
Expand Down
1 change: 1 addition & 0 deletions assets/translations/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@
"intermediateLink": "中转链接",
"exemptFromBackgroundUpdates": "禁用后台更新(仅此应用生效,即使已启用全局后台更新)",
"bgUpdatesOnWiFiOnly": "未连接 Wi-Fi 时禁用后台更新",
"bgUpdatesWhileChargingOnly": "不充电时禁用后台更新",
"autoSelectHighestVersionCode": "自动选择内部版本号最高的 APK 文件",
"versionExtractionRegEx": "提取版本号的正则表达式",
"trimVersionString": "使用 RegEx 修剪版本字符串",
Expand Down
9 changes: 4 additions & 5 deletions lib/app_sources/apkpure.dart
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,9 @@ class APKPure extends AppSource {
// Unclear why there can even be multiple APKs for the same version and arch
var apkInfo = e.nextElementSibling?.querySelector('div.info');
String? versionCode = RegExp('[0-9]+')
.firstMatch(apkInfo
?.querySelector('div.info-top span.code')
?.text ??
'')
.firstMatch(
apkInfo?.querySelector('div.info-top .code')?.text ??
'')
?.group(0)
?.trim();
var types = apkInfo
Expand Down Expand Up @@ -167,7 +166,7 @@ class APKPure extends AppSource {
var res0 = await sourceRequest('$standardUrl/versions', additionalSettings);
var versionLinks = await grabLinksCommon(res0, {
'skipSort': true,
'customLinkFilterRegex': '$standardUrl/download/[^/]+\$'
'customLinkFilterRegex': '${Uri.decodeFull(standardUrl)}/download/[^/]+\$'
});

var supportedArchs = (await DeviceInfoPlugin().androidInfo).supportedAbis;
Expand Down
19 changes: 19 additions & 0 deletions lib/pages/settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,25 @@ class _SettingsPageState extends State<SettingsPage> {
})
],
),
height16,
Row(
mainAxisAlignment:
MainAxisAlignment
.spaceBetween,
children: [
Flexible(
child: Text(tr(
'bgUpdatesWhileChargingOnly'))),
Switch(
value: settingsProvider
.bgUpdatesWhileChargingOnly,
onChanged: (value) {
settingsProvider
.bgUpdatesWhileChargingOnly =
value;
})
],
),
],
),
],
Expand Down
30 changes: 17 additions & 13 deletions lib/providers/apps_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'dart:async';
import 'dart:convert';
import 'dart:io';
import 'dart:math';
import 'package:battery_plus/battery_plus.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:http/http.dart' as http;
import 'package:crypto/crypto.dart';
Expand Down Expand Up @@ -1885,10 +1886,20 @@ Future<void> bgUpdateCheck(String taskId, Map<String, dynamic>? params) async {
(<List<MapEntry<String, int>>>[]))
];

var networkRestricted = false;
if (appsProvider.settingsProvider.bgUpdatesOnWiFiOnly) {
networkRestricted = !netResult.contains(ConnectivityResult.wifi) &&
!netResult.contains(ConnectivityResult.ethernet);
var networkRestricted = appsProvider.settingsProvider.bgUpdatesOnWiFiOnly &&
!netResult.contains(ConnectivityResult.wifi) &&
!netResult.contains(ConnectivityResult.ethernet);

var chargingRestricted =
appsProvider.settingsProvider.bgUpdatesWhileChargingOnly &&
(await Battery().batteryState) != BatteryState.charging;

if (networkRestricted) {
logs.add('BG update task: Network restriction in effect.');
}

if (chargingRestricted) {
logs.add('BG update task: Charging restriction in effect.');
}

if (toCheck.isNotEmpty) {
Expand Down Expand Up @@ -1928,14 +1939,6 @@ Future<void> bgUpdateCheck(String taskId, Map<String, dynamic>? params) async {
CheckingUpdatesNotification notif = CheckingUpdatesNotification(
plural('apps', toCheck.length)); // The notif. to show while checking

// Set a bool for when we're no on wifi/wired and the user doesn't want to download apps in that state
var networkRestricted = false;
if (appsProvider.settingsProvider.bgUpdatesOnWiFiOnly) {
var netResult = await (Connectivity().checkConnectivity());
networkRestricted = !netResult.contains(ConnectivityResult.wifi) &&
!netResult.contains(ConnectivityResult.ethernet);
}

try {
// Check for updates
notificationsProvider.notify(notif, cancelExisting: true);
Expand Down Expand Up @@ -1983,6 +1986,7 @@ Future<void> bgUpdateCheck(String taskId, Map<String, dynamic>? params) async {
// Filter out updates that will be installed silently (the rest go into toNotify)
for (var i = 0; i < updates.length; i++) {
if (networkRestricted ||
chargingRestricted ||
!(await appsProvider.canInstallSilently(updates[i]))) {
if (updates[i].additionalSettings['skipUpdateNotifications'] != true) {
toNotify.add(updates[i]);
Expand Down Expand Up @@ -2029,7 +2033,7 @@ Future<void> bgUpdateCheck(String taskId, Map<String, dynamic>? params) async {
} else {
// In install mode...
// If you haven't explicitly been given updates to install, grab all available silent updates
if (toInstall.isEmpty && !networkRestricted) {
if (toInstall.isEmpty && !networkRestricted && !chargingRestricted) {
var temp = appsProvider.findExistingUpdates(installedOnly: true);
for (var i = 0; i < temp.length; i++) {
if (await appsProvider
Expand Down
9 changes: 9 additions & 0 deletions lib/providers/settings_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,15 @@ class SettingsProvider with ChangeNotifier {
notifyListeners();
}

bool get bgUpdatesWhileChargingOnly {
return prefs?.getBool('bgUpdatesWhileChargingOnly') ?? false;
}

set bgUpdatesWhileChargingOnly(bool val) {
prefs?.setBool('bgUpdatesWhileChargingOnly', val);
notifyListeners();
}

DateTime get lastCompletedBGCheckTime {
int? temp = prefs?.getInt('lastCompletedBGCheckTime');
return temp != null
Expand Down
Loading

0 comments on commit 09f1f27

Please sign in to comment.