Home

Awesome

webviewko

Kotlin Kotlin Kotlin license release gradle ci last commit

<!-- See [RFC4646](https://www.ietf.org/rfc/rfc4646.txt), [W3C language tags](https://www.w3.org/International/articles/language-tags/#bytheway) and [iana](https://www.iana.org/assignments/language-subtag-registry) -->

English | 中文(简体)

webviewko provides a Kotlin Multiplatform binding to webview, a tiny cross-platform webview library to build modern cross-platform desktop GUIs using WebView2, WebKit and WebKitGTK.


Looking for Developers to Take Over This Project
Unfortunately, due to my busy schedule during graduate school and my loss of interest in the Kotlin technology, I am no longer willing to maintain this project.
If anyone is interested in taking over the maintenance of this project, please contact me by submitting an issue. I will hand over the development of this project to you.


screenshot

Getting Started

1. Import webviewko

If you're using a build system like Gradle or Maven, it's recommended to import webviewko via GitLab Packages.

For build.gradle.kts, just use:

repositories {
    mavenCentral()
    maven("https://gitlab.com/api/v4/projects/38224197/packages/maven")
}

implementation("com.github.winterreisender:webviewko:0.6.0")            // Kotlin Multiplatform
implementation("com.github.winterreisender:webviewko-jvm:0.6.0")        // Kotlin/JVM and Java
implementation("com.github.winterreisender:webviewko-linuxx64:0.6.0")   // Kotlin/Native Linux x64
implementation("com.github.winterreisender:webviewko-mingwx64:0.6.0")   // Kotlin/Native Windows x64
implementation("com.github.winterreisender:webviewko-macosx64:0.6.0")   // Kotlin/Native macOS x64
implementation("com.github.winterreisender:webviewko-js:0.5.0")         // Kotlin/JS Node.js

2. Use webviewko

import com.github.winterreisender.webviewko.WebviewKo

WebviewKo().run {
    title("Title")
    size(800, 600)
    url("https://example.com")
    show()
}

3. Interact with webview

You can use bind,init,dispatch and eval to interact with your webview:

import com.github.winterreisender.webviewko.WebviewKo

WebviewKo(1).run {
  title("Test")
  init("""console.log("Hello, from  init")""")
  bind("increment") {
    val r :Int = it.removePrefix("[\"").removeSuffix("\"]").toInt() + 1
    println(r.toString())
    if(r==8)
      terminate()
    "{count: $r}"
  }
  html("""
              <button id="increment">Tap me</button>
              <div>You tapped <span id="count">0</span> time(s).</div>
              <script>
              const [incrementElement, countElement] = document.querySelectorAll("#increment, #count");
                document.addEventListener("DOMContentLoaded", () => {
                  incrementElement.addEventListener("click", () => {
                    window.increment(countElement.innerText).then(result => {
                      countElement.textContent = result.count; });});});
               </script>""")
  show()
}

Help

Contribution

All suggestions, pull requests, issue and other contributions are welcome and appreciated.

Credits

ProjectLicense
webviewMIT
webview_javaMIT
webview-nodejsApache-2.0
node-ffi-napiMIT
JNALGPL-2.1-or-later OR Apache-2.0
Microsoft Webview2BSD-style
Kotlin & kotlinxApache-2.0

License

Copyright 2022 Winterreisender and other contributors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.