DownloadWorker: Match function returns

Signed-off-by: Aayush Gupta <aayushgupta219@gmail.com>
This commit is contained in:
Aayush Gupta
2025-04-13 18:42:15 +08:00
parent 5003f66fff
commit 2342ea9a78

View File

@@ -195,7 +195,8 @@ class DownloadWorker @AssistedInject constructor(
return onSuccess() return onSuccess()
} }
private suspend fun onSuccess(): Result = withContext(NonCancellable) { private suspend fun onSuccess(): Result {
return withContext(NonCancellable) {
return@withContext try { return@withContext try {
appInstaller.getPreferredInstaller().install(download) appInstaller.getPreferredInstaller().install(download)
Result.success() Result.success()
@@ -204,9 +205,10 @@ class DownloadWorker @AssistedInject constructor(
onFailure(exception) onFailure(exception)
} }
} }
}
private suspend fun onFailure(exception: Exception): Result = private suspend fun onFailure(exception: Exception): Result {
withContext(NonCancellable) { return withContext(NonCancellable) {
Log.i(TAG, "Job failed: ${download.packageName}", exception) Log.i(TAG, "Job failed: ${download.packageName}", exception)
val cancelReasons = listOf(STOP_REASON_USER, STOP_REASON_CANCELLED_BY_APP) val cancelReasons = listOf(STOP_REASON_USER, STOP_REASON_CANCELLED_BY_APP)
@@ -234,6 +236,7 @@ class DownloadWorker @AssistedInject constructor(
return@withContext Result.failure() return@withContext Result.failure()
} }
}
/** /**
* Purchases the app to get the download URL of the required files * Purchases the app to get the download URL of the required files
@@ -267,8 +270,8 @@ class DownloadWorker @AssistedInject constructor(
* @param gFile A [GPlayFile] to download * @param gFile A [GPlayFile] to download
* @return A [Boolean] indicating whether the file was downloaded or not. * @return A [Boolean] indicating whether the file was downloaded or not.
*/ */
private suspend fun downloadFile(packageName: String, gFile: GPlayFile): Boolean = private suspend fun downloadFile(packageName: String, gFile: GPlayFile): Boolean {
withContext(Dispatchers.IO) { return withContext(Dispatchers.IO) {
Log.i(TAG, "Downloading $packageName @ ${gFile.name}") Log.i(TAG, "Downloading $packageName @ ${gFile.name}")
val file = PathUtil.getLocalFile(context, gFile, download) val file = PathUtil.getLocalFile(context, gFile, download)
@@ -322,6 +325,7 @@ class DownloadWorker @AssistedInject constructor(
} }
} }
} }
}
/** /**
* Updates the progress data of the download in the local database and notifies user. * Updates the progress data of the download in the local database and notifies user.