M.C. Escher
03/29/2024, 4:56 PMclass MyApp(
private val uiDispatcher: CoroutineDispatcher, ...
) : Application, CoroutineScope by CoroutineScope(SupervisorJob() + Dispatchers.Default) {
init {
launch { // <-- new
loadFonts() // <-- new
val button = ToggleButton().apply {
font = defaultFont
pointerChanged += PointerListener.pressed {
if (Button2 in it.buttons) {
it.consume()
val popupLocation = it.location
launch(uiDispatcher) {
println("show menu") // <-- never excuted
modal {
...
}
}
}
}
}
...
}
}
}
so basically i've moved everything inside that outer`launch`-block and added a loadFonts()
call which is similar to code in the example projects.
however, now the modal is not shown any more, the show menu
println never gets executed when i right-click on the button.
when i move the code below loadFonts()
outside of the outer launch
then the popup's working again, but then my font might not yet be loadedNick
03/29/2024, 7:49 PMM.C. Escher
03/29/2024, 8:15 PMlaunch
it calls it from the coroutinescope of the outer launch
, but as soon as the execution returns from that outer scope, kotlin cancels all 'inner' jobs ("structured concurrency")... i must make sure i call the inner launch using this@MyApp.launch {}