Skip to content

Conversation

oguzkocer
Copy link
Contributor

@oguzkocer oguzkocer commented Jun 10, 2024

This PR adds a Kotlin multiplatform example app to the repository to test our integration. The app only works on desktop and Android platforms. We've looked into the Apple platforms, but it doesn't look like it'll be possible to use neither the Kotlin uniffi bindings nor the Swift one from it.

The desktop version of the example app will use the :api:kotlin dependency which doesn't package the Rust binary. That's why the binary needs to be made available to it. In a real app, we'd have to do this by downloading it from a remote - maybe it can be done with a Gradle plugin - but because this example app is in the same repo, we are able to piggy-back on our existing infrastructure. I've moved generating the Rust binary and bindings from the :api:kotlin to the root project and made the necessary connections for Gradle to make it work for both :api:kotlin & :example:composeApp desktop projects.

Note that the desktop app doesn't support login. I am not sure how that can be achieved unless we decide to implement it per OS as it requires a callback app scheme. For now, I think it's good enough that the desktop app works only with the local test site from Docker.

For the Android app, we are able to use the :api:android dependency which does include the Rust binaries for all the relevant Android architectures. So, no extra configuration was necessary for it.

I've put together this example app very quickly. So, it's rough around the edges and includes several TODOs. It was meant as a proof of concept rather than a showcase for now. However, we'll be looking into improving it in the very near future to at least address some of the glaring issues. I need to switch to something urgent at the moment and keeping all this in a branch will just get in the way, so I think merging this quickly is our best course of action.

Here is a set of things I'd like to address in the next couple weeks:

  1. Move Android integration tests from :api:android to :example:composeApp. This will further simplify the :api:android repository and would also let us to deal with test credentials only once.
  2. Remove the :example module. I've had that module because it's the structure generated from the KMP new project wizard, presumably because it includes an iOS app folder, but since we won't have an Xcode project in KMP, we can simplify the structure my removing the :example module or :composeApp - depending on whichever name we prefer to keep.
  3. Login callback should use the Rust helper to parse the url and figure out the authentication. I've a mockup of this here.
  4. We need to implement url discovery to find the authentication url which is currently assuming it at wp-admin/authorize-application.php. We'd like to do this from Rust, so this is closely related to [3]. ^
  5. Figure out authentication scoped dependency injection. This is done very crudely at the moment from App.kt's onSiteClicked by using the setAuthenticatedSite for the relevant view models. There are so many things wrong with this approach that I don't think it's even worth explaining it. Let's just say we need to do this properly in an upcoming iteration 😅
  6. Audit the Gradle build scripts (because these are partially generated from the KMP new project wizard) and the example app implementation (as I probably missed other shortcomings in this list)

To Test

  • make test-server && make dump-mysql && make backup-wp-content-plugins
  • cd native/kotlin && ./gradlew run (to run the Desktop app)
  • cd native/kotlin and run the example.composeApp configuration from Android Studio for the Android app

Android App:
https://cloudup.com/cWIHvw1XmNH
Desktop App: (doesn't include login)
Screenshot 2024-06-10 at 15 02 49

@oguzkocer oguzkocer added this to the 0.1 milestone Jun 10, 2024
@oguzkocer oguzkocer marked this pull request as ready for review June 10, 2024 19:55
@oguzkocer oguzkocer enabled auto-merge (squash) June 10, 2024 20:00
Copy link
Contributor

@jkmassel jkmassel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ran the demo app on-device against a new test server, and it worked fine – I added some more plugins and reloaded the plugins list and it downloaded that data too.

This is a great start!

@oguzkocer oguzkocer merged commit 67e3a47 into trunk Jun 10, 2024
@oguzkocer oguzkocer deleted the kotlin-example-app branch June 10, 2024 21:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants