diff --git a/src/main/kotlin/org/briarproject/briar/desktop/login/ErrorScreen.kt b/src/main/kotlin/org/briarproject/briar/desktop/login/ErrorScreen.kt index 1c344a4b1b5626a0203b8acec6ae40149acd2b71..3744c8608d45b07ebcc51d4571a22842c753ff7f 100644 --- a/src/main/kotlin/org/briarproject/briar/desktop/login/ErrorScreen.kt +++ b/src/main/kotlin/org/briarproject/briar/desktop/login/ErrorScreen.kt @@ -37,11 +37,14 @@ import org.briarproject.briar.desktop.utils.InternationalizationUtils.i18n import org.briarproject.briar.desktop.utils.PreviewUtils.preview fun main() = preview { - var error by remember { mutableStateOf(SUCCESS) } + var error: ErrorViewHolder.Error by remember { mutableStateOf(RegistrationViewHolder.RegistrationError) } Row(horizontalArrangement = spacedBy(8.dp)) { + Button(onClick = { error = RegistrationViewHolder.RegistrationError }) { + Text("Registration") + } for (e in StartResult.values().filterNot { it in listOf(SUCCESS, ALREADY_RUNNING) }) { - Button(onClick = { error = e }) { + Button(onClick = { error = StartupViewModel.StartingError(e) }) { Text(e.name.removeSuffix("_ERROR")) } } @@ -56,7 +59,7 @@ fun ErrorScreen(viewHolder: ErrorViewHolder) = @Composable fun ErrorScreen( - error: StartResult, + error: ErrorViewHolder.Error, onBackButton: () -> Unit, ) = Surface { IconButton(onClick = onBackButton) { @@ -78,12 +81,17 @@ fun ErrorScreen( Text(i18n("sorry"), style = MaterialTheme.typography.h5) val text = when (error) { - CLOCK_ERROR -> i18n("startup.failed.clock_error") - DB_ERROR -> i18n("startup.failed.db_error") - DATA_TOO_OLD_ERROR -> i18n("startup.failed.data_too_old_error") - DATA_TOO_NEW_ERROR -> i18n("startup.failed.data_too_new_error") - SERVICE_ERROR -> i18n("startup.failed.service_error") - else -> "" + is RegistrationViewHolder.RegistrationError -> i18n("startup.failed.registration") + is StartupViewModel.StartingError -> { + when (error.error) { + CLOCK_ERROR -> i18n("startup.failed.clock_error") + DB_ERROR -> i18n("startup.failed.db_error") + DATA_TOO_OLD_ERROR -> i18n("startup.failed.data_too_old_error") + DATA_TOO_NEW_ERROR -> i18n("startup.failed.data_too_new_error") + SERVICE_ERROR -> i18n("startup.failed.service_error") + else -> "" + } + } } Text( text = text, diff --git a/src/main/kotlin/org/briarproject/briar/desktop/login/ErrorViewHolder.kt b/src/main/kotlin/org/briarproject/briar/desktop/login/ErrorViewHolder.kt index 1f43078d385e5d492199e671749d02632d601150..8d540501ab66a6ce11625e1c7e07ca0f508ef565 100644 --- a/src/main/kotlin/org/briarproject/briar/desktop/login/ErrorViewHolder.kt +++ b/src/main/kotlin/org/briarproject/briar/desktop/login/ErrorViewHolder.kt @@ -4,6 +4,8 @@ import org.briarproject.bramble.api.lifecycle.LifecycleManager class ErrorViewHolder( private val viewModel: StartupViewModel, - val error: LifecycleManager.StartResult, + val error: Error, val onBackButton: () -> Unit, -) : StartupViewModel.ViewHolder +) : StartupViewModel.ViewHolder { + sealed interface Error +} diff --git a/src/main/kotlin/org/briarproject/briar/desktop/login/RegistrationViewHolder.kt b/src/main/kotlin/org/briarproject/briar/desktop/login/RegistrationViewHolder.kt index e83d4e6b3df82e273bad38eeaf5b216ea0f55b38..ca2a309376f907e11e06c0c6a754a05dc2be4cd4 100644 --- a/src/main/kotlin/org/briarproject/briar/desktop/login/RegistrationViewHolder.kt +++ b/src/main/kotlin/org/briarproject/briar/desktop/login/RegistrationViewHolder.kt @@ -24,6 +24,8 @@ class RegistrationViewHolder( private val LOG = KotlinLogging.logger {} } + object RegistrationError : ErrorViewHolder.Error + enum class State { INSERT_NICKNAME, INSERT_PASSWORD, CREATING, CREATED } @@ -100,8 +102,7 @@ class RegistrationViewHolder( viewModel.startBriarCore() } else { LOG.warn { "Failed to create account" } - _state.value = INSERT_NICKNAME - // todo: show (meaningful) error to user + viewModel.showError(RegistrationError) } } } diff --git a/src/main/kotlin/org/briarproject/briar/desktop/login/StartupViewModel.kt b/src/main/kotlin/org/briarproject/briar/desktop/login/StartupViewModel.kt index 9f8121894051de27fbb3d7371e910d6daddd48ec..bf426137677d7e00f609a32bc4e4cf9c28155cc3 100644 --- a/src/main/kotlin/org/briarproject/briar/desktop/login/StartupViewModel.kt +++ b/src/main/kotlin/org/briarproject/briar/desktop/login/StartupViewModel.kt @@ -36,6 +36,9 @@ constructor( fun lifecycleStateChanged(s: LifecycleManager.LifecycleState) {} } + class StartingError(val error: LifecycleManager.StartResult): + ErrorViewHolder.Error + private val _mode = mutableStateOf(decideMode()) val mode = _mode.asState() @@ -59,10 +62,10 @@ constructor( _mode.value = makeRegistration() } - private fun makeError(error: LifecycleManager.StartResult) = ErrorViewHolder( + private fun makeError(error: ErrorViewHolder.Error) = ErrorViewHolder( this, error, onBackButton = { _mode.value = decideMode() } ) - fun showError(error: LifecycleManager.StartResult) { + fun showError(error: ErrorViewHolder.Error) { _mode.value = makeError(error) } @@ -79,7 +82,7 @@ constructor( ALREADY_RUNNING -> LOG.info { "Already running" } else -> { LOG.warn { "Startup failed: $result" } - showError(result) + showError(StartingError(result)) } } } diff --git a/src/main/resources/strings/BriarDesktop.properties b/src/main/resources/strings/BriarDesktop.properties index 39f99f3c2461a66dd78c12f2794e95b59fc3ce9c..4f6b716a71c464fe9584a51a5541e481003417e4 100644 --- a/src/main/resources/strings/BriarDesktop.properties +++ b/src/main/resources/strings/BriarDesktop.properties @@ -139,6 +139,7 @@ startup.error.decryption.text=Briar cannot check your password. Please try reboo startup.password_forgotten.button=I have forgotten my password startup.password_forgotten.title=Lost Password startup.password_forgotten.text=Your Briar account is stored encrypted on your device, not in the cloud, so we can't reset your password. Would you like to delete your account and start again?\n\nCaution: Your identities, contacts and messages will be permanently lost. +startup.failed.registration=Briar was unable to create your account.\n\nPlease upgrade to the latest version and try again. startup.failed.clock_error=Briar was unable to start because your device's clock is wrong.\n\nPlease set your device's clock to the right time and try again. startup.failed.db_error=Briar was unable to open the database containing your account, your contacts and your messages.\n\nPlease upgrade to the latest version of the app and try again, or set up a new account by choosing 'I have forgotten my password' at the password prompt. startup.failed.data_too_old_error=Your account was created with an old version of this app and cannot be opened with this version.\n\nYou must either reinstall the old version or set up a new account by choosing 'I have forgotten my password' at the password prompt.