diff --git a/briar-desktop/src/main/kotlin/org/briarproject/briar/desktop/login/ErrorSubViewModel.kt b/briar-desktop/src/main/kotlin/org/briarproject/briar/desktop/login/ErrorSubViewModel.kt index 07a2acc9d3554c851d243f817a2ed7df2376a70a..134562098a6121f6631415e71a7ba409912db50d 100644 --- a/briar-desktop/src/main/kotlin/org/briarproject/briar/desktop/login/ErrorSubViewModel.kt +++ b/briar-desktop/src/main/kotlin/org/briarproject/briar/desktop/login/ErrorSubViewModel.kt @@ -1,6 +1,6 @@ /* * Briar Desktop - * Copyright (C) 2021-2022 The Briar Project + * Copyright (C) 2021-2023 The Briar Project * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as @@ -21,7 +21,7 @@ package org.briarproject.briar.desktop.login class ErrorSubViewModel( private val viewModel: StartupViewModel, val error: Error, - val onBackButton: (() -> Unit)?, + val onBackButton: (() -> Unit)? = null, ) : StartupViewModel.SubViewModel { sealed interface Error } diff --git a/briar-desktop/src/main/kotlin/org/briarproject/briar/desktop/login/RegistrationSubViewModel.kt b/briar-desktop/src/main/kotlin/org/briarproject/briar/desktop/login/RegistrationSubViewModel.kt index eae000878cd1a5e8f10183935eb1586ff976be41..f8556bc01d63955f1a3df4c5925eaaf80c8aef68 100644 --- a/briar-desktop/src/main/kotlin/org/briarproject/briar/desktop/login/RegistrationSubViewModel.kt +++ b/briar-desktop/src/main/kotlin/org/briarproject/briar/desktop/login/RegistrationSubViewModel.kt @@ -1,6 +1,6 @@ /* * Briar Desktop - * Copyright (C) 2021-2022 The Briar Project + * Copyright (C) 2021-2023 The Briar Project * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as @@ -122,7 +122,7 @@ class RegistrationSubViewModel( viewModel.startBriarCore() } else { LOG.w { "Failed to create account" } - viewModel.showError(RegistrationError) + viewModel.showError(RegistrationError, true) } } } diff --git a/briar-desktop/src/main/kotlin/org/briarproject/briar/desktop/login/StartupViewModel.kt b/briar-desktop/src/main/kotlin/org/briarproject/briar/desktop/login/StartupViewModel.kt index a51ba875fe9fb08d3097be14f36f8b11c970a438..c44e454ebca48e05d9d06037ab240a2c7794a268 100644 --- a/briar-desktop/src/main/kotlin/org/briarproject/briar/desktop/login/StartupViewModel.kt +++ b/briar-desktop/src/main/kotlin/org/briarproject/briar/desktop/login/StartupViewModel.kt @@ -1,6 +1,6 @@ /* * Briar Desktop - * Copyright (C) 2021-2022 The Briar Project + * Copyright (C) 2021-2023 The Briar Project * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as @@ -82,12 +82,16 @@ constructor( _currentSubViewModel.value = makeRegistration() } - private fun makeError(error: ErrorSubViewModel.Error) = ErrorSubViewModel( - this, error, onBackButton = { _currentSubViewModel.value = decideSubViewModel() } - ) + private fun makeError(error: ErrorSubViewModel.Error, allowBackNavigation: Boolean): ErrorSubViewModel { + return if (allowBackNavigation) { + ErrorSubViewModel(this, error, onBackButton = { _currentSubViewModel.value = decideSubViewModel() }) + } else { + ErrorSubViewModel(this, error) + } + } - fun showError(error: ErrorSubViewModel.Error) { - _currentSubViewModel.value = makeError(error) + fun showError(error: ErrorSubViewModel.Error, allowBackNavigation: Boolean) { + _currentSubViewModel.value = makeError(error, allowBackNavigation) } private fun makeAbout(previous: SubViewModel) = @@ -110,7 +114,7 @@ constructor( ALREADY_RUNNING -> LOG.i { "Already running" } else -> { LOG.w { "Startup failed: $result" } - showError(StartingError(result)) + showError(StartingError(result), false) } } } diff --git a/briar-desktop/src/test/kotlin/org/briarproject/briar/desktop/RunWithTemporaryAccount.kt b/briar-desktop/src/test/kotlin/org/briarproject/briar/desktop/RunWithTemporaryAccount.kt index 725b308878b6a4fd92709fea84edfe155c1a759e..7b50b7493bbf9ee3e34fdcd8324403de2ab237bf 100644 --- a/briar-desktop/src/test/kotlin/org/briarproject/briar/desktop/RunWithTemporaryAccount.kt +++ b/briar-desktop/src/test/kotlin/org/briarproject/briar/desktop/RunWithTemporaryAccount.kt @@ -1,6 +1,6 @@ /* * Briar Desktop - * Copyright (C) 2021-2022 The Briar Project + * Copyright (C) 2021-2023 The Briar Project * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as @@ -17,6 +17,7 @@ */ @file:Suppress("HardCodedStringLiteral") + package org.briarproject.briar.desktop import androidx.compose.runtime.LaunchedEffect @@ -24,6 +25,8 @@ import androidx.compose.ui.ExperimentalComposeUiApi import androidx.compose.ui.window.application import mu.KotlinLogging import org.briarproject.bramble.BrambleCoreEagerSingletons +import org.briarproject.bramble.api.lifecycle.Service +import org.briarproject.bramble.api.lifecycle.ServiceException import org.briarproject.briar.BriarCoreEagerSingletons import org.briarproject.briar.desktop.TestUtils.getDataDir import org.briarproject.briar.desktop.utils.KLoggerUtils.i @@ -37,6 +40,7 @@ internal class RunWithTemporaryAccount( val createAccount: Boolean = true, val login: Boolean = true, val makeDirUnwritable: Boolean = false, + val addBrokenService: Boolean = false, val customization: BriarDesktopTestApp.() -> Unit = {}, ) { @@ -78,6 +82,16 @@ internal class RunWithTemporaryAccount( val lifecycleManager = app.getLifecycleManager() val accountManager = app.getAccountManager() + if (addBrokenService) { + lifecycleManager.registerService(object : Service { + override fun startService() { + throw ServiceException() + } + + override fun stopService() {} + }) + } + if (createAccount) { val password = "verySecret123!" accountManager.createAccount("alice", password) diff --git a/briar-desktop/src/test/kotlin/org/briarproject/briar/desktop/TestStartupWithBrokenService.kt b/briar-desktop/src/test/kotlin/org/briarproject/briar/desktop/TestStartupWithBrokenService.kt new file mode 100644 index 0000000000000000000000000000000000000000..821f193a324ff732ed2f306be935991507b6b639 --- /dev/null +++ b/briar-desktop/src/test/kotlin/org/briarproject/briar/desktop/TestStartupWithBrokenService.kt @@ -0,0 +1,27 @@ +/* + * Briar Desktop + * Copyright (C) 2023 The Briar Project + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +package org.briarproject.briar.desktop + +/* + * Running this scenario will show an error message after account creation. + */ +fun main() = RunWithTemporaryAccount( + createAccount = false, + addBrokenService = true, +).run()