Add auto-remove option (#656) + on-foreground bugfix

This commit is contained in:
Imran Remtulla
2023-07-14 21:09:20 -04:00
parent 3f4c6a1b76
commit 3ec33a1c77
15 changed files with 65 additions and 11 deletions

View File

@@ -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?"

View File

@@ -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?"

View File

@@ -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?"

View File

@@ -234,6 +234,7 @@
"requiresCredentialsInSettings": "این به اعتبارنامه های اضافی نیاز دارد (در تنظیمات)",
"checkOnStart": "بررسی در شروع",
"tryInferAppIdFromCode": "شناسه برنامه را از کد منبع استنباط کنید",
"removeOnExternalUninstall": "Automatically remove externally uninstalled Apps",
"removeAppQuestion": {
"one": "برنامه حذف شود؟",
"other": "برنامه ها حذف شوند؟"

View File

@@ -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 ?"

View File

@@ -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?"

View File

@@ -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?"

View File

@@ -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": "アプリを削除しますか?"

View File

@@ -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?"

View File

@@ -234,6 +234,7 @@
"requiresCredentialsInSettings": "Для этого требуются дополнительные учетные данные (в настройках)",
"checkOnStart": "Проверить один раз при запуске",
"tryInferAppIdFromCode": "Попытаться определить ID приложения из исходного кода",
"removeOnExternalUninstall": "Automatically remove externally uninstalled Apps",
"removeAppQuestion": {
"one": "Удалить приложение?",
"other": "Удалить приложения?"

View File

@@ -234,6 +234,7 @@
"requiresCredentialsInSettings": "此功能需要额外的凭据(在“设置”中添加)",
"checkOnStart": "启动时进行一次检查",
"tryInferAppIdFromCode": "尝试从源代码推断应用 ID",
"removeOnExternalUninstall": "Automatically remove externally uninstalled Apps",
"removeAppQuestion": {
"one": "是否删除应用?",
"other": "是否删除应用?"

View File

@@ -226,9 +226,9 @@ class _ObtainiumState extends State<Obtainium> {
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

View File

@@ -322,6 +322,22 @@ class _SettingsPageState extends State<SettingsPage> {
],
),
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: [

View File

@@ -335,19 +335,21 @@ class AppsProvider with ChangeNotifier {
}
Future<void> 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<void> installXApkDir(DownloadedXApkDir dir,
{bool silent = false}) async {
try {
var somethingInstalled = false;
for (var file in dir.extracted.listSync(recursive: true, followLinks: false).whereType<File>()) {
for (var file in dir.extracted
.listSync(recursive: true, followLinks: false)
.whereType<File>()) {
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);
}
}
@@ -754,21 +756,37 @@ class AppsProvider with ChangeNotifier {
}
loadingApps = false;
notifyListeners();
refreshInstallStatuses();
refreshInstallStatuses(useExistingInstalledInfo: true);
}
Future<void> refreshInstallStatuses() async {
Future<void> refreshInstallStatuses(
{bool useExistingInstalledInfo = false}) async {
if (await doesInstalledAppsPluginWork()) {
List<App> 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);
}
}
}
}
}

View File

@@ -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();
}
}