Hi, how would you go about using platform calls in...
# compose-desktop
a
Hi, how would you go about using platform calls in compose-desktop? I was looking for something similar to iOS and use expect / actual to call some mac framework or windows / linux stuff, is that at all possible?
👌 1
a
On iOS interop with native calls is easier because it’s Kotlin Native. On the desktop it’s Kotlin/JVM, so you have to go through JNI or JNA.
a
thanks, although I was hoping for something nicer 😉 do you happen to know any opensource project / sample code where a compose-desktop app does different native stuff for mac / win / linux? trying to store an encryption key or refresh token in keychain / DPAPI / (linux not sure what) as I couldn't find any kmp library (I would have assumed this is a common problem)
a
It’s something unrelated to Compose, really. Just google how to use JNI (or JNA, which is easier, but slower)
Or, nowadays, ask your choice of LLM
a
true, but the LLMs told me to just do a
macosArm64
instead of the
jvm
and use the
application {
so not sure how much of compose multiplatfrom code they have seen. I mean more to get a sense how good practice looks like in calling native code depending on the current platform. I assume I get the os from the jvm properties and do something based on that.
a
You can do separate source sets if you want. Or you could do an
external
function and link a different library on each platform. But again, this has nothing to do with Compose.
It’s just JVM/native interop.
a
thanks for your help
g
also you can find different Java/Swing libraries which already abstract some platoform calls, so they also work on different platforms, so just use them, depending on what kind of API you need
a
thanks @gildor - I had the same thought for my particular problem and ended up with this https://github.com/javakeyring/java-keyring in case anyone else has this exact problem
g
Yep, great, exactly this, one of advantages of using java ecosystem. For native, even if it be possible, it would require to write abstraction level for different OS (of course it could be not necessary for your case, but still quite a big limitations)
s
https://github.com/jnr/jnr-ffi makes it really easy to call native APIs from the JVM JNA is also pretty good