stakwork / sphinx-kotlin

MIT License
18 stars 11 forks source link

Desktop Kotlin using Compose Multiplatform Program framework #383

Open kngako opened 2 years ago

kngako commented 2 years ago

The Compose Multiplatform framework can be used to build desktop apps for Windows, Linux, and Macos (as well as web) using kotlin.

Core

Due to how fragmented the modules Matt put together we can easily pull the ones that we need for the cross platform app (like wrappers, repositories, tor networking and the likes) into a core library that the desktop/android app can pull in for core Sphinx functionality with a common codebase that can be used across platforms.

This library could have it's own repo at sphinx-kotlin-core?

UI

We have the option to create a Sphinx UI library and make it easier to have a consistent UI between the desktop and android apps. As a start the desktop app will be the only app using the compose UI elements but we can slowly transition the android app to using compose UI elements in all it's activities/fragments.

This library could have it's own repo at sphinx-kotlin-ui?

Pending Investigation

The tor library still needs to be tested for crossplatform support.

Getting Started

The following need to be installed to easily get started with compose-mpp:

05nelsonm commented 2 years ago

Modules

You can maintain the modularized codebase by simply modifying the build.gradle to add the targets you'd like to support, then change the package name to commonMain. I think creating a Gradle Plugin for library modules that has a default setup would be the most optimal approach so you have the same structured source sets everywhere, and a Single Source of Truth that, upon modifying, will be inherited by all modules.

See example plugin Here See example use of plugin Here

Sphinx.kotlin-android -> KMP lib support

I've migrated some of the kotlin-android tools that I first created (which Sphinx is depending on via git submodule) to KMP, and published them to Maven Central.

See KotlinComponents

There is, however, little support for cryptography on KMP, so an alternative would be needed for authentication as it utilizes android specific framework EncryptedSharedPreferences. I believe SQLDelight + SQLCipher would be the best work-around to this for non-android which you could easliy wedge in since all references are to the AuthenticationStorage interface which, if moved to commonMain can be implemented using the db for those platforms.

Tor

I'm actively working on a KotlinMultiplatform Tor library to replace TOPL-Android that has much better functionality and is superior in architecture.

Its initial release will support:

With next steps to supporting native desktop (highly dependent on the new KMP native memory model released in 1.6, but looking very promising):

and then darwin mobile:

As it depends on Coroutines & Atomicfu, I am limited in supporting some frameworks until those 2 libraries offer support for them.

I could definitely use some help with Rust creating the JNI bindings for Android/Java, if you could ping someone that would want to contribute that'd be :fire:

Networking

Sphinx uses OkHttp, but as things are structured you could easily swap that out for KTor (unless you'd like to wait for Jesse to finish migrating OkHttp to KMP).

kngako commented 2 years ago

Thanks for fleshing this out a little more. I've recently stumbled across a kotlin Tor binding netlayer being used in bisq. From what I saw it doesn't seem to have any Android support at the current moment.

Have you checked out netlayer before and have any thoughts on it being used for the desktop tor connections?

05nelsonm commented 2 years ago

That is Java.

If you were to create a Java desktop app, that could work, sure