Can I write plugins using compose? Like being able...
# compose-desktop
d
Can I write plugins using compose? Like being able to add a jar to an app that will change/add screens. I'm not sure how to do this right now.
t
yes, it is possible. i have not done it myself. I only remembered this example. https://github.com/JetBrains/compose-jb/tree/master/examples/intellij-plugin
k
Plugins for what? For a random Compose app, or for an app that you are developing? If it’s for an app you’re developing where you want to allow third-party developers to write plugins that integrate with your core app experience, there’s nothing particularly special about Compose. You define the way for plugins to register themselves at runtime - usually with an XML file (or any other config file) under META-INF, scan the classpath for all such plugins, instantiate them and “expose” them in your app UI. The rest is really up to you - to define what plugins can do, and what kind of interface(s) those plugins need to implement to participate in your app UI.
d
Thank you, that's what I want, do you have an example of how to implement that?
b
https://github.com/pf4j/pf4j would be a good start
k
The only compose specific thing I can think of here is how to have Composable functions work with reflection from the Java side of things.
d
Yes, I'm not sure how they will work since they will be compiled separately, but I'll try to work on something, will post here if I succeed
m
There's a simple plugin mechanism built in, the
ServiceLoader
o
I believe the simplest way would be to require plugin to implement some interface, and you can have
@Composable
functions on it, and implement them in plugin. Compose works with polymorphism just fine.
b
Wait, but the jar plugin would also need to be compiled with compose compiler plugin, correct?
o
For sure
b
I see how this might cause a lot of misunderstanding between 3rd party plugin authors 😀
o
Well, I don’t think it would be a big issue, if the app is not very popular (few people will do it anyway), or if the app is very popular (people are generally okay to adapt to whatever technology is required). E.g. if I need to develop a plugin to Wordpress, well, I probably have to code in PHP 🙂
d
Or use swing composables when the overlay bug is fixed