mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-11-19 23:49:16 +01:00
Run extension auto updater only when library service isnt running
Will wait for library service to finish, or downloads to finish before running
This commit is contained in:
parent
1b08e07037
commit
9eef1b48a8
@ -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()
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
@ -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.
|
||||
*/
|
||||
|
@ -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
|
||||
) && !libraryServiceRunning
|
||||
) {
|
||||
val extensionManager = Injekt.get<ExtensionManager>()
|
||||
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 {
|
||||
|
Loading…
Reference in New Issue
Block a user