From c72ea1e1ac50e3d7a0b72c11806fefa3ffec70e1 Mon Sep 17 00:00:00 2001 From: Cuong-Tran Date: Sat, 28 Dec 2024 17:56:37 +0700 Subject: [PATCH] Allow disable app auto-update --- .../more/settings/screen/SettingsAdvancedScreen.kt | 1 + .../tachiyomi/data/updater/AppUpdateChecker.kt | 12 ++++++++++-- .../domain/release/service/AppUpdatePolicy.kt | 1 + .../src/commonMain/moko-resources/base/strings.xml | 1 + 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsAdvancedScreen.kt b/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsAdvancedScreen.kt index 0326f29544..cc20d6d8d5 100644 --- a/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsAdvancedScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsAdvancedScreen.kt @@ -167,6 +167,7 @@ object SettingsAdvancedScreen : SearchableSettings { AppUpdatePolicy.DEVICE_ONLY_ON_WIFI to stringResource(MR.strings.connected_to_wifi), AppUpdatePolicy.DEVICE_NETWORK_NOT_METERED to stringResource(MR.strings.network_not_metered), AppUpdatePolicy.DEVICE_CHARGING to stringResource(MR.strings.charging), + AppUpdatePolicy.DISABLE_AUTO_DOWNLOAD to stringResource(KMR.strings.auto_update_app_disable_auto_download), ), onValueChanged = { // Post to event looper to allow the preference to be updated. diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/updater/AppUpdateChecker.kt b/app/src/main/java/eu/kanade/tachiyomi/data/updater/AppUpdateChecker.kt index 9df00a8280..43615651ff 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/updater/AppUpdateChecker.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/updater/AppUpdateChecker.kt @@ -5,7 +5,11 @@ import android.os.Build import eu.kanade.tachiyomi.BuildConfig import eu.kanade.tachiyomi.util.system.isInstalledFromFDroid import tachiyomi.core.common.util.lang.withIOContext +import tachiyomi.domain.UnsortedPreferences import tachiyomi.domain.release.interactor.GetApplicationRelease +import tachiyomi.domain.release.service.AppUpdatePolicy +import uy.kohesive.injekt.Injekt +import uy.kohesive.injekt.api.get import uy.kohesive.injekt.injectLazy class AppUpdateChecker( @@ -16,11 +20,15 @@ class AppUpdateChecker( private val getApplicationRelease: GetApplicationRelease by injectLazy() + // KMK --> + private val preferences by lazy { Injekt.get() } + // KMK <-- + suspend fun checkForUpdate( context: Context, forceCheck: Boolean = false, // KMK --> - pendingAutoUpdate: Boolean = true, + autoUpdate: Boolean = AppUpdatePolicy.DISABLE_AUTO_DOWNLOAD !in preferences.appShouldAutoUpdate().get(), // KMK <-- ): GetApplicationRelease.Result { return withIOContext { @@ -54,7 +62,7 @@ class AppUpdateChecker( } // KMK --> - if (pendingAutoUpdate && result is GetApplicationRelease.Result.NewUpdate) { + if (autoUpdate && result is GetApplicationRelease.Result.NewUpdate) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { AppUpdateDownloadJob.start( context = context, diff --git a/domain/src/main/java/tachiyomi/domain/release/service/AppUpdatePolicy.kt b/domain/src/main/java/tachiyomi/domain/release/service/AppUpdatePolicy.kt index b422cfdee4..08c0143501 100644 --- a/domain/src/main/java/tachiyomi/domain/release/service/AppUpdatePolicy.kt +++ b/domain/src/main/java/tachiyomi/domain/release/service/AppUpdatePolicy.kt @@ -5,5 +5,6 @@ class AppUpdatePolicy { const val DEVICE_ONLY_ON_WIFI = "wifi" const val DEVICE_NETWORK_NOT_METERED = "network_not_metered" const val DEVICE_CHARGING = "ac" + const val DISABLE_AUTO_DOWNLOAD = "disable" } } diff --git a/i18n-kmk/src/commonMain/moko-resources/base/strings.xml b/i18n-kmk/src/commonMain/moko-resources/base/strings.xml index e438d4c722..f05ba44952 100644 --- a/i18n-kmk/src/commonMain/moko-resources/base/strings.xml +++ b/i18n-kmk/src/commonMain/moko-resources/base/strings.xml @@ -109,6 +109,7 @@ Saved Searches & Feeds Preload library's cover color Auto-update app + Don't auto download update Access media files permission