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,18 +195,20 @@ class DownloadWorker @AssistedInject constructor(
return onSuccess() return onSuccess()
} }
private suspend fun onSuccess(): Result = withContext(NonCancellable) { private suspend fun onSuccess(): Result {
return@withContext try { return withContext(NonCancellable) {
appInstaller.getPreferredInstaller().install(download) return@withContext try {
Result.success() appInstaller.getPreferredInstaller().install(download)
} catch (exception: Exception) { Result.success()
Log.e(TAG, "Failed to install ${download.packageName}", exception) } catch (exception: Exception) {
onFailure(exception) Log.e(TAG, "Failed to install ${download.packageName}", 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.