Skip to content

Commit 3d23482

Browse files
committed
fix: improve keystore import error handling and show toast
1 parent cd06d36 commit 3d23482

File tree

3 files changed

+22
-16
lines changed

3 files changed

+22
-16
lines changed

app/src/main/java/app/revanced/manager/ui/screen/settings/ImportExportSettingsScreen.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import app.revanced.manager.ui.component.bundle.BundleSelector
3737
import app.revanced.manager.ui.component.settings.SettingsListItem
3838
import app.revanced.manager.ui.viewmodel.ImportExportViewModel
3939
import app.revanced.manager.util.toast
40+
import app.revanced.manager.util.uiSafe
4041
import kotlinx.coroutines.launch
4142
import org.koin.androidx.compose.koinViewModel
4243

@@ -86,8 +87,10 @@ fun ImportExportSettingsScreen(
8687
onDismissRequest = vm::cancelKeystoreImport,
8788
onSubmit = { cn, pass ->
8889
vm.viewModelScope.launch {
89-
val result = vm.tryKeystoreImport(cn, pass)
90-
if (!result) context.toast(context.getString(R.string.import_keystore_wrong_credentials))
90+
uiSafe(context, R.string.failed_to_import_keystore, "Failed to import keystore") {
91+
val result = vm.tryKeystoreImport(cn, pass)
92+
if (!result) context.toast(context.getString(R.string.import_keystore_wrong_credentials))
93+
}
9194
}
9295
}
9396
)

app/src/main/java/app/revanced/manager/ui/viewmodel/ImportExportViewModel.kt

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -69,25 +69,27 @@ class ImportExportViewModel(
6969
}
7070

7171
fun startKeystoreImport(content: Uri) = viewModelScope.launch {
72-
val path = withContext(Dispatchers.IO) {
73-
File.createTempFile("signing", "ks", app.cacheDir).toPath().also {
74-
Files.copy(
75-
contentResolver.openInputStream(content)!!,
76-
it,
77-
StandardCopyOption.REPLACE_EXISTING
78-
)
72+
uiSafe(app, R.string.failed_to_import_keystore, "Failed to import keystore") {
73+
val path = withContext(Dispatchers.IO) {
74+
File.createTempFile("signing", "ks", app.cacheDir).toPath().also {
75+
Files.copy(
76+
contentResolver.openInputStream(content)!!,
77+
it,
78+
StandardCopyOption.REPLACE_EXISTING
79+
)
80+
}
7981
}
80-
}
8182

82-
aliases.forEach { alias ->
83-
knownPasswords.forEach { pass ->
84-
if (tryKeystoreImport(alias, pass, path)) {
85-
return@launch
83+
aliases.forEach { alias ->
84+
knownPasswords.forEach { pass ->
85+
if (tryKeystoreImport(alias, pass, path)) {
86+
return@launch
87+
}
8688
}
8789
}
88-
}
8990

90-
keystoreImportPath = path
91+
keystoreImportPath = path
92+
}
9193
}
9294

9395
fun cancelKeystoreImport() {

app/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,4 +419,5 @@
419419
<string name="never_show_again">Never show again</string>
420420
<string name="show_manager_update_dialog_on_launch">Show update message on launch</string>
421421
<string name="show_manager_update_dialog_on_launch_description">Shows a popup notification whenever there is a new update available on launch.</string>
422+
<string name="failed_to_import_keystore">Failed to import keystore</string>
422423
</resources>

0 commit comments

Comments
 (0)