fix: improve keystore import error handling and show toast

This commit is contained in:
Robert 2025-01-29 19:58:38 +01:00
parent cd06d36f68
commit 3d234820a3
No known key found for this signature in database
GPG Key ID: 887C470FCF872DC6
3 changed files with 24 additions and 18 deletions

View File

@ -37,6 +37,7 @@ import app.revanced.manager.ui.component.bundle.BundleSelector
import app.revanced.manager.ui.component.settings.SettingsListItem import app.revanced.manager.ui.component.settings.SettingsListItem
import app.revanced.manager.ui.viewmodel.ImportExportViewModel import app.revanced.manager.ui.viewmodel.ImportExportViewModel
import app.revanced.manager.util.toast import app.revanced.manager.util.toast
import app.revanced.manager.util.uiSafe
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import org.koin.androidx.compose.koinViewModel import org.koin.androidx.compose.koinViewModel
@ -86,10 +87,12 @@ fun ImportExportSettingsScreen(
onDismissRequest = vm::cancelKeystoreImport, onDismissRequest = vm::cancelKeystoreImport,
onSubmit = { cn, pass -> onSubmit = { cn, pass ->
vm.viewModelScope.launch { vm.viewModelScope.launch {
uiSafe(context, R.string.failed_to_import_keystore, "Failed to import keystore") {
val result = vm.tryKeystoreImport(cn, pass) val result = vm.tryKeystoreImport(cn, pass)
if (!result) context.toast(context.getString(R.string.import_keystore_wrong_credentials)) if (!result) context.toast(context.getString(R.string.import_keystore_wrong_credentials))
} }
} }
}
) )
} }

View File

@ -69,6 +69,7 @@ class ImportExportViewModel(
} }
fun startKeystoreImport(content: Uri) = viewModelScope.launch { fun startKeystoreImport(content: Uri) = viewModelScope.launch {
uiSafe(app, R.string.failed_to_import_keystore, "Failed to import keystore") {
val path = withContext(Dispatchers.IO) { val path = withContext(Dispatchers.IO) {
File.createTempFile("signing", "ks", app.cacheDir).toPath().also { File.createTempFile("signing", "ks", app.cacheDir).toPath().also {
Files.copy( Files.copy(
@ -89,6 +90,7 @@ class ImportExportViewModel(
keystoreImportPath = path keystoreImportPath = path
} }
}
fun cancelKeystoreImport() { fun cancelKeystoreImport() {
keystoreImportPath?.deleteExisting() keystoreImportPath?.deleteExisting()

View File

@ -419,4 +419,5 @@
<string name="never_show_again">Never show again</string> <string name="never_show_again">Never show again</string>
<string name="show_manager_update_dialog_on_launch">Show update message on launch</string> <string name="show_manager_update_dialog_on_launch">Show update message on launch</string>
<string name="show_manager_update_dialog_on_launch_description">Shows a popup notification whenever there is a new update available on launch.</string> <string name="show_manager_update_dialog_on_launch_description">Shows a popup notification whenever there is a new update available on launch.</string>
<string name="failed_to_import_keystore">Failed to import keystore</string>
</resources> </resources>