https://kotlinlang.org logo
#compose-desktop
Title
# compose-desktop
l

loloof64

03/25/2023, 9:46 AM
Hi ! I'm creating a simple ChessClock in a Compose for Desktop application. But it seems I'm facing a strange issue, which should be really related to my coding anti-patterns I guess. More in the thread 🧵 .
1
Here a testable version of my component.
The problem I'm facing that, when we keep the running window in foreground, all is fine. But as soon as we switch window on the guest os (I've tried on Ubuntu 22.04 64 bits), the clock is interrupted instead of keeping on running on the background. So is there a feature I should add / implement ? Or is it because of my coding anti-patterns ?
I've tested on Windows 11 64 bit, and it works normally on this platform. So I think it's defintely a Linux problem.
d

dewildte

03/25/2023, 1:54 PM
I am not sure what the problem is here but my gut tells me it's because the CoroutineScope you are using is launching things using the MainThread Dispatcher. What happens if you use the Default Dispatcher?
l

loloof64

03/25/2023, 3:23 PM
Thank you I'm gonna try with the Default dispatcher. 🙂
d

dewildte

03/25/2023, 3:24 PM
I can't guarantee that will work. It's just a hunch.
You could also try hoisting the state of the clock into a ViewModel that is updated by a different 🧵?
l

loloof64

03/25/2023, 3:26 PM
But it was an excellent advise 🙂 👍🏾 . It has solved my issue. 🙂
But I can't use ViewModel : there are not integrated into Compose for Desktop. Anyway thank you very much 🙂
d

dewildte

03/25/2023, 3:31 PM
ViewModel is just a design pattern it does not have to come from the Android ViewModel library.
I highly suggest researching it's history and usage in other platforms and technologies.
l

loloof64

03/25/2023, 3:35 PM
You're right. I will have a look at blogs on Jetpack Compose (Medium ?) I can find a good article about it 🙂
d

dewildte

03/25/2023, 3:37 PM
I actually suggest branching your understanding about the ViewModel pattern to outside the Compose world. ViewModels have been used before Compose was even an idea in a person's mind. They may have been in use before Android itself existed.
Anyway, glad I could help.
8 Views