我正在尝试使用 compose 创建一个多窗口桌面应用程序。
他们将拥有完全不同的屏幕。一个是主屏幕,另一个是子屏幕。我试过这样。
子屏幕旨在由共享演示器内的某些状态流显示,它将在主屏幕上调用为 true,但为了使代码简短,我已经删除了该部分。
fun main() = application {
val windowState = rememberWindowState()
val subWindowState = rememberWindowState()
var isVisible by remember { mutableStateOf(true) }
var isSubScreenVisible by remember { mutableStateOf(false) }
val onVisibilityChanged : (Boolean) -> Unit = {
isVisible = it
}
setTray(this) {
isVisible = it
}
//Sub screen
Window(onCloseRequest = {
isSubScreenVisible = false
},
title = "SubScreen",
state = subWindowState,
undecorated = true,
resizable = false,
visible = isSubScreenVisible,
transparent = true) {
} {
AppTheme(darkTheme = false) {
//my sub screen composable..
}
}
//Main Screen
Window(
onCloseRequest = {
onVisibilityChanged(false)
},
icon = painterResource("logo.png"),
title = "Main Screen",
state = windowState,
undecorated = true,
resizable = false,
visible = isVisible,
transparent = true
){
AppTheme(darkTheme = false) {
val rootState by mPresenter.mRootState.collectAsState()
when(rootState){
is RootState.Splash -> {
showMessage("[RootNav] Splash")
Splash(this, mPresenter)
}
is RootState.NotLoggedIn -> {
showMessage("[RootNav] Login")
Login(mPresenter, this, windowState, onVisibilityChanged)
}
is RootState.LoggedIn -> {
showMessage("[RootNav] Main")
MainFrame(this, windowState, onVisibilityChanged)
}
}
}
}
}
此代码导致此异常。
Exception in thread "main" java.awt.IllegalComponentStateException: The frame is displayable.
此错误发生在主屏幕窗口上,并且没有显示任何内容。
这是什么意思?是否允许多个窗口,因为有 SingleWindowApplication 之类的东西?
我能做些什么 ?