webview-sdk:仓颉语言WebView开发工具包,实现本地UI与JS交互

仓颉语言绑定webview; 可以使用任何 web 技术开发你的桌面程序。

Branch1Tags0
FilesLast commitLast update
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago

TIP

测试和验证 webview 的使用

当前仓颉不支持静态编译,需要手动把 webview 依赖放进系统

示例

https://gitcode.com/service/webview-sdk/tree/main/test

package test

import webview_sdk.*
import encoding.json.*
import std.collection.*

main(): Int64 {
    let w = webview("仓颉 webview 例子", 630, 500, true)

    // 本地 WEB UI, 目录使用了 cdn 资源,可能会白屏一下
    w.setResources("./resources/")

    // 绑定一个函数,用于保存数据
    let list: ArrayList<JsonValue> = ArrayList<JsonValue>()
    w.bind("save", { request =>
        let jsName = request.getArgString(0)
        let jsLastname = request.getArgString(1)

        var map = JsonObject()
        map.put("name", JsonString(jsName))
        map.put("lastname", JsonString(jsLastname))
        list.append(map)
        var result: JsonValue = JsonArray(list)
        Result(result)
    })

    w.bind("getList", { request =>
        var result: JsonValue = JsonArray(list)
        Result(result)
    })

    // 加载远程页面
    // w.setUrl("https://www.bilibili.com/")

    w.run()
    w.destroy()

    return 0
}

Mac 安装依赖

cp library/libwebview.dylib /usr/local/lib/

Windows 安装依赖

复制 library/webview.dll 到 C:\Windows\System32;

运行

WIN 打包时自己加去黑窗参数 -subsystem windows

link-option = "-subsystem windows"


cjpm run

TODO

  • 仓颉和 JS 互相调用
  • 仓颉绑定 js 运行

Introduction

仓颉语言绑定webview; 可以使用任何 web 技术开发你的桌面程序。

Customize your domain