diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadService.kt b/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadService.kt index 42e7f05bd2..3f955a768f 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadService.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadService.kt @@ -11,12 +11,15 @@ import android.os.Build import android.os.IBinder import android.os.PowerManager import androidx.core.app.NotificationCompat +import androidx.work.NetworkType import com.github.pwittchen.reactivenetwork.library.Connectivity import com.github.pwittchen.reactivenetwork.library.ReactiveNetwork import com.jakewharton.rxrelay.BehaviorRelay import eu.kanade.tachiyomi.R +import eu.kanade.tachiyomi.data.library.LibraryUpdateService import eu.kanade.tachiyomi.data.notification.Notifications import eu.kanade.tachiyomi.data.preference.PreferencesHelper +import eu.kanade.tachiyomi.extension.ExtensionUpdateJob import eu.kanade.tachiyomi.util.lang.plusAssign import eu.kanade.tachiyomi.util.system.connectivityManager import eu.kanade.tachiyomi.util.system.isServiceRunning @@ -137,6 +140,10 @@ class DownloadService : Service() { downloadManager.stopDownloads() callListeners(downloadManager.hasQueue()) wakeLock.releaseIfNeeded() + if (LibraryUpdateService.runExtensionUpdatesAfter) { + ExtensionUpdateJob.runJobAgain(this, NetworkType.CONNECTED) + LibraryUpdateService.runExtensionUpdatesAfter = false + } super.onDestroy() } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateService.kt b/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateService.kt index 410ffc12c9..19456898c4 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateService.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateService.kt @@ -6,6 +6,7 @@ import android.content.Intent import android.os.Build import android.os.IBinder import android.os.PowerManager +import androidx.work.NetworkType import coil.Coil import coil.request.CachePolicy import coil.request.ImageRequest @@ -27,6 +28,7 @@ import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.data.preference.getOrDefault import eu.kanade.tachiyomi.data.track.TrackManager import eu.kanade.tachiyomi.data.track.UnattendedTrackService +import eu.kanade.tachiyomi.extension.ExtensionUpdateJob import eu.kanade.tachiyomi.source.SourceManager import eu.kanade.tachiyomi.source.model.SManga import eu.kanade.tachiyomi.source.model.toSChapter @@ -355,6 +357,10 @@ class LibraryUpdateService( mangaShortcutManager.updateShortcuts() failedUpdates.clear() notifier.cancelProgressNotification() + if (runExtensionUpdatesAfter && !DownloadService.isRunning(this)) { + ExtensionUpdateJob.runJobAgain(this, NetworkType.CONNECTED) + runExtensionUpdatesAfter = false + } } private suspend fun updateMangaInSource(source: Long): Boolean { @@ -561,14 +567,14 @@ class LibraryUpdateService( */ const val KEY_MANGAS = "mangas" + var runExtensionUpdatesAfter = false + /** * Returns the status of the service. * * @return true if the service is running, false otherwise. */ - fun isRunning(): Boolean { - return instance != null - } + fun isRunning() = instance != null /** * Starts the service. It will be started only if there isn't another instance already 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 b3c8dff133..03074dfbc3 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/extension/ExtensionInstallService.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/extension/ExtensionInstallService.kt @@ -166,6 +166,13 @@ class ExtensionInstallService( context.stopService(Intent(context, ExtensionUpdateJob::class.java)) } + /** + * Returns the status of the service. + * + * @return true if the service is running, false otherwise. + */ + fun isRunning() = instance != null + /** * Key that defines what should be updated. */ diff --git a/app/src/main/java/eu/kanade/tachiyomi/extension/ExtensionUpdateJob.kt b/app/src/main/java/eu/kanade/tachiyomi/extension/ExtensionUpdateJob.kt index 2e5b3e9861..38da45e0e1 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/extension/ExtensionUpdateJob.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/extension/ExtensionUpdateJob.kt @@ -17,6 +17,7 @@ import androidx.work.PeriodicWorkRequestBuilder import androidx.work.WorkManager import androidx.work.WorkerParameters import eu.kanade.tachiyomi.R +import eu.kanade.tachiyomi.data.library.LibraryUpdateService import eu.kanade.tachiyomi.data.notification.NotificationReceiver import eu.kanade.tachiyomi.data.notification.Notifications import eu.kanade.tachiyomi.data.preference.PreferencesHelper @@ -54,12 +55,16 @@ class ExtensionUpdateJob(private val context: Context, workerParams: WorkerParam preferences.extensionUpdatesCount().set(extensions.size) if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S && inputData.getBoolean(RUN_AUTO, true) && - preferences.autoUpdateExtensions() != AutoUpdaterJob.NEVER + preferences.autoUpdateExtensions() != AutoUpdaterJob.NEVER && + !ExtensionInstallService.isRunning() ) { val cm = context.connectivityManager + val libraryServiceRunning = LibraryUpdateService.isRunning() if ( - preferences.autoUpdateExtensions() == AutoUpdaterJob.ALWAYS || - !cm.isActiveNetworkMetered + ( + preferences.autoUpdateExtensions() == AutoUpdaterJob.ALWAYS || + !cm.isActiveNetworkMetered + ) && !libraryServiceRunning ) { val extensionManager = Injekt.get() val extensionsInstalledByApp = @@ -83,8 +88,10 @@ class ExtensionUpdateJob(private val context: Context, workerParams: WorkerParam extensions.removeAll(extensionsInstalledByApp) } } - } else { + } else if (!libraryServiceRunning) { runJobAgain(context, NetworkType.UNMETERED) + } else { + LibraryUpdateService.runExtensionUpdatesAfter = true } } NotificationManagerCompat.from(context).apply {