From 3ec33a1c778c56dcbae28dfe6cc4190be85e8e38 Mon Sep 17 00:00:00 2001 From: Imran Remtulla Date: Fri, 14 Jul 2023 21:09:20 -0400 Subject: [PATCH] Add auto-remove option (#656) + on-foreground bugfix --- assets/translations/de.json | 1 + assets/translations/en.json | 1 + assets/translations/es.json | 1 + assets/translations/fa.json | 1 + assets/translations/fr.json | 1 + assets/translations/hu.json | 1 + assets/translations/it.json | 1 + assets/translations/ja.json | 1 + assets/translations/pl.json | 1 + assets/translations/ru.json | 1 + assets/translations/zh.json | 1 + lib/main.dart | 4 ++-- lib/pages/settings.dart | 16 +++++++++++++ lib/providers/apps_provider.dart | 36 +++++++++++++++++++++------- lib/providers/settings_provider.dart | 9 +++++++ 15 files changed, 65 insertions(+), 11 deletions(-) diff --git a/assets/translations/de.json b/assets/translations/de.json index f68da68..87ecd2d 100644 --- a/assets/translations/de.json +++ b/assets/translations/de.json @@ -234,6 +234,7 @@ "requiresCredentialsInSettings": "Benötigt zusätzliche Anmeldedaten (in den Einstellungen)", "checkOnStart": "Überprüfe einmalig beim Start", "tryInferAppIdFromCode": "Try inferring App ID from source code", + "removeOnExternalUninstall": "Automatically remove externally uninstalled Apps", "removeAppQuestion": { "one": "App entfernen?", "other": "Apps entfernen?" diff --git a/assets/translations/en.json b/assets/translations/en.json index e9b4503..8bed92b 100644 --- a/assets/translations/en.json +++ b/assets/translations/en.json @@ -234,6 +234,7 @@ "requiresCredentialsInSettings": "This needs additional credentials (in Settings)", "checkOnStart": "Check Once on Start", "tryInferAppIdFromCode": "Try inferring App ID from source code", + "removeOnExternalUninstall": "Automatically remove externally uninstalled Apps", "removeAppQuestion": { "one": "Remove App?", "other": "Remove Apps?" diff --git a/assets/translations/es.json b/assets/translations/es.json index 6c7cc05..3f05649 100644 --- a/assets/translations/es.json +++ b/assets/translations/es.json @@ -234,6 +234,7 @@ "requiresCredentialsInSettings": "This needs additional credentials (in Settings)", "checkOnStart": "Check Once on Start", "tryInferAppIdFromCode": "Try inferring App ID from source code", + "removeOnExternalUninstall": "Automatically remove externally uninstalled Apps", "removeAppQuestion": { "one": "¿Eliminar Aplicación?", "other": "¿Eliminar Aplicaciones?" diff --git a/assets/translations/fa.json b/assets/translations/fa.json index 555868d..1673f7b 100644 --- a/assets/translations/fa.json +++ b/assets/translations/fa.json @@ -234,6 +234,7 @@ "requiresCredentialsInSettings": "این به اعتبارنامه های اضافی نیاز دارد (در تنظیمات)", "checkOnStart": "بررسی در شروع", "tryInferAppIdFromCode": "شناسه برنامه را از کد منبع استنباط کنید", + "removeOnExternalUninstall": "Automatically remove externally uninstalled Apps", "removeAppQuestion": { "one": "برنامه حذف شود؟", "other": "برنامه ها حذف شوند؟" diff --git a/assets/translations/fr.json b/assets/translations/fr.json index ea60088..6a804b6 100644 --- a/assets/translations/fr.json +++ b/assets/translations/fr.json @@ -234,6 +234,7 @@ "requiresCredentialsInSettings": "This needs additional credentials (in Settings)", "checkOnStart": "Check Once on Start", "tryInferAppIdFromCode": "Try inferring App ID from source code", + "removeOnExternalUninstall": "Automatically remove externally uninstalled Apps", "removeAppQuestion": { "one": "Supprimer l'application ?", "other": "Supprimer les applications ?" diff --git a/assets/translations/hu.json b/assets/translations/hu.json index b0b553c..c6ebc55 100644 --- a/assets/translations/hu.json +++ b/assets/translations/hu.json @@ -233,6 +233,7 @@ "requiresCredentialsInSettings": "Ehhez további hitelesítő adatokra van szükség (a Beállításokban)", "checkOnStart": "Egyszer az indításkor", "tryInferAppIdFromCode": "Próbálja kikövetkeztetni az app azonosítót a forráskódból", + "removeOnExternalUninstall": "Automatically remove externally uninstalled Apps", "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 4d4d925..c06180b 100644 --- a/assets/translations/it.json +++ b/assets/translations/it.json @@ -234,6 +234,7 @@ "requiresCredentialsInSettings": "Servono credenziali aggiuntive (in Impostazioni)", "checkOnStart": "Controlla una volta all'avvio", "tryInferAppIdFromCode": "Prova a dedurre l'ID dell'app dal codice sorgente", + "removeOnExternalUninstall": "Automatically remove externally uninstalled Apps", "removeAppQuestion": { "one": "Rimuovere l'app?", "other": "Rimuovere le app?" diff --git a/assets/translations/ja.json b/assets/translations/ja.json index c0d9c22..270e3a2 100644 --- a/assets/translations/ja.json +++ b/assets/translations/ja.json @@ -234,6 +234,7 @@ "requiresCredentialsInSettings": "これには追加の認証が必要です (設定にて)", "checkOnStart": "Check Once on Start", "tryInferAppIdFromCode": "Try inferring App ID from source code", + "removeOnExternalUninstall": "Automatically remove externally uninstalled Apps", "removeAppQuestion": { "one": "アプリを削除しますか?", "other": "アプリを削除しますか?" diff --git a/assets/translations/pl.json b/assets/translations/pl.json index f1b5274..2837709 100644 --- a/assets/translations/pl.json +++ b/assets/translations/pl.json @@ -238,6 +238,7 @@ "requiresCredentialsInSettings": "Wymaga to dodatkowych poświadczeń (w Ustawieniach)", "checkOnStart": "Sprawdź raz przy starcie", "tryInferAppIdFromCode": "Spróbuj wywnioskować identyfikator aplikacji z kodu źródłowego", + "removeOnExternalUninstall": "Automatically remove externally uninstalled Apps", "removeAppQuestion": { "one": "Usunąć aplikację?", "other": "Usunąć aplikacje?" diff --git a/assets/translations/ru.json b/assets/translations/ru.json index ce91304..d036167 100644 --- a/assets/translations/ru.json +++ b/assets/translations/ru.json @@ -234,6 +234,7 @@ "requiresCredentialsInSettings": "Для этого требуются дополнительные учетные данные (в настройках)", "checkOnStart": "Проверить один раз при запуске", "tryInferAppIdFromCode": "Попытаться определить ID приложения из исходного кода", + "removeOnExternalUninstall": "Automatically remove externally uninstalled Apps", "removeAppQuestion": { "one": "Удалить приложение?", "other": "Удалить приложения?" diff --git a/assets/translations/zh.json b/assets/translations/zh.json index 9e0bbdb..81179e9 100644 --- a/assets/translations/zh.json +++ b/assets/translations/zh.json @@ -234,6 +234,7 @@ "requiresCredentialsInSettings": "此功能需要额外的凭据(在“设置”中添加)", "checkOnStart": "启动时进行一次检查", "tryInferAppIdFromCode": "尝试从源代码推断应用 ID", + "removeOnExternalUninstall": "Automatically remove externally uninstalled Apps", "removeAppQuestion": { "one": "是否删除应用?", "other": "是否删除应用?" diff --git a/lib/main.dart b/lib/main.dart index bbbe37d..dbcf44d 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -226,9 +226,9 @@ class _ObtainiumState extends State { if (!supportedLocales .map((e) => e.key.languageCode) .contains(context.locale.languageCode) || - settingsProvider.forcedLocale == null && + (settingsProvider.forcedLocale == null && context.deviceLocale.languageCode != - context.locale.languageCode) { + context.locale.languageCode)) { settingsProvider.resetLocaleSafe(context); } // Register the background update task according to the user's setting diff --git a/lib/pages/settings.dart b/lib/pages/settings.dart index 7827111..7135a25 100644 --- a/lib/pages/settings.dart +++ b/lib/pages/settings.dart @@ -322,6 +322,22 @@ class _SettingsPageState extends State { ], ), height16, + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Flexible( + child: + Text(tr('removeOnExternalUninstall'))), + Switch( + value: settingsProvider + .removeOnExternalUninstall, + onChanged: (value) { + settingsProvider + .removeOnExternalUninstall = value; + }) + ], + ), + height16, Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ diff --git a/lib/providers/apps_provider.dart b/lib/providers/apps_provider.dart index ff77731..b1da1b2 100644 --- a/lib/providers/apps_provider.dart +++ b/lib/providers/apps_provider.dart @@ -335,19 +335,21 @@ class AppsProvider with ChangeNotifier { } Future unzipFile(String filePath, String destinationPath) async { - await ZipFile.extractToDirectory(zipFile: File(filePath), destinationDir: Directory(destinationPath)); + await ZipFile.extractToDirectory( + zipFile: File(filePath), destinationDir: Directory(destinationPath)); } Future installXApkDir(DownloadedXApkDir dir, {bool silent = false}) async { try { var somethingInstalled = false; - for (var file in dir.extracted.listSync(recursive: true, followLinks: false).whereType()) { + for (var file in dir.extracted + .listSync(recursive: true, followLinks: false) + .whereType()) { if (file.path.toLowerCase().endsWith('.apk')) { somethingInstalled = somethingInstalled || await installApk(DownloadedApk(dir.appId, file), silent: silent); - } - else if (file.path.toLowerCase().endsWith('.obb')) { + } else if (file.path.toLowerCase().endsWith('.obb')) { await moveObbFile(file, dir.appId); } } @@ -389,7 +391,7 @@ class AppsProvider with ChangeNotifier { } Future moveObbFile(File file, String appId) async { - if(!file.path.toLowerCase().endsWith('.obb')) return; + if (!file.path.toLowerCase().endsWith('.obb')) return; // TODO: Does not support Android 11+ if ((await DeviceInfoPlugin().androidInfo).version.sdkInt <= 29) { @@ -754,21 +756,37 @@ class AppsProvider with ChangeNotifier { } loadingApps = false; notifyListeners(); - refreshInstallStatuses(); + + refreshInstallStatuses(useExistingInstalledInfo: true); } - Future refreshInstallStatuses() async { + Future refreshInstallStatuses( + {bool useExistingInstalledInfo = false}) async { if (await doesInstalledAppsPluginWork()) { List modifiedApps = []; for (var app in apps.values) { - var moddedApp = - getCorrectedInstallStatusAppIfPossible(app.app, app.installedInfo); + var moddedApp = getCorrectedInstallStatusAppIfPossible( + app.app, + useExistingInstalledInfo + ? app.installedInfo + : await getInstalledInfo(app.app.id)); if (moddedApp != null) { modifiedApps.add(moddedApp); } } if (modifiedApps.isNotEmpty) { await saveApps(modifiedApps, attemptToCorrectInstallStatus: false); + var removedAppIds = modifiedApps + .where((a) => a.installedVersion == null) + .map((e) => e.id) + .toList(); + if (removedAppIds.isNotEmpty) { + var settingsProvider = SettingsProvider(); + await settingsProvider.initializeSettings(); + if (settingsProvider.removeOnExternalUninstall) { + await removeApps(removedAppIds); + } + } } } } diff --git a/lib/providers/settings_provider.dart b/lib/providers/settings_provider.dart index 8ddfdf2..2319a6d 100644 --- a/lib/providers/settings_provider.dart +++ b/lib/providers/settings_provider.dart @@ -273,4 +273,13 @@ class SettingsProvider with ChangeNotifier { context.deleteSaveLocale(); } } + + bool get removeOnExternalUninstall { + return prefs?.getBool('removeOnExternalUninstall') ?? false; + } + + set removeOnExternalUninstall(bool show) { + prefs?.setBool('removeOnExternalUninstall', show); + notifyListeners(); + } }