Kotlin/Native and cross platform web-based UI?


#1

Hi all,

I’m very excited about Kotlin/Native and want to use it to create a small Hello World web-based application in a cross platform way. I found the gtk-based kotlin/native example but it is not exactly what I want. It would be great if we could create a cross platform API to show a web page in a window with JavaScript supported using embedded webkit (so web-based UI will be possible with React, Vue, Vue Material etc). The idea is something like nwjs or Electron but in Kotlin/Native

Do you have any idea or some example to share?

Thanks a lot!

-Thai


#2

I think what you want would be a bit of work, if you just want to have an electron like app you need to implement for each platform and use their native web framework (webkit on macOS, UWP on Windows and on Linux maybe embed in your library an web engine like webkit) then build a bridge or some kind of way to interact with the html/css.

If you use this approach your apps will be smaller on Windows and macOS but on Linux you will have almost the same overhead of electron, just b/c you need to embed the webkit/chromium on it.

May you start on Windows that will be easier b/c its well documented

https://docs.microsoft.com/en-us/windows/uwp/design/basics/design-and-ui-intro

On mac you need to check the framework documentation, but its just a documentation, maybe you need to find examples or tutorials on how to use it

https://developer.apple.com/documentation/webkit/webview

And last Linux, I’ve no experience on embedding webkit or chromium.

The only thing that I don’t like about Kotlin Native its that you could only use with CLion and I don’t have any license to use it.

Edit

You can check this thread about the windows webview

https://github.com/pojala/electrino/issues/6


#3

Not sure about this idea, unless it’s something specific that require underlying native platform features without using C/C++ or similar lanugages. There are lots of ways to embed JVM, which allow you to stay on your rails. That’s my opinion.


#4

Thank you for the info! It looks like the APIs are not ready for cross platform development yet and any serious work will require platform specific APIs. What do you think? Do you find Kotlin/Native is useful for your work?


#5

Thank you for your idea. I will try to embed JVM to see how it works.


#6

Indeed you could use the webview of javafx or javafx directly to build the UI (check tornadofx).

But every crossplatform implementation requires platform specific code for each platform, in this case or you could just embed chromium.

I think you want an easy solution to do a crossplatform app, right now theres no such proyecto that Im aware in the kotlin native ecosystem, but I was thinking a while ago about this kind of approach, its just kotlin native isnt production ready and the tools to work with are experimental (the clion support comes a week ago or something like that).


#7

I agree. Maybe I will wait for some time until the ecosystem and the API is more complete and try again.


#8

I have a “good” idea here, how about use an embedded server as a local server and create a webapps that interact with the embedded server via Rest. The requirement here is the users must have a modern browser preinstalled.