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.
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:
```kotlin {3} 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
- [Additional steps](https://github.com/Winterreisender/webviewko/wiki/How-to-Import#using-gradle-with-kotlinnative) are required for Kotlin/Native in Linux.
- If you are using `JitPack.io` please move `maven("https://jitpack.io")` below `maven("https://gitlab.com/api/v4/projects/38224197/packages/maven")`
### 2. Use webviewko
```kotlin
import com.github.winterreisender.webviewko.WebviewKo
WebviewKo().run {
title("Title")
size(800, 600)
url("https://example.com")
show()
}
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()
}
All suggestions, pull requests, issue and other contributions are welcome and appreciated.
Project | License |
---|---|
webview | MIT |
webview_java | MIT |
webview-nodejs | Apache-2.0 |
node-ffi-napi | MIT |
JNA | LGPL-2.1-or-later OR Apache-2.0 |
Microsoft Webview2 | BSD-style |
Kotlin & kotlinx | Apache-2.0 |
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.