Rename app updating classes

So I stop confusing it for updaters of other things.
This commit is contained in:
arkon 2021-10-16 10:21:15 -04:00
parent 2a1bb3dc27
commit 21e647017b
7 changed files with 30 additions and 36 deletions

View File

@ -178,7 +178,7 @@
android:exported="false" /> android:exported="false" />
<service <service
android:name=".data.updater.UpdaterService" android:name=".data.updater.AppUpdateService"
android:exported="false" /> android:exported="false" />
<service <service

View File

@ -9,7 +9,7 @@ import eu.kanade.tachiyomi.data.preference.PreferenceKeys
import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import eu.kanade.tachiyomi.data.preference.plusAssign import eu.kanade.tachiyomi.data.preference.plusAssign
import eu.kanade.tachiyomi.data.track.TrackManager 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.extension.ExtensionUpdateJob
import eu.kanade.tachiyomi.network.PREF_DOH_CLOUDFLARE import eu.kanade.tachiyomi.network.PREF_DOH_CLOUDFLARE
import eu.kanade.tachiyomi.ui.library.LibrarySort import eu.kanade.tachiyomi.ui.library.LibrarySort
@ -39,7 +39,7 @@ object Migrations {
// Always set up background tasks to ensure they're running // Always set up background tasks to ensure they're running
if (BuildConfig.INCLUDE_UPDATER) { if (BuildConfig.INCLUDE_UPDATER) {
UpdaterJob.setupTask(context) AppUpdateJob.setupTask(context)
} }
ExtensionUpdateJob.setupTask(context) ExtensionUpdateJob.setupTask(context)
LibraryUpdateJob.setupTask(context) LibraryUpdateJob.setupTask(context)
@ -53,7 +53,7 @@ object Migrations {
if (oldVersion < 14) { if (oldVersion < 14) {
// Restore jobs after upgrading to Evernote's job scheduler. // Restore jobs after upgrading to Evernote's job scheduler.
if (BuildConfig.INCLUDE_UPDATER) { if (BuildConfig.INCLUDE_UPDATER) {
UpdaterJob.setupTask(context) AppUpdateJob.setupTask(context)
} }
LibraryUpdateJob.setupTask(context) LibraryUpdateJob.setupTask(context)
} }
@ -86,7 +86,7 @@ object Migrations {
if (oldVersion < 43) { if (oldVersion < 43) {
// Restore jobs after migrating from Evernote's job scheduler to WorkManager. // Restore jobs after migrating from Evernote's job scheduler to WorkManager.
if (BuildConfig.INCLUDE_UPDATER) { if (BuildConfig.INCLUDE_UPDATER) {
UpdaterJob.setupTask(context) AppUpdateJob.setupTask(context)
} }
LibraryUpdateJob.setupTask(context) LibraryUpdateJob.setupTask(context)
BackupCreatorJob.setupTask(context) BackupCreatorJob.setupTask(context)
@ -158,13 +158,13 @@ object Migrations {
// Disable update check for Android 5.x users // Disable update check for Android 5.x users
if (BuildConfig.INCLUDE_UPDATER && Build.VERSION.SDK_INT <= Build.VERSION_CODES.M) { if (BuildConfig.INCLUDE_UPDATER && Build.VERSION.SDK_INT <= Build.VERSION_CODES.M) {
UpdaterJob.cancelTask(context) AppUpdateJob.cancelTask(context)
} }
} }
if (oldVersion < 60) { if (oldVersion < 60) {
// Re-enable update check that was prevously accidentally disabled for M // Re-enable update check that was prevously accidentally disabled for M
if (BuildConfig.INCLUDE_UPDATER && Build.VERSION.SDK_INT == Build.VERSION_CODES.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 // Migrate Rotation and Viewer values to default values for viewer_flags

View File

@ -2,25 +2,24 @@ package eu.kanade.tachiyomi.data.updater
import android.content.Context import android.content.Context
import androidx.work.Constraints import androidx.work.Constraints
import androidx.work.CoroutineWorker
import androidx.work.ExistingPeriodicWorkPolicy import androidx.work.ExistingPeriodicWorkPolicy
import androidx.work.NetworkType import androidx.work.NetworkType
import androidx.work.PeriodicWorkRequestBuilder import androidx.work.PeriodicWorkRequestBuilder
import androidx.work.WorkManager import androidx.work.WorkManager
import androidx.work.Worker
import androidx.work.WorkerParameters import androidx.work.WorkerParameters
import eu.kanade.tachiyomi.BuildConfig import eu.kanade.tachiyomi.BuildConfig
import kotlinx.coroutines.runBlocking import kotlinx.coroutines.coroutineScope
import java.util.concurrent.TimeUnit import java.util.concurrent.TimeUnit
class UpdaterJob(private val context: Context, workerParams: WorkerParameters) : class AppUpdateJob(private val context: Context, workerParams: WorkerParameters) :
Worker(context, workerParams) { CoroutineWorker(context, workerParams) {
override fun doWork() = runBlocking { override suspend fun doWork() = coroutineScope {
try { try {
val result = AppUpdateChecker().checkForUpdate() val result = AppUpdateChecker().checkForUpdate()
if (result is AppUpdateResult.NewUpdate) { if (result is AppUpdateResult.NewUpdate) {
UpdaterNotifier(context).promptUpdate(result.release.getDownloadLink()) AppUpdateNotifier(context).promptUpdate(result.release.getDownloadLink())
} }
Result.success() Result.success()
} catch (e: Exception) { } catch (e: Exception) {
@ -32,8 +31,8 @@ class UpdaterJob(private val context: Context, workerParams: WorkerParameters) :
private const val TAG = "UpdateChecker" private const val TAG = "UpdateChecker"
fun setupTask(context: Context) { fun setupTask(context: Context) {
// Never check for updates in debug builds that don't include the updater // Never check for updates in builds that don't include the updater
if (BuildConfig.DEBUG && !BuildConfig.INCLUDE_UPDATER) { if (!BuildConfig.INCLUDE_UPDATER) {
cancelTask(context) cancelTask(context)
return return
} }
@ -42,7 +41,7 @@ class UpdaterJob(private val context: Context, workerParams: WorkerParameters) :
.setRequiredNetworkType(NetworkType.CONNECTED) .setRequiredNetworkType(NetworkType.CONNECTED)
.build() .build()
val request = PeriodicWorkRequestBuilder<UpdaterJob>( val request = PeriodicWorkRequestBuilder<AppUpdateJob>(
7, 7,
TimeUnit.DAYS, TimeUnit.DAYS,
3, 3,

View File

@ -12,12 +12,7 @@ import eu.kanade.tachiyomi.data.notification.Notifications
import eu.kanade.tachiyomi.util.system.notificationBuilder import eu.kanade.tachiyomi.util.system.notificationBuilder
import eu.kanade.tachiyomi.util.system.notificationManager import eu.kanade.tachiyomi.util.system.notificationManager
/** internal class AppUpdateNotifier(private val context: Context) {
* DownloadNotifier is used to show notifications when downloading and update.
*
* @param context context of application.
*/
internal class UpdaterNotifier(private val context: Context) {
private val notificationBuilder = context.notificationBuilder(Notifications.CHANNEL_COMMON) private val notificationBuilder = context.notificationBuilder(Notifications.CHANNEL_COMMON)
@ -31,8 +26,8 @@ internal class UpdaterNotifier(private val context: Context) {
} }
fun promptUpdate(url: String) { fun promptUpdate(url: String) {
val intent = Intent(context, UpdaterService::class.java).apply { val intent = Intent(context, AppUpdateService::class.java).apply {
putExtra(UpdaterService.EXTRA_DOWNLOAD_URL, url) putExtra(AppUpdateService.EXTRA_DOWNLOAD_URL, url)
} }
val pendingIntent = PendingIntent.getService(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT) val pendingIntent = PendingIntent.getService(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT)
with(notificationBuilder) { with(notificationBuilder) {
@ -125,7 +120,7 @@ internal class UpdaterNotifier(private val context: Context) {
addAction( addAction(
R.drawable.ic_refresh_24dp, R.drawable.ic_refresh_24dp,
context.getString(R.string.action_retry), context.getString(R.string.action_retry),
UpdaterService.downloadApkPendingService(context, url) AppUpdateService.downloadApkPendingService(context, url)
) )
addAction( addAction(
R.drawable.ic_close_24dp, R.drawable.ic_close_24dp,

View File

@ -25,7 +25,7 @@ import logcat.LogPriority
import uy.kohesive.injekt.injectLazy import uy.kohesive.injekt.injectLazy
import java.io.File import java.io.File
class UpdaterService : Service() { class AppUpdateService : Service() {
private val network: NetworkHelper by injectLazy() private val network: NetworkHelper by injectLazy()
@ -34,12 +34,12 @@ class UpdaterService : Service() {
*/ */
private lateinit var wakeLock: PowerManager.WakeLock private lateinit var wakeLock: PowerManager.WakeLock
private lateinit var notifier: UpdaterNotifier private lateinit var notifier: AppUpdateNotifier
override fun onCreate() { override fun onCreate() {
super.onCreate() super.onCreate()
notifier = UpdaterNotifier(this) notifier = AppUpdateNotifier(this)
wakeLock = acquireWakeLock(javaClass.name) wakeLock = acquireWakeLock(javaClass.name)
startForeground(Notifications.ID_UPDATER, notifier.onDownloadStarted().build()) startForeground(Notifications.ID_UPDATER, notifier.onDownloadStarted().build())
@ -139,7 +139,7 @@ class UpdaterService : Service() {
* @return true if the service is running, false otherwise. * @return true if the service is running, false otherwise.
*/ */
private fun isRunning(context: Context): Boolean = 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. * 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)) { fun start(context: Context, url: String, title: String = context.getString(R.string.app_name)) {
if (!isRunning(context)) { 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_TITLE, title)
putExtra(EXTRA_DOWNLOAD_URL, url) putExtra(EXTRA_DOWNLOAD_URL, url)
} }
@ -164,7 +164,7 @@ class UpdaterService : Service() {
* @return [PendingIntent] * @return [PendingIntent]
*/ */
internal fun downloadApkPendingService(context: Context, url: String): 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) putExtra(EXTRA_DOWNLOAD_URL, url)
} }
return PendingIntent.getService(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT) return PendingIntent.getService(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT)

View File

@ -13,7 +13,7 @@ import kotlinx.serialization.Serializable
* @param assets assets of latest release. * @param assets assets of latest release.
*/ */
@Serializable @Serializable
class GithubRelease( data class GithubRelease(
@SerialName("tag_name") val version: String, @SerialName("tag_name") val version: String,
@SerialName("body") val info: String, @SerialName("body") val info: String,
@SerialName("assets") private val assets: List<Assets> @SerialName("assets") private val assets: List<Assets>
@ -40,5 +40,5 @@ class GithubRelease(
* @param downloadLink download url. * @param downloadLink download url.
*/ */
@Serializable @Serializable
class Assets(@SerialName("browser_download_url") val downloadLink: String) data class Assets(@SerialName("browser_download_url") val downloadLink: String)
} }

View File

@ -6,7 +6,7 @@ import androidx.core.os.bundleOf
import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.google.android.material.dialog.MaterialAlertDialogBuilder
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.updater.AppUpdateResult 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 import eu.kanade.tachiyomi.ui.base.controller.DialogController
class NewUpdateDialogController(bundle: Bundle? = null) : DialogController(bundle) { class NewUpdateDialogController(bundle: Bundle? = null) : DialogController(bundle) {
@ -24,7 +24,7 @@ class NewUpdateDialogController(bundle: Bundle? = null) : DialogController(bundl
if (appContext != null) { if (appContext != null) {
// Start download // Start download
val url = args.getString(URL_KEY) ?: "" val url = args.getString(URL_KEY) ?: ""
UpdaterService.start(appContext, url) AppUpdateService.start(appContext, url)
} }
} }
.setNegativeButton(R.string.update_check_ignore, null) .setNegativeButton(R.string.update_check_ignore, null)