Hello, How do I open a new Window in the middle of...
# compose-desktop
k
Hello, How do I open a new Window in the middle of a @Composable function, and pause the execution while keeping the Window open until it is manually closed?? See thread for code. Thanks!
Copy code
println("Opening settings window...")
    var showSettings by remember { mutableStateOf(true) }
    if (showSettings) {
        Window(
            state = rememberWindowState(
                width = 300.dp,
                height = 500.dp,
                position = WindowPosition(100.dp, 100.dp)
            ),
            onCloseRequest = { showSettings = false },
        ) { /* etc done here */ }
        println("Closing settings window...")
    }
The window flashes up for a brief moment, then closes, continuing execution of the function it is within.
s
I think you want to a
LaunchedEffect
like:
Copy code
LaunchedEffect(showSettings) {
    if (!showSettings) {
        println("Closing settings window")
    }
}
k
Thanks! So that will pause the function until the window is closed by the user?
s
Composable functions shouldn't block/suspend, so there's no way to do what you wrote.
No, but it will execute some code when the window is closed.
k
Yes OK. I tried putting it out in a separate function, but still the same effect. I'll try the launchedEffect idea. Thanks!
I need to somehow sequence things differently I guess. More learning!
s
The other option is to put that code in
onCloseRequest
k
How would you load a @Composable in the middle of .......
I think I was just trying to type that!! Yes, that starts to gel with my thoughts now!
So, do the first stuff, then open the window to display the values, edit the values, then call the next code/function using the onCloseRequest callback?
s
I guess? I'm not really sure what you're trying to do.
k
Yep. I'll try that idea anyway. Thanks so much for your attention! 😎
s
A settings dialog should either apply the settings as the user changes them or when they click ok/save. Usually closing a dialog is a no-op.
k
Yes, true. That should be adjustable in the logic. I'm heading for bed here now, so you have a nice day! 😄
s
Good night
k
Yep, thanks mate.