Skip to content

Commit

Permalink
fix: Safely handle installation exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
oSumAtrIX committed Jan 22, 2024
1 parent a928b19 commit 4d4d682
Showing 1 changed file with 3 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import app.revanced.manager.util.PM
import app.revanced.manager.util.simpleMessage
import app.revanced.manager.util.tag
import app.revanced.manager.util.toast
import app.revanced.manager.util.uiSafe
import kotlinx.collections.immutable.ImmutableList
import kotlinx.collections.immutable.toImmutableList
import kotlinx.coroutines.Dispatchers
Expand Down Expand Up @@ -214,15 +215,12 @@ class InstallerViewModel(
}

is SelectedApp.Installed -> {
try {
uiSafe(app, R.string.failed_to_mount, "Failed to mount") {
installedApp?.let {
if (it.installType == InstallType.ROOT) {
rootInstaller.mount(packageName)
}
}
} catch (e: Exception) {
Log.e(tag, "Failed to mount", e)
app.toast(app.getString(R.string.failed_to_mount, e.simpleMessage()))
}
}

Expand All @@ -243,16 +241,12 @@ class InstallerViewModel(
}

fun reinstall() = viewModelScope.launch {
try {
uiSafe(app, R.string.reinstall_app_fail, "Failed to reinstall") {
pm.getPackageInfo(outputFile)?.packageName?.let { pm.uninstallPackage(it) }
?: throw Exception("Failed to load application info")

pm.installApp(listOf(outputFile))
} catch (e: Exception) {
Log.e(tag, "Failed to reinstall", e)
app.toast(app.getString(R.string.reinstall_app_fail, e.simpleMessage()))
}

}

fun install(installType: InstallType) = viewModelScope.launch {
Expand Down

0 comments on commit 4d4d682

Please sign in to comment.