Hi ! I'm creating a simple ChessClock in a Compose...
# compose-desktop
l
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
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
Thank you I'm gonna try with the Default dispatcher. 🙂
d
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
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
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
You're right. I will have a look at blogs on Jetpack Compose (Medium ?) I can find a good article about it 🙂
d
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.