From 5da21660a3b3c775b767d709b45153eb2b56c415 Mon Sep 17 00:00:00 2001 From: Jays2Kings Date: Sat, 17 Jul 2021 23:17:13 -0400 Subject: [PATCH] Filter out extensions that have already been updated via other means from update service --- .../extension/ExtensionInstallService.kt | 17 ++++++++++++++++- .../tachiyomi/extension/ExtensionManager.kt | 4 +++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/extension/ExtensionInstallService.kt b/app/src/main/java/eu/kanade/tachiyomi/extension/ExtensionInstallService.kt index 19a967b3c2..26f7ccd80d 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/extension/ExtensionInstallService.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/extension/ExtensionInstallService.kt @@ -5,10 +5,13 @@ import android.content.Context import android.content.Intent import android.os.IBinder import android.os.PowerManager +import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.notification.Notifications +import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.extension.ExtensionManager.ExtensionInfo import eu.kanade.tachiyomi.extension.model.Extension import eu.kanade.tachiyomi.util.system.notificationManager +import eu.kanade.tachiyomi.util.system.toast import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Job @@ -41,6 +44,8 @@ class ExtensionInstallService( private val requestSemaphore = Semaphore(3) + private val preferences: PreferencesHelper = Injekt.get() + /** * This method needs to be implemented, but it's not used/needed. */ @@ -58,10 +63,20 @@ class ExtensionInstallService( */ override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { if (intent == null) return START_NOT_STICKY + if (!preferences.hasPromptedBeforeUpdateAll().get()) { + toast(R.string.some_extensions_may_prompt) + preferences.hasPromptedBeforeUpdateAll().set(true) + } instance = this - val list = intent.getParcelableArrayListExtra(KEY_EXTENSION) + val list = intent.getParcelableArrayListExtra(KEY_EXTENSION)?.filter { + ( + extensionManager.installedExtensions.find { installed -> + installed.pkgName == it.pkgName + }?.versionCode ?: 0 + ) < it.versionCode + } ?: return START_NOT_STICKY var installed = 0 job = serviceScope.launch { diff --git a/app/src/main/java/eu/kanade/tachiyomi/extension/ExtensionManager.kt b/app/src/main/java/eu/kanade/tachiyomi/extension/ExtensionManager.kt index b9d3ff7dc5..828e40c949 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/extension/ExtensionManager.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/extension/ExtensionManager.kt @@ -411,11 +411,13 @@ class ExtensionManager( val apkName: String, val pkgName: String, val name: String, + val versionCode: Int, ) : Parcelable { constructor(extension: Extension.Available) : this( apkName = extension.apkName, pkgName = extension.pkgName, - name = extension.name + name = extension.name, + versionCode = extension.versionCode ) } }