webviewko

Kotlin Kotlin os license

release Gradle CI GitHub last commit JitPack

English | 中文(简体) | 中文(繁體)

webviewko provides a Kotlin/JVM and a Kotlin/Native(experimental) binding to webview, a tiny cross-platform webview library to build modern cross-platform GUIs using WebView2, WebKit and WebKitGTK.

screenshot

Getting Started

1. Import webviewko

If you’re using a build system like Gradle or Maven, see webviewko in JitPack.io

If you want to use jar files, see GitHub Release

2. Use webviewko

For Kotlin:

import com.github.winterreisender.webviewko.*
import com.sun.jna.Pointer;

with(WebviewKo()) {
    title("Basic Example")
    size(480, 320, WindowHint.None)
    html("Thanks for using webview!")
    show()
}

For Java:

import com.github.winterreisender.webviewko.*;

WebviewKo webview = new WebviewKo();
webview.title("webviewKo Java Test");
webview.size(1024,768,WindowHint.None);
webview.url("https://example.com");

webview.show();

Native API

You can also use JNA bindings directly:

import com.github.winterreisender.webviewko.*
import com.github.winterreisender.webviewko.WebviewJNA.WebviewLibrary
import com.sun.jna.Pointer
import java.beans.JavaBean

with(WebviewJNA.getLib()) {
    val pWebview = webview_create(1, Pointer.NULL)
    webview_set_title(pWebview, "Hello")
    webview_set_size(pWebview, 800, 600, WebviewJNA.WEBVIEW_HINT_NONE)
    webview_navigate(pWebview, "https://example.com")
    webview_run(pWebview)
    webview_destroy(pWebview)
}

or in Java:

WebviewJNA.WebviewLibrary lib = WebviewJNA.Companion.getLib();
Pointer pWebview = lib.webview_create(1, Pointer.NULL);
lib.webview_set_title(pWebview, "Hello");
lib.webview_set_size(pWebview, 800, 600, WebviewJNA.WEBVIEW_HINT_NONE);
lib.webview_navigate(pWebview, "https://example.com");
lib.webview_run(pWebview);
lib.webview_destroy(pWebview);

More examples like binding a Kotlin/Java callback or running in a thread: see TestKt.kt and TestJava.java

Kotlin/Native Bindings

There’s an experimental and under developing Kotlin/Native binding in experimental

Documentation

See docs for the full document

Contribution

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

Credits

Project License
wiverson/webviewjar MIT
webview_csharp MIT
webview MIT
JNA LGPL-2.1-or-later OR Apache-2.0
Microsoft Webview2 See the License
Kotlin & kotlinx Apache-2.0

License

Copyright 2022 Winterreisender

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.

SPDX short identifier: Apache-2.0

OSI Approved

GitHub

View Github