Rename app updating classes
So I stop confusing it for updaters of other things.
This commit is contained in:
parent
2a1bb3dc27
commit
21e647017b
@ -178,7 +178,7 @@
|
||||
android:exported="false" />
|
||||
|
||||
<service
|
||||
android:name=".data.updater.UpdaterService"
|
||||
android:name=".data.updater.AppUpdateService"
|
||||
android:exported="false" />
|
||||
|
||||
<service
|
||||
|
@ -9,7 +9,7 @@ import eu.kanade.tachiyomi.data.preference.PreferenceKeys
|
||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||
import eu.kanade.tachiyomi.data.preference.plusAssign
|
||||
import eu.kanade.tachiyomi.data.track.TrackManager
|
||||
import eu.kanade.tachiyomi.data.updater.UpdaterJob
|
||||
import eu.kanade.tachiyomi.data.updater.AppUpdateJob
|
||||
import eu.kanade.tachiyomi.extension.ExtensionUpdateJob
|
||||
import eu.kanade.tachiyomi.network.PREF_DOH_CLOUDFLARE
|
||||
import eu.kanade.tachiyomi.ui.library.LibrarySort
|
||||
@ -39,7 +39,7 @@ object Migrations {
|
||||
|
||||
// Always set up background tasks to ensure they're running
|
||||
if (BuildConfig.INCLUDE_UPDATER) {
|
||||
UpdaterJob.setupTask(context)
|
||||
AppUpdateJob.setupTask(context)
|
||||
}
|
||||
ExtensionUpdateJob.setupTask(context)
|
||||
LibraryUpdateJob.setupTask(context)
|
||||
@ -53,7 +53,7 @@ object Migrations {
|
||||
if (oldVersion < 14) {
|
||||
// Restore jobs after upgrading to Evernote's job scheduler.
|
||||
if (BuildConfig.INCLUDE_UPDATER) {
|
||||
UpdaterJob.setupTask(context)
|
||||
AppUpdateJob.setupTask(context)
|
||||
}
|
||||
LibraryUpdateJob.setupTask(context)
|
||||
}
|
||||
@ -86,7 +86,7 @@ object Migrations {
|
||||
if (oldVersion < 43) {
|
||||
// Restore jobs after migrating from Evernote's job scheduler to WorkManager.
|
||||
if (BuildConfig.INCLUDE_UPDATER) {
|
||||
UpdaterJob.setupTask(context)
|
||||
AppUpdateJob.setupTask(context)
|
||||
}
|
||||
LibraryUpdateJob.setupTask(context)
|
||||
BackupCreatorJob.setupTask(context)
|
||||
@ -158,13 +158,13 @@ object Migrations {
|
||||
|
||||
// Disable update check for Android 5.x users
|
||||
if (BuildConfig.INCLUDE_UPDATER && Build.VERSION.SDK_INT <= Build.VERSION_CODES.M) {
|
||||
UpdaterJob.cancelTask(context)
|
||||
AppUpdateJob.cancelTask(context)
|
||||
}
|
||||
}
|
||||
if (oldVersion < 60) {
|
||||
// Re-enable update check that was prevously accidentally disabled for M
|
||||
if (BuildConfig.INCLUDE_UPDATER && Build.VERSION.SDK_INT == Build.VERSION_CODES.M) {
|
||||
UpdaterJob.setupTask(context)
|
||||
AppUpdateJob.setupTask(context)
|
||||
}
|
||||
|
||||
// Migrate Rotation and Viewer values to default values for viewer_flags
|
||||
|
@ -2,25 +2,24 @@ package eu.kanade.tachiyomi.data.updater
|
||||
|
||||
import android.content.Context
|
||||
import androidx.work.Constraints
|
||||
import androidx.work.CoroutineWorker
|
||||
import androidx.work.ExistingPeriodicWorkPolicy
|
||||
import androidx.work.NetworkType
|
||||
import androidx.work.PeriodicWorkRequestBuilder
|
||||
import androidx.work.WorkManager
|
||||
import androidx.work.Worker
|
||||
import androidx.work.WorkerParameters
|
||||
import eu.kanade.tachiyomi.BuildConfig
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import kotlinx.coroutines.coroutineScope
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
class UpdaterJob(private val context: Context, workerParams: WorkerParameters) :
|
||||
Worker(context, workerParams) {
|
||||
class AppUpdateJob(private val context: Context, workerParams: WorkerParameters) :
|
||||
CoroutineWorker(context, workerParams) {
|
||||
|
||||
override fun doWork() = runBlocking {
|
||||
override suspend fun doWork() = coroutineScope {
|
||||
try {
|
||||
val result = AppUpdateChecker().checkForUpdate()
|
||||
|
||||
if (result is AppUpdateResult.NewUpdate) {
|
||||
UpdaterNotifier(context).promptUpdate(result.release.getDownloadLink())
|
||||
AppUpdateNotifier(context).promptUpdate(result.release.getDownloadLink())
|
||||
}
|
||||
Result.success()
|
||||
} catch (e: Exception) {
|
||||
@ -32,8 +31,8 @@ class UpdaterJob(private val context: Context, workerParams: WorkerParameters) :
|
||||
private const val TAG = "UpdateChecker"
|
||||
|
||||
fun setupTask(context: Context) {
|
||||
// Never check for updates in debug builds that don't include the updater
|
||||
if (BuildConfig.DEBUG && !BuildConfig.INCLUDE_UPDATER) {
|
||||
// Never check for updates in builds that don't include the updater
|
||||
if (!BuildConfig.INCLUDE_UPDATER) {
|
||||
cancelTask(context)
|
||||
return
|
||||
}
|
||||
@ -42,7 +41,7 @@ class UpdaterJob(private val context: Context, workerParams: WorkerParameters) :
|
||||
.setRequiredNetworkType(NetworkType.CONNECTED)
|
||||
.build()
|
||||
|
||||
val request = PeriodicWorkRequestBuilder<UpdaterJob>(
|
||||
val request = PeriodicWorkRequestBuilder<AppUpdateJob>(
|
||||
7,
|
||||
TimeUnit.DAYS,
|
||||
3,
|
@ -12,12 +12,7 @@ import eu.kanade.tachiyomi.data.notification.Notifications
|
||||
import eu.kanade.tachiyomi.util.system.notificationBuilder
|
||||
import eu.kanade.tachiyomi.util.system.notificationManager
|
||||
|
||||
/**
|
||||
* DownloadNotifier is used to show notifications when downloading and update.
|
||||
*
|
||||
* @param context context of application.
|
||||
*/
|
||||
internal class UpdaterNotifier(private val context: Context) {
|
||||
internal class AppUpdateNotifier(private val context: Context) {
|
||||
|
||||
private val notificationBuilder = context.notificationBuilder(Notifications.CHANNEL_COMMON)
|
||||
|
||||
@ -31,8 +26,8 @@ internal class UpdaterNotifier(private val context: Context) {
|
||||
}
|
||||
|
||||
fun promptUpdate(url: String) {
|
||||
val intent = Intent(context, UpdaterService::class.java).apply {
|
||||
putExtra(UpdaterService.EXTRA_DOWNLOAD_URL, url)
|
||||
val intent = Intent(context, AppUpdateService::class.java).apply {
|
||||
putExtra(AppUpdateService.EXTRA_DOWNLOAD_URL, url)
|
||||
}
|
||||
val pendingIntent = PendingIntent.getService(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT)
|
||||
with(notificationBuilder) {
|
||||
@ -125,7 +120,7 @@ internal class UpdaterNotifier(private val context: Context) {
|
||||
addAction(
|
||||
R.drawable.ic_refresh_24dp,
|
||||
context.getString(R.string.action_retry),
|
||||
UpdaterService.downloadApkPendingService(context, url)
|
||||
AppUpdateService.downloadApkPendingService(context, url)
|
||||
)
|
||||
addAction(
|
||||
R.drawable.ic_close_24dp,
|
@ -25,7 +25,7 @@ import logcat.LogPriority
|
||||
import uy.kohesive.injekt.injectLazy
|
||||
import java.io.File
|
||||
|
||||
class UpdaterService : Service() {
|
||||
class AppUpdateService : Service() {
|
||||
|
||||
private val network: NetworkHelper by injectLazy()
|
||||
|
||||
@ -34,12 +34,12 @@ class UpdaterService : Service() {
|
||||
*/
|
||||
private lateinit var wakeLock: PowerManager.WakeLock
|
||||
|
||||
private lateinit var notifier: UpdaterNotifier
|
||||
private lateinit var notifier: AppUpdateNotifier
|
||||
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
|
||||
notifier = UpdaterNotifier(this)
|
||||
notifier = AppUpdateNotifier(this)
|
||||
wakeLock = acquireWakeLock(javaClass.name)
|
||||
|
||||
startForeground(Notifications.ID_UPDATER, notifier.onDownloadStarted().build())
|
||||
@ -139,7 +139,7 @@ class UpdaterService : Service() {
|
||||
* @return true if the service is running, false otherwise.
|
||||
*/
|
||||
private fun isRunning(context: Context): Boolean =
|
||||
context.isServiceRunning(UpdaterService::class.java)
|
||||
context.isServiceRunning(AppUpdateService::class.java)
|
||||
|
||||
/**
|
||||
* Downloads a new update and let the user install the new version from a notification.
|
||||
@ -149,7 +149,7 @@ class UpdaterService : Service() {
|
||||
*/
|
||||
fun start(context: Context, url: String, title: String = context.getString(R.string.app_name)) {
|
||||
if (!isRunning(context)) {
|
||||
val intent = Intent(context, UpdaterService::class.java).apply {
|
||||
val intent = Intent(context, AppUpdateService::class.java).apply {
|
||||
putExtra(EXTRA_DOWNLOAD_TITLE, title)
|
||||
putExtra(EXTRA_DOWNLOAD_URL, url)
|
||||
}
|
||||
@ -164,7 +164,7 @@ class UpdaterService : Service() {
|
||||
* @return [PendingIntent]
|
||||
*/
|
||||
internal fun downloadApkPendingService(context: Context, url: String): PendingIntent {
|
||||
val intent = Intent(context, UpdaterService::class.java).apply {
|
||||
val intent = Intent(context, AppUpdateService::class.java).apply {
|
||||
putExtra(EXTRA_DOWNLOAD_URL, url)
|
||||
}
|
||||
return PendingIntent.getService(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT)
|
@ -13,7 +13,7 @@ import kotlinx.serialization.Serializable
|
||||
* @param assets assets of latest release.
|
||||
*/
|
||||
@Serializable
|
||||
class GithubRelease(
|
||||
data class GithubRelease(
|
||||
@SerialName("tag_name") val version: String,
|
||||
@SerialName("body") val info: String,
|
||||
@SerialName("assets") private val assets: List<Assets>
|
||||
@ -40,5 +40,5 @@ class GithubRelease(
|
||||
* @param downloadLink download url.
|
||||
*/
|
||||
@Serializable
|
||||
class Assets(@SerialName("browser_download_url") val downloadLink: String)
|
||||
data class Assets(@SerialName("browser_download_url") val downloadLink: String)
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ import androidx.core.os.bundleOf
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.data.updater.AppUpdateResult
|
||||
import eu.kanade.tachiyomi.data.updater.UpdaterService
|
||||
import eu.kanade.tachiyomi.data.updater.AppUpdateService
|
||||
import eu.kanade.tachiyomi.ui.base.controller.DialogController
|
||||
|
||||
class NewUpdateDialogController(bundle: Bundle? = null) : DialogController(bundle) {
|
||||
@ -24,7 +24,7 @@ class NewUpdateDialogController(bundle: Bundle? = null) : DialogController(bundl
|
||||
if (appContext != null) {
|
||||
// Start download
|
||||
val url = args.getString(URL_KEY) ?: ""
|
||||
UpdaterService.start(appContext, url)
|
||||
AppUpdateService.start(appContext, url)
|
||||
}
|
||||
}
|
||||
.setNegativeButton(R.string.update_check_ignore, null)
|
||||
|
Loading…
Reference in New Issue
Block a user