Giter VIP home page Giter VIP logo

Comments (11)

pablichjenkov avatar pablichjenkov commented on May 27, 2024 2

kotlinx-coroutines-swing should go in jvmMain/desktopMain dependecies block.

from compose-multiplatform.

kropp avatar kropp commented on May 27, 2024 2

Hi @luanrodrigsr
I confirm that this is a bug in Lifecycle implementation for desktop target.
The good news is that it is already fixed, however, the fix is not yet published.
I tried your snippet on the newer version and it now works.
Currently, I would expect it to be available Lifecycle 2.8.0-rc01 release and the subsequent Compose 1.6.10-rc01 release.

from compose-multiplatform.

pablichjenkov avatar pablichjenkov commented on May 27, 2024 1

Oh. I tried both of them, separately. Not at the same time.

I am using desktopMain right now, by the way.

Ah ok sorry I misunderstood you. Can you post the errors you are getting

from compose-multiplatform.

luanrodrigsr avatar luanrodrigsr commented on May 27, 2024 1

The code after the lifecycleRegistry.currentState = Lifecycle.State.CREATED line is not being executed. Which is preventing the "Application" for being created. It only happens when i use the kotlinx-coroutines-swing dependency.

Captura de tela 2024-04-21 204421

But, when i updated the code on line 75 to LifecycleRegistry.createUnsafe(this), it works fine. (Pay attention to the debug panel which shows the enforceMainThread field set to false. Looking at the source code, this parameter is present in the private constructor of the LifecycleRegistry, that is (i believe) supposed to be always true).

Captura de tela 2024-04-21 204704

The documentation says that the method createUnsafe:

Creates a new LifecycleRegistry for the given provider, that doesn't check that its methods are called on the threads other than main. LifecycleRegistry is not synchronized: if multiple threads access this LifecycleRegistry, it must be synchronized externally.

Considering all this, I may not be fully aware of the implications that using the createUnsafe method can bring. Except for the fact that "if multiple threads access this LifecycleRegistry, it must be synchronized externally".

from compose-multiplatform.

pablichjenkov avatar pablichjenkov commented on May 27, 2024 1

I see, Humm 🤔 seems like a problem inside LifecycleRegistry constructor. You are basically having a silent crash or so.
It is hard to predict with logs or more information. I would start by checking the implementation of LifecycleRegistry.

from compose-multiplatform.

luanrodrigsr avatar luanrodrigsr commented on May 27, 2024

Hey @pablichjenkov, thanks! I updated my build.gradle.kts files, but still couldn't get the code to work.

Captura de tela 2024-04-20 235522
Captura de tela 2024-04-21 000051

from compose-multiplatform.

pablichjenkov avatar pablichjenkov commented on May 27, 2024

I think you misunderstood my previous comment. You have either jvmMain or desktopMain not both. Need to add swing dependecy in one of them. Are you using jvmMain or desktopMain?

from compose-multiplatform.

luanrodrigsr avatar luanrodrigsr commented on May 27, 2024

Oh. I tried both of them, separately. Not at the same time.

I am using desktopMain right now, by the way.

from compose-multiplatform.

luanrodrigsr avatar luanrodrigsr commented on May 27, 2024

To add more context, what I'm trying to achieve is to create a custom implementation of the LifecycleOwner interface in an abstract Application class that will be responsible for controlling the lifecycle of the desktop app (outside of compose). I needed to add the kotlinx-coroutines-swing dependency because of the "Module with the Main dispatcher is missing" (#4653) error.

from compose-multiplatform.

luanrodrigsr avatar luanrodrigsr commented on May 27, 2024

Thank you. I will try to dig into the implementation.

I just wanna note that the enforceMainThread being set to false on the example i gave is working as intended, I think, since it is the role of the createUnsafe method.

This makes me wonder if the right way to create a LifecycleRegistry, in my case, wasn't using the public constructor which sets this field to true . I am just too worried about the inability to do so. I mean, the lifecycle registry is created, but I'm unable to interact with it.

from compose-multiplatform.

luanrodrigsr avatar luanrodrigsr commented on May 27, 2024

Thank you! @kropp

from compose-multiplatform.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.