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
8 files
+ 179
60
Compare changes
  • Side-by-side
  • Inline
Files
8
package org.briarproject.briar.desktop.ui
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.compositionLocalOf
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.ApplicationScope
import androidx.compose.ui.window.Window
import androidx.compose.ui.window.application
import org.briarproject.bramble.api.account.AccountManager
import org.briarproject.bramble.api.contact.ContactManager
import org.briarproject.bramble.api.identity.IdentityManager
@@ -37,7 +38,8 @@ enum class Screen {
interface BriarUi {
fun start()
@Composable
fun start(applicationScope: ApplicationScope)
fun stop()
}
@@ -77,57 +79,57 @@ 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) {
contactListViewModel.loadContacts()
screenState = Screen.MAIN
}
Screen.LOGIN ->
Login(loginViewModel) {
contactListViewModel.loadContacts()
screenState = Screen.MAIN
}
else ->
CompositionLocalProvider(
CVM provides conversationManager,
CTM provides contactManager,
MM provides messagingManager,
IM provides identityManager,
) {
MainScreen(
contactListViewModel,
addContactViewModel,
introductionViewModel,
isDark,
setDark
)
}
}
@Composable
override fun start(applicationScope: ApplicationScope) {
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(); applicationScope.exitApplication() },
) {
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 ->
CompositionLocalProvider(
CVM provides conversationManager,
CTM provides contactManager,
MM provides messagingManager,
IM provides identityManager,
) {
MainScreen(
contactListViewModel,
addContactViewModel,
introductionViewModel,
isDark,
setDark
)
}
}
}
}
Loading