Skip to content
Snippets Groups Projects

Make it possible to run multiple versions of briar-desktop concurrently

Merged Sebastian requested to merge 77-run-two-instances-in-parallel into main
Compare and
10 files
+ 226
81
Compare changes
  • Side-by-side
  • Inline
Files
10
package org.briarproject.briar.desktop.ui
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.window.Window
import androidx.compose.ui.window.application
import org.briarproject.bramble.api.account.AccountManager
import org.briarproject.bramble.api.lifecycle.LifecycleManager
import org.briarproject.bramble.api.lifecycle.LifecycleManager.LifecycleState.RUNNING
@@ -33,7 +33,8 @@ enum class Screen {
interface BriarUi {
fun start()
@Composable
fun start(onClose: () -> Unit)
fun stop()
}
@@ -66,51 +67,51 @@ constructor(
}
}
override fun start() {
application {
val (isDark, setDark) = remember { mutableStateOf(true) }
val title = "Briar Desktop"
var screenState by remember {
mutableStateOf(
if (accountManager.hasDatabaseKey()) {
// this should only happen during testing when we launch the main UI directly
// without a need to enter the password.
contactListViewModel.loadContacts()
Screen.MAIN
} else if (accountManager.accountExists()) {
Screen.LOGIN
} else {
Screen.REGISTRATION
}
)
}
Window(
title = title,
onCloseRequest = { stop(); exitApplication() },
) {
window.minimumSize = Dimension(800, 600)
BriarTheme(isDarkTheme = isDark) {
when (screenState) {
Screen.REGISTRATION ->
Registration(registrationViewModel) {
screenState = Screen.MAIN
}
Screen.LOGIN ->
Login(loginViewModel) {
contactListViewModel.loadContacts()
screenState = Screen.MAIN
}
else ->
MainScreen(
contactListViewModel,
conversationViewModel,
addContactViewModel,
introductionViewModel,
sidebarViewModel,
isDark,
setDark
)
}
@Composable
override fun start(onClose: () -> Unit) {
val (isDark, setDark) = remember { mutableStateOf(true) }
val title = "Briar Desktop"
var screenState by remember {
mutableStateOf(
if (accountManager.hasDatabaseKey()) {
// this should only happen during testing when we launch the main UI directly
// without a need to enter the password.
contactListViewModel.loadContacts()
Screen.MAIN
} else if (accountManager.accountExists()) {
Screen.LOGIN
} else {
Screen.REGISTRATION
}
)
}
Window(
title = title,
onCloseRequest = onClose,
) {
window.minimumSize = Dimension(800, 600)
BriarTheme(isDarkTheme = isDark) {
when (screenState) {
Screen.REGISTRATION ->
Registration(registrationViewModel) {
contactListViewModel.loadContacts()
screenState = Screen.MAIN
}
Screen.LOGIN ->
Login(loginViewModel) {
contactListViewModel.loadContacts()
screenState = Screen.MAIN
}
else ->
MainScreen(
contactListViewModel,
conversationViewModel,
addContactViewModel,
introductionViewModel,
sidebarViewModel,
isDark,
setDark
)
}
}
}
Loading