XU XUv0.16.0

#ui/webview

导入方式: #ui/webview

公开 API: 42 函数, 17 方法, 2 类型, 0 常量, 0 方法集

按窗口挂载网页;bind_ipc_requests_www 派发带文档身份的 InvokeRequest。__XU__.invoke 支持 Promise.id / cancel、timeoutMs 与 AbortSignal。请求 / 结果上限 1 MiB,最多 64 个活跃派发额度,共享 8 MiB;取消不强制中断用户代码。eval_async、find_async 与 cookie 异步接口通过 ui.EV_REQUEST 完成,结果最多 64 KiB。

使用指南与生命周期

正式版示例(完整工程与源码下载):webview_requests

示例代码 · API 声明

示例代码

以下源码来自官方 examples 仓库,可复制或下载。请在完整工程中使用本地 Xu SDK 运行;网络、数据库和桌面示例需要对应的服务或资源。

16_ui_webview/webview_requests/main.xu

所需 SDK:Xu 0.10.11 · 完整工程 · 下载源码

Xu本地 SDK 示例
@main
#ui
#ui/webview
fn route(request webview.InvokeRequest) string {
    if request.name == "slow" { sleep_ns(300000000) }
    if request.name == "wait" { sleep_ns(1500000000) }
    if request.name == "native" {
        target := ui.CanvasEvent{window_id: request.window_id,canvas_id: request.window_id,generation: request.generation}
        options := ui.RequestOptions{timeout_ms: 2000}
        script := "document.title"
        result := ui.webview_request_wait(&target,ui.REQUEST_WEBVIEW_EVAL,&script,&options) >>> (err) { << "failed: " + err.msg() }
        if result.status != ui.REQUEST_COMPLETED { << "status: " + str(result.status) }
        << result.value + ""
    }
    << request.payload + ""
}
fn ipc(emit_ch chan string,ech chan ui.Event) {
    webview.bind_ipc_requests_www(":mem:",route,emit_ch,ech) >>> (err) { eprintln(err.msg())
        << }
}
fn events(ech chan ui.Event,emit_ch chan string) {
    while true { event := <-ech
        if event.kind == ui.EV_EXIT { emit_ch <- ""
            << }
        if event.kind == ui.EV_CLOSED { println("Window closed; pending document requests revoked") }
    }
}
fn run() int {
    ech := chan ui.Event{cap: 1024}
    emit_ch := chan string{cap: 64}
    $app := ui.new_app_events(ech)
    webview.stage_www_root(":mem:") >>>
    xu ipc(emit_ch,ech)
    xu events(ech,emit_ch)
    $window := app.new_window(ui.WindowOpts{title: "Xu UI / WebView Request Lifecycle",width: 880,height: 640})
    $browser := webview.attach($&window)
    browser.load_url(webview.app_scheme_url()) >>>
    << app.run() >>>
}
fn main() int { << run() >>> (err) { eprintln(err.msg())
    << 1 } }
16_ui_webview/shaped_webview/main.xu

所需 SDK:Xu 0.10.11 · 完整工程 · 下载源码

Xu本地 SDK 示例
@main

#ui
#ui/webview

// Frameless + PNG mask + WKWebView (macOS).
//   xu build examples/16ui_webview/shaped_webview --target macos-arm64 --desktop -o /tmp/xu_shaped_wv
//   /tmp/xu_shaped_wv
// Drag from the top ~28px strip; Close calls shell.quit.

fn route(name string, payload string) string {
    if name == "ping" {
        << "pong:" + payload
    }
    if name == "greet" {
        << "hello, " + payload
    }
    if name == "win" {
        if payload == "quit" {
            q := ui.native_quit() >>> (err) { << "err" }
            << "quit"
        }
        if payload == "minimize" {
            m := ui.native_minimize() >>> (err) { << "err" }
            << "minimized"
        }
        << "win?"
    }
    << "miss"
}

fn demo_www() string {
    << "www"
}

fn ipc_boot(emit_ch chan string, shell_ch chan ui.Event) {
    webview.bind_ipc_www(demo_www(), route, emit_ch, shell_ch) >>> (err) {
        eprintln(err.msg())
        <<
    }
}

fn main() int {
    emit_ch := chan string{cap: 32}
    shell_ch := chan ui.Event{cap: 32}
    $app := ui.new_app_events(shell_ch)
    app.set_icon(ui.icon_from_file("brand/xu_app_logo.png"))
    webview.stage_www_root(demo_www()) >>> (err) {
        println(err.msg())
        << 1
    }
    xu ipc_boot(emit_ch, shell_ch)
    sleep_ns(50000000)

    $win := app.new_window(ui.WindowOpts{title: "Xu Shaped WebView", width: 360, height: 360})
    r := $&win
    $wv := webview.attach(r)
    wv.on("ping")
    wv.on("greet")
    wv.on("win")

    a0 := ui.native_set_frameless(1)
    a1 := ui.native_set_transparent(1)
    a2 := ui.native_set_window_mask("brand/xu_app_logo.png") >>> (err) {
        println(err.msg())
        << 1
    }
    a3 := ui.native_set_shadow(1)
    if a0 + a1 + a2 + a3 < 0 {
        << 1
    }

    wv.load_url("xu://app/shaped.html") >>> (err) {
        println(err.msg())
        << 1
    }
    println("shaped webview — xu://app/shaped.html XUN IPC (drag top; Close quits)")
    app.run() >>> (err) {
        println(err.msg())
        << 1
    }
    << 0
}
16_ui_webview/remote/main.xu

所需 SDK:Xu 0.10.11 · 完整工程 · 下载源码

Xu本地 SDK 示例
@main

#ui
#ui/webview

// Remote HTTP document + xu:// IPC.
// 1) python3 examples/16ui_webview/remote_http/serve.py
// 2) xu build examples/16ui_webview/remote --target macos-arm64 --desktop -o /tmp/xu_remote
// 3) /tmp/xu_remote
// Optional: XU_UI_REMOTE_URL=http://127.0.0.1:8765/

fn route(name string, payload string) string {
    if name == "ping" {
        << "pong:" + payload
    }
    if name == "greet" {
        << "hello, " + payload
    }
    << "unknown:" + name
}

fn demo_www() string {
    << "www"
}

fn remote_url() string {
    u := env_get("XU_UI_REMOTE_URL")
    if u.len > 0 {
        << u + ""
    }
    << "http://127.0.0.1:8765/"
}

fn ipc_boot(emit_ch chan string, shell_ch chan ui.Event) {
    // Still stage www + bridge so xu://app/__xu works; main document is remote.
    webview.bind_ipc_www(demo_www(), route, emit_ch, shell_ch) >>> (err) {
        eprintln(err.msg())
        <<
    }
}

fn tick_loop(emit_ch chan string) {
    $n := 0
    while true {
        sleep_ns(3000000000)
        n = n + 1
        webview.bus_emit(emit_ch, "tick", str(n))
    }
}

fn watch_shell(shell_ch chan ui.Event) {
    while true {
        ev := <-shell_ch
        if ev.kind == ui.EV_EXIT || ev.kind == ui.EV_CLOSED {
            println("shell event kind=" + str(ev.kind))
        } else if ev.kind == ui.EV_LOADED {
            println("shell event loaded")
        } else if ev.kind == ui.EV_LOAD_FAILED {
            println("shell event load_failed")
        } else if ev.kind == ui.EV_READY {
            println("shell event ready")
        }
    }
}

fn main() int {
    emit_ch := chan string{cap: 32}
    shell_ch := chan ui.Event{cap: 32}
    $app := ui.new_app_events(shell_ch)
    app.set_icon(ui.icon_from_file("brand/xu_app_logo.png"))
    url := remote_url()
    xu watch_shell(shell_ch)
    xu ipc_boot(emit_ch, shell_ch)
    xu tick_loop(emit_ch)
    sleep_ns(50000000)
    $win := app.new_window(ui.WindowOpts{title: "Xu Remote HTTP + xu:// IPC", width: 720, height: 520})
    r := $&win
    $wv := webview.attach(r)
    wv.on("ping")
    wv.on("greet")
    url2 := url + ""
    wv.load_remote(url2) >>> (err) {
        println(err.msg())
        << 1
    }
    println("remote document " + url + " — IPC via xu://app/__xu (start remote_http/serve.py first)")
    app.run() >>> (err) {
        println(err.msg())
        << 1
    }
    << 0
}
更多相关示例
  • 16_ui_webview/open/main.xu

    所需 SDK:Xu 0.10.11 · 完整工程 · 下载源码

    Xu本地 SDK 示例
    @main
    
    #ui
    #ui/webview
    
    fn route(name string, payload string) string {
        if name == "ping" {
            << "pong:" + payload
        }
        if name == "greet" {
            << "hello, " + payload
        }
        if name == "menu" {
            << "menu:" + payload
        }
        if name == "tray" {
            << "tray:" + payload
        }
        if name == "shell" {
            << "shell:" + payload
        }
        if name == "win" {
            if payload == "hide" {
                _ := ui.native_hide() >>> (err) { << "err" }
                << "hidden"
            }
            if payload == "show" {
                _ := ui.native_show() >>> (err) { << "err" }
                << "shown"
            }
            if payload == "minimize" {
                _ := ui.native_minimize() >>> (err) { << "err" }
                << "minimized"
            }
            if payload == "reload" {
                _ := webview.native_reload() >>> (err) { << "err" }
                << "reloaded"
            }
            if payload == "float" {
                _ := ui.native_set_floating(1) >>> (err) { << "err" }
                << "floating"
            }
            if payload == "unfloat" {
                _ := ui.native_set_floating(0) >>> (err) { << "err" }
                << "unfloated"
            }
            if payload == "fullscreen" {
                _ := ui.native_set_fullscreen(1) >>> (err) { << "err" }
                << "fullscreen"
            }
            if payload == "unfullscreen" {
                _ := ui.native_set_fullscreen(0) >>> (err) { << "err" }
                << "unfullscreen"
            }
            if payload == "center" {
                _ := ui.native_center() >>> (err) { << "err" }
                << "centered"
            }
            if payload == "devtools" {
                _ := webview.native_open_devtools() >>> (err) { << "err" }
                << "devtools"
            }
            if payload == "zoom_in" {
                _ := webview.native_set_zoom(125) >>> (err) { << "err" }
                << "zoom 125%"
            }
            if payload == "zoom_out" {
                _ := webview.native_set_zoom(80) >>> (err) { << "err" }
                << "zoom 80%"
            }
            if payload == "zoom_100" {
                _ := webview.native_set_zoom(100) >>> (err) { << "err" }
                << "zoom 100%"
            }
            if payload == "open_ext" {
                _ := ui.native_open_external("https://example.com") >>> (err) { << "err" }
                << "opened browser"
            }
            if payload == "clip_set" {
                _ := ui.native_clipboard_set("hello from Xu") >>> (err) { << "err" }
                << "clipboard set"
            }
            if payload == "clip_get" {
                _ := ui.native_clipboard_get()
                << "clipboard:posted"
            }
            if payload == "back" {
                _ := webview.native_go_back() >>> (err) { << "err" }
                << "back"
            }
            if payload == "forward" {
                _ := webview.native_go_forward() >>> (err) { << "err" }
                << "forward"
            }
            if payload == "stop" {
                _ := webview.native_stop() >>> (err) { << "err" }
                << "stop"
            }
            if payload == "maximize" {
                _ := ui.native_set_maximized(1) >>> (err) { << "err" }
                << "maximized"
            }
            if payload == "unmaximize" {
                _ := ui.native_set_maximized(0) >>> (err) { << "err" }
                << "unmaximized"
            }
            if payload == "bounce" {
                _ := ui.native_bounce() >>> (err) { << "err" }
                << "bounce"
            }
            if payload == "pick" {
                _ := ui.native_pick_file()
                << "pick:posted"
            }
            if payload == "save" {
                _ := ui.native_save_file("xu-note.txt")
                << "save:posted"
            }
            if payload == "print" {
                _ := webview.native_print() >>> (err) { << "err" }
                << "print"
            }
            if payload == "opacity_low" {
                _ := ui.native_set_opacity(70) >>> (err) { << "err" }
                << "opacity 70%"
            }
            if payload == "opacity_full" {
                _ := ui.native_set_opacity(100) >>> (err) { << "err" }
                << "opacity 100%"
            }
            if payload == "shot" {
                _ := ui.native_screenshot()
                << "shot:posted"
            }
            if payload == "alert" {
                _ := ui.native_alert("Xu", "Hello from alert")
                << "alert:posted"
            }
            if payload == "confirm" {
                _ := ui.native_confirm("Xu", "Continue?")
                << "confirm:posted"
            }
            if payload == "notify" {
                _ := ui.native_notify("Xu", "Desktop notification")
                << "notified"
            }
            if payload == "folder" {
                _ := ui.native_pick_folder()
                << "folder:posted"
            }
            if payload == "minsize" {
                _ := ui.native_set_min_size(480, 320) >>> (err) { << "err" }
                << "minsize 480x320"
            }
            if payload == "lock_size" {
                _ := ui.native_set_resizable(0) >>> (err) { << "err" }
                << "not resizable"
            }
            if payload == "unlock_size" {
                _ := ui.native_set_resizable(1) >>> (err) { << "err" }
                << "resizable"
            }
            if payload == "eval_result" {
                r := webview.native_eval_result("1+2+3")
                << "eval:" + r
            }
            if payload == "find" {
                r := webview.native_find("WebView")
                << "find:" + str(r)
            }
            if payload == "find_clear" {
                _ := webview.native_find_clear()
                << "find cleared"
            }
            if payload == "bounds" {
                _ := ui.native_get_bounds()
                << "bounds:posted"
            }
            if payload == "ua" {
                _ := webview.native_set_user_agent("XuWebView/1.0")
                << "ua set"
            }
            if payload == "css" {
                _ := webview.native_inject_css("body{outline:3px solid #e11d48 !important}")
                << "css injected"
            }
            if payload == "titlebar_hide" {
                _ := ui.native_set_titlebar_visible(0)
                << "titlebar hidden"
            }
            if payload == "titlebar_show" {
                _ := ui.native_set_titlebar_visible(1)
                << "titlebar shown"
            }
            if payload == "guard_on" {
                _ := ui.native_set_close_guard(1)
                << "close guard on — try red close / Quit (dialog)"
            }
            if payload == "guard_off" {
                _ := ui.native_set_close_guard(0)
                << "close guard off"
            }
            if payload == "accept_close" {
                _ := ui.native_accept_close()
                << "accepting close"
            }
            if payload == "reject_close" {
                _ := ui.native_reject_close()
                << "close rejected"
            }
            if payload == "clear_cache" {
                _ := webview.native_clear_cache()
                << "clearing cache"
            }
            if payload == "state" {
                _ := ui.native_get_state()
                << "state:posted"
            }
            if payload == "all_spaces" {
                _ := ui.native_set_visible_on_all_spaces(1)
                << "all spaces on"
            }
            if payload == "mute" {
                _ := webview.native_set_muted(1)
                << "muted"
            }
            if payload == "unmute" {
                _ := webview.native_set_muted(0)
                << "unmuted"
            }
            if payload == "bg" {
                _ := webview.native_set_background("#dc2626")
                << "bg #dc2626"
            }
            if payload == "bg2" {
                _ := webview.native_set_background("#2563eb")
                << "bg #2563eb"
            }
            if payload == "reveal_shot" {
                _ := write_file(ui.host_tmp() + "/xu_ui_shot_follow.txt", "reveal") >>> (err) {
                    << "err"
                }
                _ := ui.native_screenshot()
                << "reveal_shot:posted"
            }
            if payload == "open_shot" {
                _ := write_file(ui.host_tmp() + "/xu_ui_shot_follow.txt", "open") >>> (err) {
                    << "err"
                }
                _ := ui.native_screenshot()
                << "open_shot:posted"
            }
            if payload == "dark" {
                _ := ui.native_set_appearance("dark")
                << "appearance dark"
            }
            if payload == "light" {
                _ := ui.native_set_appearance("light")
                << "appearance light"
            }
            if payload == "ctx_off" {
                _ := webview.native_set_context_menu(0)
                << "context menu off"
            }
            if payload == "ctx_on" {
                _ := webview.native_set_context_menu(1)
                << "context menu on"
            }
            if payload == "badge" {
                _ := ui.native_set_dock_badge("3")
                << "dock badge 3"
            }
            if payload == "badge_clear" {
                _ := ui.native_set_dock_badge("")
                << "dock badge cleared"
            }
            if payload == "shot_clip" {
                _ := ui.native_screenshot_to_clipboard()
                << "shot_clip:posted"
            }
            if payload == "shadow_off" {
                _ := ui.native_set_shadow(0)
                << "shadow off"
            }
            if payload == "shadow_on" {
                _ := ui.native_set_shadow(1)
                << "shadow on"
            }
            if payload == "magnify_off" {
                _ := webview.native_set_magnification(0)
                << "magnify off"
            }
            if payload == "magnify_on" {
                _ := webview.native_set_magnification(1)
                << "magnify on"
            }
            if payload == "cookie_set" {
                _ := webview.native_cookie_set("xu_demo", "1", "127.0.0.1")
                << "cookie set"
            }
            if payload == "cookies_get" {
                c := webview.native_cookies_get()
                << "cookies:\n" + c
            }
            if payload == "cookies_clear" {
                _ := webview.native_cookies_clear()
                << "cookies clearing"
            }
            << "win:" + payload
        }
        << "unknown:" + name
    }
    
    fn demo_www() string {
        // Pack oneexe: force in-PE www (never stage developer/... or TEMP/www).
        if env_get("XU_UI_WWW") == ":mem:" || env_get("XU_UI_PACK") == "1" {
            << ":mem:"
        }
        << "www"
    }
    
    fn pack_trace(step string) {
        // Pack has no xu_ui TMP dir; skip disk breadcrumbs (console / XU_UI_LOG still work).
        d := env_get("XU_UI_TMP")
        if d.len == 0 || d == ":xu:" {
            <<
        }
        _ := write_file(d + "/xu_main_trace.txt", step + "\n") >>> (err) {
            <<
        }
    }
    
    fn ipc_boot(emit_ch chan string, shell_ch chan ui.Event) {
        webview.bind_ipc_www(demo_www(), route, emit_ch, shell_ch) >>> (err) {
            eprintln(err.msg())
            <<
        }
    }
    
    fn tick_loop(emit_ch chan string) {
        $n := 0
        while true {
            // Short sleeps so a blocked/mis-scheduled task cannot sit on a 2s nanosleep
            // that starves sibling work if threading is ever wrong. Emit only — no
            // native_eval/title on this loop (those jam the AppKit main thread).
            sleep_ns(200000000)
            n = n + 1
            if n % 10 == 0 {
                webview.bus_emit(emit_ch, "tick", str(n / 10))
            }
        }
    }
    
    // Native app.run blocks main; shell events arrive on event_ch from #ui's host pump.
    fn watch_shell(shell_ch chan ui.Event, emit_ch chan string) {
        while true {
            ev := <-shell_ch
            if ev.kind == ui.EV_PROGRESS {
                ->
            }
            // Result-bearing shell ops → XUN emit (same post protocol as invoke).
            if ev.kind == ui.EV_CLIPBOARD {
                webview.bus_emit(emit_ch, "clipboard", ev.menu_id + "")
            } else if ev.kind == ui.EV_FILE_PICKED {
                webview.bus_emit(emit_ch, "file_picked", ev.menu_id + "")
            } else if ev.kind == ui.EV_FILE_SAVED {
                webview.bus_emit(emit_ch, "file_saved", ev.menu_id + "")
            } else if ev.kind == ui.EV_FOLDER_PICKED {
                webview.bus_emit(emit_ch, "folder_picked", ev.menu_id + "")
            } else if ev.kind == ui.EV_SCREENSHOT {
                p := ev.menu_id + ""
                webview.bus_emit(emit_ch, "screenshot", p + "")
                // reveal_shot / open_shot: follow-up after shell event (post protocol).
                follow := shot_follow_take()
                if follow == "reveal" && p.len > 0 {
                    _ := ui.native_reveal_path(p + "")
                } else if follow == "open" && p.len > 0 {
                    _ := ui.native_open_path(p + "")
                }
            } else if ev.kind == ui.EV_ALERT {
                webview.bus_emit(emit_ch, "alert", ev.menu_id + "")
            } else if ev.kind == ui.EV_CONFIRM {
                webview.bus_emit(emit_ch, "confirm", ev.menu_id + "")
            } else if ev.kind == ui.EV_BOUNDS {
                webview.bus_emit(emit_ch, "bounds", ev.menu_id + "")
            } else if ev.kind == ui.EV_STATE {
                webview.bus_emit(emit_ch, "state", ev.menu_id + "")
            } else if ev.kind == ui.EV_NOTIFY {
                webview.bus_emit(emit_ch, "notify", ev.menu_id + "")
            }
            if ev.kind == ui.EV_MENU_CLICKED {
                println("shell event menu_clicked id=" + ev.menu_id)
            } else if ev.kind == ui.EV_TRAY_MENU_CLICKED {
                println("shell event tray_menu_clicked id=" + ev.menu_id)
            } else if ev.kind == ui.EV_CLOSED {
                println("shell event closed")
            } else if ev.kind == ui.EV_EXIT {
                println("shell event exit")
            } else if ev.kind == ui.EV_CLOSE_REQUESTED {
                println("shell event close_requested")
            } else if ev.kind == ui.EV_FILE_PICKED {
                println("shell event file_picked " + ev.menu_id)
            } else if ev.kind == ui.EV_CLIPBOARD {
                println("shell event clipboard")
            } else if ev.kind == ui.EV_BOUNDS {
                println("shell event bounds " + ev.menu_id)
            } else if ev.kind == ui.EV_STATE {
                println("shell event state " + ev.menu_id)
            }
        }
    }
    
    fn shot_follow_take() string {
        path := ui.host_tmp() + "/xu_ui_shot_follow.txt"
        body := read_file(path) >>> (err) {
            << ""
        }
        _ := write_file(path, "") >>> (err) {
            << body
        }
        << body
    }
    
    fn soft_install_tray() int {
        $tray_items := []ui.MenuItem{}
        tray_items.push(ui.menu_item("show", "Show"))
        tray_items.push(ui.menu_item("hide", "Hide"))
        tray_items.push(ui.menu_item("quit", "Quit"))
        a := ui.install_tray("Xu", ui.menu(tray_items)) >>> (err) {
            pack_trace("install_tray soft-fail: " + err.msg())
            << 0
        }
        b := ui.install_tray_icon("brand/xu_app_logo.png") >>> (err) {
            pack_trace("install_tray_icon soft-fail: " + err.msg())
            << 0
        }
        << a + b
    }
    
    fn main() int {
        emit_ch := chan string{cap: 64}
        // Large cap: host floods progress/moved/focus during load; a full channel
        // blocks the IPC worker on `shell_ch <-` and delays invoke by ~1s.
        shell_ch := chan ui.Event{cap: 4096}
        $app := ui.new_app_events(shell_ch)
        pack_trace("main begin")
        app.set_icon(ui.icon_from_file("brand/xu_app_logo.png"))
        // Stage www before the window so host xu://app/ load is not empty.
        webview.stage_www_root(demo_www()) >>> (err) {
            pack_trace("stage_www_root fail: " + err.msg())
            println(err.msg())
            << 1
        }
        pack_trace("stage_www_root ok")
        xu watch_shell(shell_ch, emit_ch)
        xu ipc_boot(emit_ch, shell_ch)
        xu tick_loop(emit_ch)
        pack_trace("xu tasks spawned")
        sleep_ns(50000000)
        $win := app.new_window(ui.WindowOpts{title: "Xu WebView IPC", width: 800, height: 560})
        $menu_items := []ui.MenuItem{}
        menu_items.push(ui.menu_item("about", "About"))
        menu_items.push(ui.menu_item("quit", "Quit"))
        win.set_menu(ui.menu(menu_items))
        soft_install_tray()
        app.new_tray(ui.TrayOpts{tip: "Xu", icon: ui.icon_default(), menu: ui.menu([]ui.MenuItem{})})
        r := $&win
        $wv := webview.attach(r)
        pack_trace("webview.attach ok")
        wv.on("ping")
        wv.on("greet")
        wv.load_url(webview.app_scheme_url()) >>> (err) {
            pack_trace("load_url fail: " + err.msg())
            println(err.msg())
            << 1
        }
        pack_trace("before app.run")
        println("shell events on App.event_ch / xu://app/ (XUN IPC)")
        app.run() >>> (err) {
            pack_trace("app.run fail: " + err.msg())
            println(err.msg())
            << 1
        }
        pack_trace("window closed")
        println("window closed")
        << 0
    }
  • 16_ui_webview/webview_component/main.xu

    所需 SDK:Xu 0.10.13-dev.1 · 完整工程 · 下载源码 · events.xu

    Xu本地 SDK 示例
    @main
    #ui
    #ui/widgets
    #ui/webview
    #math
    demo #"github.com/xulang-org/examples/ui_demo"
    
    fn document(title string, tone string) string {
        << "<!doctype html><html><head><meta charset='utf-8'><title>" + title + "</title><style>body{margin:0;padding:28px;font:15px -apple-system,system-ui;color:#252521;background:#faf9f6}small{letter-spacing:.14em;color:#797970}h1{font-size:28px;font-weight:600;letter-spacing:-.04em;margin:16px 0}p{line-height:1.65;color:#6b6b63}input,button{box-sizing:border-box;font:inherit;border-radius:8px;padding:12px;width:100%;margin:8px 0}input{border:1px solid #d8d8cf;background:white;outline-color:" + tone + "}button{border:0;background:" + tone + ";color:white;cursor:pointer}output{display:block;min-height:42px;padding:12px 0;line-height:1.5;color:" + tone + "}</style></head><body><small>EMBEDDED WEBVIEW</small><h1>" + title + "</h1><p>This document has its own viewport, focus and request identity.</p><input aria-label='Message' value='Hello from " + title + "'><button onclick='send()'>Ask native Xu</button><output aria-live='polite'>Ready for an independent native request.</output><p>Tab moves inside this document.<br>Ctrl + Tab returns to the native controls.</p><script>async function send(){let out=document.querySelector('output');out.textContent='Waiting…';try{out.textContent=await window.__XU__.invoke('echo',document.querySelector('input').value)}catch(e){out.textContent=e.message}}</script></body></html>"
    }
    fn route(request webview.InvokeRequest) string {
        target := request.target() >>> (err) { << "Target closed: " + err.msg()}
        script := "document.title"
        options := ui.RequestOptions{timeout_ms: 3000}
        result := ui.webview_request_wait(&target, ui.REQUEST_WEBVIEW_EVAL, &script, &options) >>> (err) { << err.msg()}
        << result.value + " · " + request.payload + " · view " + str(target.canvas_id)
    }
    fn ipc(events chan ui.Event, emits chan string) {
        webview.bind_ipc_requests_www(":mem:", route, emits, events) >>> (err) {eprintln(err.msg())
            << }
    }
    fn scene(events chan ui.Event) int {
        ready := demo.ready(events) >>>
        if ready.kind == ui.EV_EXIT{ << 0}
        $screen := widgets.screen(&ready) >>>
        screen.resize(1020.0, 720.0) >>>
        screen.set_min_size(760, 580) >>>
        title := screen.label("Web content. Native composition.", 26.0, false) >>>
        subtitle := screen.label("Two independent WebViews inside a Canvas window", 13.0, true) >>>
        hide := screen.button("Hide left") >>>
        reload := screen.button("Reload right") >>>
        close := screen.button("Dispose left") >>>
        modal_button := screen.button("Open modal") >>>
        left := screen.webview() >>>
        right := screen.webview() >>>
        status := screen.label("Resize the window, edit both pages, or test their native requests.", 13.0, true) >>>
        modal := screen.modal("Native overlay", "The WebViews resume when this dialog closes.") >>>
        dismiss := screen.button("Close dialog") >>>
        screen.set_parent(dismiss, modal) >>>
        screen.place(dismiss, 24.0, 175.0, 180.0, 38.0) >>>
        screen.load_web_html(left, document("Editor preview", "#b64c3c")) >>>
        screen.load_web_html(right, document("Reference panel", "#386f6b")) >>>
        $model := Model{left: left, right: right, hide: hide, close: close, status: status, modal: modal, hidden: false, disposed: false}
        $dispatcher := widgets.action_dispatcher(&model, &screen)
        dispatcher.on(hide, widgets.ACTION_ACTIVATE, toggle_left) >>>
        dispatcher.on(reload, widgets.ACTION_ACTIVATE, reload_right) >>>
        dispatcher.on(close, widgets.ACTION_ACTIVATE, dispose_left) >>>
        dispatcher.on(modal_button, widgets.ACTION_ACTIVATE, open_modal) >>>
        dispatcher.on(dismiss, widgets.ACTION_ACTIVATE, close_modal) >>>
        for id in[left, right] {
            dispatcher.on(id, widgets.ACTION_WEB_LOADED, web_loaded) >>>
            dispatcher.on(id, widgets.ACTION_WEB_FAILED, web_failed) >>>
        }
        while screen.is_open() {
            width := screen.width()
            height := screen.height()
            half :=(width - 76.0) * 0.5
            screen.place(title, 28.0, 25.0, width - 56.0, 38.0) >>>
            screen.place(subtitle, 28.0, 69.0, width - 56.0, 25.0) >>>
            screen.place(hide, 28.0, 112.0, 136.0, 38.0) >>>
            screen.place(reload, 174.0, 112.0, 146.0, 38.0) >>>
            screen.place(close, 330.0, 112.0, 136.0, 38.0) >>>
            screen.place(modal_button, 476.0, 112.0, 136.0, 38.0) >>>
            screen.place(left, 28.0, 174.0, half, math.max(300.0, height - 245.0)) >>>
            screen.place(right, 48.0 + half, 174.0, half, math.max(300.0, height - 245.0)) >>>
            screen.place(status, 28.0, height - 49.0, width - 56.0, 28.0) >>>
            _ := screen.render() >>>
            for action in screen.next(events) >>> {
                _ := dispatcher.dispatch(&action, $&model, $&screen) >>>
            }
        }
        screen.dispose()
        << 0
    }
    fn worker(events chan ui.Event) {scene(events) >>> (err) {demo.fail(err.msg())
            << }}
    fn launch() int {
        $app := demo.app("XUUI / WebView Components", 1020, 720) >>>
        _ := ui.register_content_plugin(ui.content_plugin_webview())
        emits := chan string {cap: 64}
        xu ipc(app.event_ch, emits)
        xu worker(app.event_ch)
        << app.run() >>>
    }
    fn main() int { << launch() >>> (err) {eprintln(err.msg())
            << 1}}
  • 16_ui_webview/component_workshop/main.xu

    所需 SDK:Xu 0.10.13-dev.3 · 完整工程 · 下载源码 · events.xu · events_tools.xu · layout.xu · model.xu · style.xu · view.xu

    Xumain.xu
    @main
    
    #ui
    #ui/widgets
    #time
    demo #"github.com/xulang-org/examples/ui_demo"
    
    fn scene(events chan ui.Event) int {
        ready := demo.ready(events) >>>
        if ready.kind == ui.EV_EXIT{ << 0}
        $screen := widgets.screen(&ready) >>>
        screen.resize(1180.0, 900.0) >>> (err) {screen.dispose()
            >> err}
        screen.set_min_size(920, 780) >>> (err) {screen.dispose()
            >> err}
        $model := create($&screen) >>> (err) {screen.dispose()
            >> err}
        workshop_loop(events, $&model, $&screen) >>> (err) {screen.dispose()
            >> err}
        screen.dispose()
        << 0
    }
    
    fn worker(events chan ui.Event) {scene(events) >>> (err) {demo.fail(err.msg())
            << }}
    
    fn launch() int {
        $app := demo.app("XUUI / Component Workshop", 1180, 900) >>>
        xu worker(app.event_ch)
        << app.run() >>>
    }
    
    fn main() int { << launch() >>> (err) {eprintln(err.msg())
            << 1}}
    
    fn next_event(events chan ui.Event, deadline time.Instant) ui.Event{
        if deadline.is_zero() { << <- events}
        delay := deadline.since(time.instant())
        if delay.nanoseconds() <= 0 { << ui.Event{kind: ui.EV_NONE, window_id: 0, menu_id: "", width: 0, height: 0}}
        timer := delay.timer()
        select {event := <- events{timer.stop()
                << event}
            _ := <- timer.c{timer.stop()}}
        << ui.Event{kind: ui.EV_NONE, window_id: 0, menu_id: "", width: 0, height: 0}
    }
    
    fn workshop_loop(events chan ui.Event, model $&Workshop, screen $&widgets.Screen) int {
        model.apply_locale(screen) >>>
        screen.set_text(model.title, "XUUI  /  Field") >>>
        model.configure_controls(screen) >>>
        model.controls_dirty = false
        model.apply_appearance(screen) >>>
        model.appearance_dirty = false
        $dispatcher := register_events(& * model, & * screen) >>>
        model.layout(screen) >>>
        while screen.is_open() {
            register_notice_events(& * screen, $&dispatcher) >>>
            now := time.instant()
            model.work(screen, now) >>>
            if model.controls_dirty{model.configure_controls(screen) >>>
                model.controls_dirty = false}
            if model.appearance_dirty{model.apply_appearance(screen) >>>
                model.appearance_dirty = false}
            model.apply_page_options(screen) >>>
            model.layout(screen) >>>
            $deadline := screen.advance(now) >>>
            $timed_actions := false
            for action in screen.take_actions() {
                _ := dispatcher.dispatch_or_fallback(&action, model, screen) >>>
                timed_actions = true
            }
            // Reconcile timer-driven values/styles before computing the next wait.
            if timed_actions{ -> }
            _ := screen.render() >>>
            if model.running &&(deadline.is_zero() || model.deadline.before(deadline)) {deadline = model.deadline}
            event := next_event(events, deadline) >>>
            $actions := screen.event(&event) >>>
            $count := 0
            while screen.is_open() && count < 128 {pending := ui.poll_chan(events)
                if pending.kind == ui.EV_NONE{ <- }
                more := screen.event(&pending) >>>
                for action in more{actions.push(action)}
                count += 1}
            for action in actions{register_notice_events(& * screen, $&dispatcher) >>>
                _ := dispatcher.dispatch_or_fallback(&action, model, screen) >>> }
        }
        << 0
    }
    Xuevents_tools.xu
    @main
    
    #ui/widgets
    #ui/webview
    #time
    #math
    #errors
    #strconv
    
    fn tool_0_update(m $&Workshop, s $&widgets.Screen, option int) int {
        page := m.page_snapshot(0)
        id := page.ids[0]
        $text := "精密 · 清晰 · 可靠。"
        if option == 0 {text = "长中文:输入、选择、复制与原生排版保持一致。Long English text wraps inside its content width. Family 👨‍👩‍👧‍👦 and developer 👩🏽‍💻 remain intact."}
        s.set_text(id, text) >>>
        << 0
    }
    
    fn tool_1_update(m $&Workshop, s $&widgets.Screen, option int) int {
        page := m.page_snapshot(1)
        id := page.ids[0]
        s.set_selected_button(id, option == 0) >>>
        << 0
    }
    
    fn tool_2_update(m $&Workshop, s $&widgets.Screen, option int) int {
        page := m.page_snapshot(2)
        id := page.ids[0]
        s.set_selected_button(id, option == 0) >>>
        << 0
    }
    
    fn tool_3_update(m $&Workshop, s $&widgets.Screen, option int) int {
        index := 3
        page := m.page_snapshot(3)
        id := page.ids[0]
        if option == 0 {s.set_value(id, "") >>> }
        if option == 1 {$value := "Long text · 很长的中文与 English · 👩🏽‍💻 🙂 abcdefghijklmnopqrstuvwxyz"
            if index == 4 || index == 6 {value = value + "\n第二行\n第三行\n第四行\n第五行\n第六行\n第七行:内部滚动"}
            s.set_value(id, value) >>> }
        << 0
    }
    
    fn tool_4_update(m $&Workshop, s $&widgets.Screen, option int) int {
        index := 4
        page := m.page_snapshot(4)
        id := page.ids[0]
        if option == 0 {s.set_value(id, "") >>> }
        if option == 1 {$value := "Long text · 很长的中文与 English · 👩🏽‍💻 🙂 abcdefghijklmnopqrstuvwxyz"
            if index == 4 || index == 6 {value = value + "\n第二行\n第三行\n第四行\n第五行\n第六行\n第七行:内部滚动"}
            s.set_value(id, value) >>> }
        << 0
    }
    
    fn tool_5_update(m $&Workshop, s $&widgets.Screen, option int) int {
        index := 5
        page := m.page_snapshot(5)
        id := page.ids[0]
        if option == 0 {s.set_value(id, "") >>> }
        if option == 1 {$value := "Long text · 很长的中文与 English · 👩🏽‍💻 🙂 abcdefghijklmnopqrstuvwxyz"
            if index == 4 || index == 6 {value = value + "\n第二行\n第三行\n第四行\n第五行\n第六行\n第七行:内部滚动"}
            s.set_value(id, value) >>> }
        if option == 2 && index >= 5 {m.field_options_dirty = true
            m.field_options_page = index
            m.variant += 1}
        << 0
    }
    
    fn tool_6_update(m $&Workshop, s $&widgets.Screen, option int) int {
        index := 6
        page := m.page_snapshot(6)
        id := page.ids[0]
        if option == 0 {s.set_value(id, "") >>> }
        if option == 1 {$value := "Long text · 很长的中文与 English · 👩🏽‍💻 🙂 abcdefghijklmnopqrstuvwxyz"
            if index == 4 || index == 6 {value = value + "\n第二行\n第三行\n第四行\n第五行\n第六行\n第七行:内部滚动"}
            s.set_value(id, value) >>> }
        if option == 2 && index >= 5 {m.field_options_dirty = true
            m.field_options_page = index
            m.variant += 1}
        << 0
    }
    
    fn tool_7_update(m $&Workshop, s $&widgets.Screen, option int) int {
        page := m.page_snapshot(7)
        id := page.ids[0]
        if option == 0 {m.guided = !m.guided
            m.tree_options_dirty = true}
        if option == 1 {s.set_selected(id, 7) >>>
            s.focus(id) >>> }
        if option == 2 {s.set_value(page.ids[1], "") >>>
            s.set_tree_filter(id, "") >>> }
        << 0
    }
    
    fn tool_8_update(m $&Workshop, s $&widgets.Screen, option int) int {
        page := m.page_snapshot(8)
        id := page.ids[0]
        if option == 0 {m.variant += 1
            s.set_task_progress_mode(id, m.variant % 3) >>> }
        if option == 1 {m.failure = !m.failure
            s.set_selected_button(m.tools[1], m.failure) >>> }
        if option == 2 && m.running{_ := s.complete_task(id, m.revision, widgets.TASK_CANCELLED) >>>
            m.running = false}
        << 0
    }
    
    fn tool_9_update(m $&Workshop, s $&widgets.Screen, option int) int {
        page := m.page_snapshot(9)
        id := page.ids[0]
        s.set_checkbox_indeterminate(id, option == 0) >>>
        if option > 0 {s.set_toggle_value(id, option == 1) >>> }
        << 0
    }
    
    fn tool_10_update(m $&Workshop, s $&widgets.Screen, option int) int {
        page := m.page_snapshot(10)
        id := page.ids[0]
        if option == 0 {m.pending_before = s.toggle_value(id) >>>
            s.set_switch_pending(id, true) >>>
            s.set_text(id, "Live preview · Saving…") >>> }
        else {s.set_switch_pending(id, false) >>>
            s.set_toggle_value(id, option == 1 || m.pending_before) >>>
            s.set_invalid(id, option == 2) >>>
            s.set_text(id, "Live preview 实时预览") >>> }
        << 0
    }
    
    fn tool_11_update(m $&Workshop, s $&widgets.Screen, option int) int {
        page := m.page_snapshot(11)
        id := page.ids[0]
        s.set_toggle_value(id, option == 0) >>>
        << 0
    }
    
    fn tool_13_update(m $&Workshop, s $&widgets.Screen, option int) int {
        page := m.page_snapshot(13)
        id := page.ids[0]
        if option > 0 {s.set_slider_commit_only(id, option == 1) >>> }
        else {text := s.text_value(page.ids[1]) >>>
            value := strconv.parse_float(&text) >>> (err) {s.set_field_invalid(page.ids[1], true) >>>
                << 0}
            if math.is_nan(value) || math.is_inf(value) || value < 0.0 || value > 100.0 {s.set_field_invalid(page.ids[1], true) >>>
                << 0}
            s.set_number_value(id, value) >>>
            s.set_field_invalid(page.ids[1], false) >>> }
        << 0
    }
    
    fn tool_15_update(m $&Workshop, s $&widgets.Screen, option int) int {
        page := m.page_snapshot(15)
        id := page.ids[0]
        if option == 0 {s.set_candidate_open(id, true) >>> }
        else {s.set_select_option_enabled(id, 2, false) >>> }
        << 0
    }
    
    fn tool_16_update(m $&Workshop, s $&widgets.Screen, option int) int {
        page := m.page_snapshot(16)
        id := page.ids[0]
        if option < 2 {s.set_combo_custom_values(id, option == 0) >>> }
        else {s.set_value(id, "") >>> }
        << 0
    }
    
    fn tool_17_update(m $&Workshop, s $&widgets.Screen, option int) int {
        page := m.page_snapshot(17)
        id := page.ids[0]
        s.select_all(id, option == 0) >>>
        << 0
    }
    
    fn tool_18_update(m $&Workshop, s $&widgets.Screen, option int) int {
        page := m.page_snapshot(18)
        id := page.ids[0]
        if option == 0 {s.clear_calendar(id) >>> }
        else {value := time.date(2026, 10, 25, 0, 0, 0, 0)
            s.set_calendar_value(id, value) >>> }
        << 0
    }
    
    fn tool_19_update(m $&Workshop, s $&widgets.Screen, option int) int {
        page := m.page_snapshot(19)
        id := page.ids[0]
        s.set_clock_format(id, option == 0, option != 2) >>>
        << 0
    }
    
    fn tool_20_update(m $&Workshop, s $&widgets.Screen, option int) int {
        page := m.page_snapshot(20)
        id := page.ids[0]
        $value := "#B4392DFF"
        if option == 0 {value = s.text_value(page.ids[1]) >>> }
        if option == 2 {value = "#3279A080"}
        s.set_color_hex(id, value) >>> (err) {s.set_field_invalid(page.ids[1], true) >>>
            s.set_text(m.status, err.msg()) >>>
            << 0}
        s.set_field_invalid(page.ids[1], false) >>>
        s.remember_color(id) >>>
        s.set_value(page.ids[1], s.color_hex(id) >>>) >>>
        << 0
    }
    
    fn tool_24_update(m $&Workshop, s $&widgets.Screen, option int) int {
        page := m.page_snapshot(24)
        id := page.ids[0]
        s.set_table_status(id,["", "Loading workspace… 正在加载", "Unable to load. Retry when ready."][option]) >>>
        << 0
    }
    
    fn tool_25_update(m $&Workshop, s $&widgets.Screen, option int) int {
        page := m.page_snapshot(25)
        id := page.ids[0]
        sizes :=[10, 20, 50, 100]
        size := sizes[s.selected(page.ids[2]) >>>]
        data := s.pagination_data(id) >>>
        if option == 2 {if data.total == 0 {s.set_pagination_data(id, 20000, size) >>> }
            else {s.set_pagination_data(id, 0, size) >>> }}
        else {
            if data.pages == 0 {m.pagination_invalid(s) >>>
                << 0}
            current := s.pagination_data(id) >>>
            $number := current.pages
            if option == 0 {text := s.text_value(page.ids[1]) >>>
                number = strconv.atoi(&text) >>> (err) {m.pagination_invalid(s) >>>
                    << 0}
                if number < 1 || number > current.pages{m.pagination_invalid(s) >>>
                    << 0}}
            s.set_selected(id, number - 1) >>>
            s.set_field_invalid(page.ids[1], false) >>>
        }
        m.update_pagination(s, true) >>>
        << 0
    }
    
    fn tool_27_update(m $&Workshop, s $&widgets.Screen, option int) int {
        page := m.page_snapshot(27)
        id := page.ids[0]
        s.set_number_value(id,[0.0, 0.42, 1.0][option]) >>>
        << 0
    }
    
    fn tool_28_update(m $&Workshop, s $&widgets.Screen, option int) int {
        page := m.page_snapshot(28)
        id := page.ids[0]
        if option < 2 {s.set_running(id, option == 0) >>> }
        else {m.spinner_options_dirty = true}
        << 0
    }
    
    fn tool_30_update(m $&Workshop, s $&widgets.Screen, option int) int {
        page := m.page_snapshot(30)
        id := page.ids[0]
        if option == 0 {m.unread += 1}
        if option == 1 {m.unread = 0}
        if option == 2 {m.unread = 123}
        m.update_badges(s) >>>
        << 0
    }
    
    fn tool_32_update(m $&Workshop, s $&widgets.Screen, option int) int {
        page := m.page_snapshot(32)
        id := page.ids[0]
        if option == 0 {s.set_scroll_offset(id, 0.0) >>> }
        if option == 1 {s.set_scroll_offset(id, 100000.0) >>> }
        if option == 2 {s.focus(page.ids[page.ids.len - 1]) >>> }
        << 0
    }
    
    fn tool_33_update(m $&Workshop, s $&widgets.Screen, option int) int {
        index := 33
        page := m.page_snapshot(33)
        id := page.ids[0]
        if option == 2 {m.variant =(m.variant + 1) % 4
            m.popover_options_dirty = true}
        if option == 0 {if index == 33 {m.open_preferences(s) >>> } else {s.open(page.ids[1]) >>> }}
        else if option == 1 {s.close_overlay(page.ids[1]) >>> }
        << 0
    }
    
    fn tool_34_update(m $&Workshop, s $&widgets.Screen, option int) int {
        page := m.page_snapshot(34)
        id := page.ids[0]
        if option == 2 {m.tooltip_side =(m.tooltip_side + 1) % 4
            m.appearance_dirty = true
            s.focus(id) >>>
            s.set_text(m.status, "Tooltip · " +["Bottom 下", "Top 上", "Left 左", "Right 右"][m.tooltip_side] + " · flips at the viewport edge") >>> }
        if option == 0 {s.focus(id) >>> }
        else if option == 1 {s.focus(0) >>> }
        << 0
    }
    
    fn tool_35_update(m $&Workshop, s $&widgets.Screen, option int) int {
        page := m.page_snapshot(35)
        id := page.ids[0]
        $notice := widgets.notice(&"Workspace saved · 工作区已保存")
        notice.action = "Undo"
        notice.key = "workspace-save"
        if option == 1 {notice.text = "Changes restored · 已撤销"
            notice.key = "workspace-undo"}
        $count := 1
        if option == 2 {count = 3}
        for i in 0:count{if count > 1 {notice.key = "notice-" + str(i)
                notice.text = "Queued notice " + str(i + 1)}
            _ := s.enqueue_notice(&notice) >>> }
        << 0
    }
    
    fn tool_36_update(m $&Workshop, s $&widgets.Screen, option int) int {
        index := 36
        page := m.page_snapshot(36)
        id := page.ids[0]
        if option == 0 {if index == 33 {m.open_preferences(s) >>> } else {s.open(page.ids[1]) >>> }}
        else if option == 1 {s.close_overlay(page.ids[1]) >>> }
        << 0
    }
    
    fn tool_37_update(m $&Workshop, s $&widgets.Screen, option int) int {
        page := m.page_snapshot(37)
        id := page.ids[0]
        if option == 0 {native := s.webview_native(id) >>>
            client := webview.bind_native(&native) >>>
            client.command("reload") >>> }
        else {s.set_visible(id, option == 2) >>> }
        << 0
    }
    
    fn tool_38_update(m $&Workshop, s $&widgets.Screen, option int) int {
        page := m.page_snapshot(38)
        id := page.ids[0]
        if option == 0 {m.group_disabled = !m.group_disabled
            m.controls_dirty = true}
        if option == 1 {m.group_vertical = !m.group_vertical}
        if option == 2 {m.group_joined = !m.group_joined}
        m.appearance_dirty = true
        << 0
    }
    
    fn tool_39_update(m $&Workshop, s $&widgets.Screen, option int) int {
        page := m.page_snapshot(39)
        id := page.ids[0]
        if option == 0 {m.revision += 1
            english := (s.selected(m.language) >>>) == 1
            series := chart_data_locale(m.chart_kind, m.revision, english)
            s.set_chart_series(id, &series) >>>
            m.chart_paused = false}
        if option == 1 {s.reset_chart_viewport(id) >>> }
        if option == 2 {m.chart_paused = !m.chart_paused
            if m.chart_paused{s.pause_chart_animation(id) >>> }
            else {s.resume_chart_animation(id) >>> }}
        << 0
    }
    
    fn tool_40_update(m $&Workshop, s $&widgets.Screen, option int) int {
        page := m.page_snapshot(40)
        id := page.ids[0]
        if option == 0 {m.range_push = !m.range_push}
        if option == 1 {m.range_commit = !m.range_commit}
        if option == 2 {m.range_vertical = !m.range_vertical}
        m.appearance_dirty = true
        m.range_summary(s, false) >>>
        << 0
    }
    
    fn tool_41_update(m $&Workshop, s $&widgets.Screen, option int) int {
        page := m.page_snapshot(41)
        id := page.ids[0]
        if option == 0 {m.split_vertical = !m.split_vertical
            m.appearance_dirty = true}
        if option == 1 {m.split_collapsed =(s.split_layout(id) >>>).collapsed == 0
            s.set_split_collapsed(id, 0, m.split_collapsed) >>> }
        if option == 2 {m.split_collapsed = false
            s.set_split_ratio(id, 0.4) >>> }
        << 0
    }
    
    fn tool_42_update(m $&Workshop, s $&widgets.Screen, option int) int {
        page := m.page_snapshot(42)
        id := page.ids[0]
        if option == 0 {s.focus(id) >>>
            s.set_menu_open(id, true) >>> }
        if option == 1 {m.menu_stays_open = !m.menu_stays_open
            m.appearance_dirty = true}
        if option == 2 {m.menu_export_disabled = !m.menu_export_disabled
            s.set_menu_item_enabled(id, 30, !m.menu_export_disabled) >>> }
        << 0
    }
    
    fn tool_43_update(m $&Workshop, s $&widgets.Screen, option int) int {
        page := m.page_snapshot(43)
        id := page.ids[0]
        if option == 0 {s.focus(id) >>>
            s.set_menu_open(id, true) >>> }
        if option == 1 {m.menu_stays_open = !m.menu_stays_open
            m.appearance_dirty = true}
        if option == 2 {m.menu_export_disabled = !m.menu_export_disabled
            s.set_menu_item_enabled(id, 30, !m.menu_export_disabled) >>> }
        << 0
    }
    
    fn tool_44_update(m $&Workshop, s $&widgets.Screen, option int) int {
        page := m.page_snapshot(44)
        id := page.ids[0]
        if option == 0 {s.focus(id) >>>
            s.set_menu_open(id, true) >>> }
        if option == 1 {m.menu_stays_open = !m.menu_stays_open
            m.appearance_dirty = true}
        if option == 2 {m.menu_export_disabled = !m.menu_export_disabled
            s.set_menu_item_enabled(id, 30, !m.menu_export_disabled) >>> }
        << 0
    }
    
    fn tool_45_update(m $&Workshop, s $&widgets.Screen, option int) int {
        page := m.page_snapshot(45)
        id := page.ids[0]
        if option == 0 {s.set_value(id, "") >>> }
        if option == 1 {s.set_value(id, "Xu-密码🙂") >>> }
        if option == 2 {s.focus(id) >>> }
        << 0
    }
    
    fn tool_none_update(m $&Workshop, s $&widgets.Screen, option int) int { << 0}
    
    fn tool_clicked_update(m $&Workshop, s $&widgets.Screen, a &widgets.Action) int {
        handlers :=[tool_0, tool_1, tool_2, tool_3, tool_4, tool_5, tool_6, tool_7, tool_8, tool_9, tool_10, tool_11, tool_none, tool_13, tool_none, tool_15, tool_16, tool_17, tool_18, tool_19, tool_20, tool_none, tool_none, tool_none, tool_24, tool_25, tool_none, tool_27, tool_28, tool_none, tool_30, tool_none, tool_32, tool_33, tool_34, tool_35, tool_36, tool_37, tool_38, tool_39, tool_40, tool_41, tool_42, tool_43, tool_44, tool_45]
        for i in 0:3 {if a.id == m.tools[i] {handler := handlers[m.selected]
                message := handler(m, s, i)
                if message.len > 0 { >> errors.new(message)}
                << 0}}
        << 0
    }
    
    fn tool_clicked(m $&Workshop, s $&widgets.Screen, a &widgets.Action) string {
        tool_clicked_update(m, s, a) >>> (err) { << err.msg()}
        << ""
    }
    
    fn tool_0(m $&Workshop, s $&widgets.Screen, option int) string {
        tool_0_update(m, s, option) >>> (err) { << err.msg()}
        << ""
    }
    
    fn tool_1(m $&Workshop, s $&widgets.Screen, option int) string {
        tool_1_update(m, s, option) >>> (err) { << err.msg()}
        << ""
    }
    
    fn tool_2(m $&Workshop, s $&widgets.Screen, option int) string {
        tool_2_update(m, s, option) >>> (err) { << err.msg()}
        << ""
    }
    
    fn tool_3(m $&Workshop, s $&widgets.Screen, option int) string {
        tool_3_update(m, s, option) >>> (err) { << err.msg()}
        << ""
    }
    
    fn tool_4(m $&Workshop, s $&widgets.Screen, option int) string {
        tool_4_update(m, s, option) >>> (err) { << err.msg()}
        << ""
    }
    
    fn tool_5(m $&Workshop, s $&widgets.Screen, option int) string {
        tool_5_update(m, s, option) >>> (err) { << err.msg()}
        << ""
    }
    
    fn tool_6(m $&Workshop, s $&widgets.Screen, option int) string {
        tool_6_update(m, s, option) >>> (err) { << err.msg()}
        << ""
    }
    
    fn tool_7(m $&Workshop, s $&widgets.Screen, option int) string {
        tool_7_update(m, s, option) >>> (err) { << err.msg()}
        << ""
    }
    
    fn tool_8(m $&Workshop, s $&widgets.Screen, option int) string {
        tool_8_update(m, s, option) >>> (err) { << err.msg()}
        << ""
    }
    
    fn tool_9(m $&Workshop, s $&widgets.Screen, option int) string {
        tool_9_update(m, s, option) >>> (err) { << err.msg()}
        << ""
    }
    
    fn tool_10(m $&Workshop, s $&widgets.Screen, option int) string {
        tool_10_update(m, s, option) >>> (err) { << err.msg()}
        << ""
    }
    
    fn tool_11(m $&Workshop, s $&widgets.Screen, option int) string {
        tool_11_update(m, s, option) >>> (err) { << err.msg()}
        << ""
    }
    
    fn tool_13(m $&Workshop, s $&widgets.Screen, option int) string {
        tool_13_update(m, s, option) >>> (err) { << err.msg()}
        << ""
    }
    
    fn tool_15(m $&Workshop, s $&widgets.Screen, option int) string {
        tool_15_update(m, s, option) >>> (err) { << err.msg()}
        << ""
    }
    
    fn tool_16(m $&Workshop, s $&widgets.Screen, option int) string {
        tool_16_update(m, s, option) >>> (err) { << err.msg()}
        << ""
    }
    
    fn tool_17(m $&Workshop, s $&widgets.Screen, option int) string {
        tool_17_update(m, s, option) >>> (err) { << err.msg()}
        << ""
    }
    
    fn tool_18(m $&Workshop, s $&widgets.Screen, option int) string {
        tool_18_update(m, s, option) >>> (err) { << err.msg()}
        << ""
    }
    
    fn tool_19(m $&Workshop, s $&widgets.Screen, option int) string {
        tool_19_update(m, s, option) >>> (err) { << err.msg()}
        << ""
    }
    
    fn tool_20(m $&Workshop, s $&widgets.Screen, option int) string {
        tool_20_update(m, s, option) >>> (err) { << err.msg()}
        << ""
    }
    
    fn tool_24(m $&Workshop, s $&widgets.Screen, option int) string {
        tool_24_update(m, s, option) >>> (err) { << err.msg()}
        << ""
    }
    
    fn tool_25(m $&Workshop, s $&widgets.Screen, option int) string {
        tool_25_update(m, s, option) >>> (err) { << err.msg()}
        << ""
    }
    
    fn tool_27(m $&Workshop, s $&widgets.Screen, option int) string {
        tool_27_update(m, s, option) >>> (err) { << err.msg()}
        << ""
    }
    
    fn tool_28(m $&Workshop, s $&widgets.Screen, option int) string {
        tool_28_update(m, s, option) >>> (err) { << err.msg()}
        << ""
    }
    
    fn tool_30(m $&Workshop, s $&widgets.Screen, option int) string {
        tool_30_update(m, s, option) >>> (err) { << err.msg()}
        << ""
    }
    
    fn tool_32(m $&Workshop, s $&widgets.Screen, option int) string {
        tool_32_update(m, s, option) >>> (err) { << err.msg()}
        << ""
    }
    
    fn tool_33(m $&Workshop, s $&widgets.Screen, option int) string {
        tool_33_update(m, s, option) >>> (err) { << err.msg()}
        << ""
    }
    
    fn tool_34(m $&Workshop, s $&widgets.Screen, option int) string {
        tool_34_update(m, s, option) >>> (err) { << err.msg()}
        << ""
    }
    
    fn tool_35(m $&Workshop, s $&widgets.Screen, option int) string {
        tool_35_update(m, s, option) >>> (err) { << err.msg()}
        << ""
    }
    
    fn tool_36(m $&Workshop, s $&widgets.Screen, option int) string {
        tool_36_update(m, s, option) >>> (err) { << err.msg()}
        << ""
    }
    
    fn tool_37(m $&Workshop, s $&widgets.Screen, option int) string {
        tool_37_update(m, s, option) >>> (err) { << err.msg()}
        << ""
    }
    
    fn tool_38(m $&Workshop, s $&widgets.Screen, option int) string {
        tool_38_update(m, s, option) >>> (err) { << err.msg()}
        << ""
    }
    
    fn tool_39(m $&Workshop, s $&widgets.Screen, option int) string {
        tool_39_update(m, s, option) >>> (err) { << err.msg()}
        << ""
    }
    
    fn tool_40(m $&Workshop, s $&widgets.Screen, option int) string {
        tool_40_update(m, s, option) >>> (err) { << err.msg()}
        << ""
    }
    
    fn tool_41(m $&Workshop, s $&widgets.Screen, option int) string {
        tool_41_update(m, s, option) >>> (err) { << err.msg()}
        << ""
    }
    
    fn tool_42(m $&Workshop, s $&widgets.Screen, option int) string {
        tool_42_update(m, s, option) >>> (err) { << err.msg()}
        << ""
    }
    
    fn tool_43(m $&Workshop, s $&widgets.Screen, option int) string {
        tool_43_update(m, s, option) >>> (err) { << err.msg()}
        << ""
    }
    
    fn tool_44(m $&Workshop, s $&widgets.Screen, option int) string {
        tool_44_update(m, s, option) >>> (err) { << err.msg()}
        << ""
    }
    
    fn tool_45(m $&Workshop, s $&widgets.Screen, option int) string {
        tool_45_update(m, s, option) >>> (err) { << err.msg()}
        << ""
    }
    
    fn tool_none(m $&Workshop, s $&widgets.Screen, option int) string {
        tool_none_update(m, s, option) >>> (err) { << err.msg()}
        << ""
    }

API 声明

struct WebView

XuAPI
pub struct WebView {
    pub id int
    pub window_id int
    pub html string
    pub url string
    pub ipc_names []string
    pub emit_q []string
    pub sim int
}

用途

承载 id、window_id、html、url、ipc_names 等属性的结构体。

公开字段

id int
字段(int)
window_id int
字段(int)
html string
字段(string)
url string
字段(string)
ipc_names []string
字段([]string)
emit_q []string
字段([]string)
sim int
字段(int)

attach

XuAPI
pub fn attach(w $&ui.Window) WebView

用途

执行 attach 处理。

参数

w $&ui.Window
写入侧 / 宽度(独占借用,可修改原值;类型 $&ui.Window)

返回值

WebView — 该类型的值

查看用法示例

bind_native

XuAPI
pub fn bind_native(view &ui.NativeView) WebView

用途

执行 bind native 操作。失败时抛出错误,调用方需处理或继续传播。

参数

view &ui.NativeView
view(只读借用,调用方仍持有原值;类型 &ui.NativeView)

返回值

WebView — 该类型的值

查看用法示例

(&WebView) command

XuAPI
pub fn (wv &WebView) command(line string) int

用途

&WebView 上的操作:命令。失败时抛出错误,调用方需处理或继续传播。

参数

wv &WebView
本次调用使用的 WebView 实例;以只读借用传入,调用方仍持有实例。
line string
line(string)

返回值

int — 该类型的值

www_root_path

XuAPI
pub fn www_root_path() string

用途

执行 www root path 操作。

参数

无需传入参数。

返回值

string — 结果字符串

resolve_www_dir

XuAPI
pub fn resolve_www_dir(want string) string

用途

执行 resolve www dir 操作。失败时抛出错误,调用方需处理或继续传播。

参数

want string
want(string)

返回值

string — 结果字符串

stage_www_root

XuAPI
pub fn stage_www_root(dir0 string) int

用途

执行 stage www root 操作。失败时抛出错误,调用方需处理或继续传播。

参数

dir0 string
dir0(string)

返回值

int — 该类型的值

查看用法示例

ipc_encode_xun

XuAPI
pub fn ipc_encode_xun(name string, payload string) string

用途

执行 ipc encode xun 操作。

参数

name string
名字(string)
payload string
payload(string)

返回值

string — 结果字符串

ipc_encode_result

XuAPI
pub fn ipc_encode_result(ok bool, result string, err string) string

用途

执行 ipc encode result 操作。

参数

ok bool
ok(bool)
result string
result(string)
err string
错误(string)

返回值

string — 结果字符串

ipc_decode_name

XuAPI
pub fn ipc_decode_name(raw string) string

用途

执行 ipc decode name 操作。

参数

raw string
raw(string)

返回值

string — 结果字符串

ipc_decode_payload

XuAPI
pub fn ipc_decode_payload(raw string) string

用途

执行 ipc decode payload 操作。

参数

raw string
raw(string)

返回值

string — 结果字符串

ipc_decode_result

XuAPI
pub fn ipc_decode_result(raw string) string

用途

执行 ipc decode result 操作。

参数

raw string
raw(string)

返回值

string — 结果字符串

bridge_script

XuAPI
pub fn bridge_script() string

用途

执行 bridge script 操作。

参数

无需传入参数。

返回值

string — 结果字符串

app_scheme_url

XuAPI
pub fn app_scheme_url() string

用途

执行 app scheme url 操作。

参数

无需传入参数。

返回值

string — 结果字符串

查看用法示例

default_ipc_addr

XuAPI
pub fn default_ipc_addr() string

用途

执行 default ipc addr 操作。

参数

无需传入参数。

返回值

string — 结果字符串

default_ipc_port

XuAPI
pub fn default_ipc_port() string

用途

执行 default ipc port 操作。

参数

无需传入参数。

返回值

string — 结果字符串

($&WebView) load_html

XuAPI
pub fn (wv $&WebView) load_html(html string) int

用途

$&WebView 上的操作:执行 load html 操作。失败时抛出错误,调用方需处理或继续传播。

参数

wv $&WebView
本次调用使用的 WebView 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
html string
html(string)

返回值

int — 该类型的值

($&WebView) load_url

XuAPI
pub fn (wv $&WebView) load_url(url string) int

用途

$&WebView 上的操作:执行 load url 操作。失败时抛出错误,调用方需处理或继续传播。

参数

wv $&WebView
本次调用使用的 WebView 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
url string
url(string)

返回值

int — 该类型的值

($&WebView) load_remote

XuAPI
pub fn (wv $&WebView) load_remote(url string) int

用途

$&WebView 上的操作:执行 load remote 操作。失败时抛出错误,调用方需处理或继续传播。

参数

wv $&WebView
本次调用使用的 WebView 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
url string
url(string)

返回值

int — 该类型的值

($&WebView) load_file

XuAPI
pub fn (wv $&WebView) load_file(path string) int

用途

$&WebView 上的操作:读文件。失败时抛出错误,调用方需处理或继续传播。

参数

wv $&WebView
本次调用使用的 WebView 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
path string
文件系统路径(string)

返回值

int — 该类型的值

native_eval

XuAPI
pub fn native_eval(js string) int

用途

执行 native eval 操作。失败时抛出错误,调用方需处理或继续传播。

参数

js string
js(string)

返回值

int — 该类型的值

native_reload

XuAPI
pub fn native_reload() int

用途

执行 native reload 操作。失败时抛出错误,调用方需处理或继续传播。

参数

无需传入参数。

返回值

int — 该类型的值

查看用法示例

native_open_devtools

XuAPI
pub fn native_open_devtools() int

用途

执行 native open devtools 操作。失败时抛出错误,调用方需处理或继续传播。

参数

无需传入参数。

返回值

int — 该类型的值

查看用法示例

native_set_zoom

XuAPI
pub fn native_set_zoom(zoom_percent int) int

用途

执行 native set zoom 操作。失败时抛出错误,调用方需处理或继续传播。

参数

zoom_percent int
zoom_percent(int)

返回值

int — 该类型的值

查看用法示例

native_go_back

XuAPI
pub fn native_go_back() int

用途

执行 native go back 操作。失败时抛出错误,调用方需处理或继续传播。

参数

无需传入参数。

返回值

int — 该类型的值

查看用法示例

native_go_forward

XuAPI
pub fn native_go_forward() int

用途

执行 native go forward 操作。失败时抛出错误,调用方需处理或继续传播。

参数

无需传入参数。

返回值

int — 该类型的值

查看用法示例

native_stop

XuAPI
pub fn native_stop() int

用途

原生停止。失败时抛出错误,调用方需处理或继续传播。

参数

无需传入参数。

返回值

int — 该类型的值

查看用法示例

native_print

XuAPI
pub fn native_print() int

用途

原生打印。失败时抛出错误,调用方需处理或继续传播。

参数

无需传入参数。

返回值

int — 该类型的值

查看用法示例

native_eval_result

XuAPI
pub fn native_eval_result(js string) string

用途

执行 native eval result 操作。

参数

js string
js(string)

返回值

string — 结果字符串

查看用法示例

native_find

XuAPI
pub fn native_find(text string) int

用途

执行 native find 操作。

参数

text string
文本(string)

返回值

int — 该类型的值

查看用法示例

native_find_clear

XuAPI
pub fn native_find_clear() int

用途

执行 native find clear 操作。

参数

无需传入参数。

返回值

int — 该类型的值

查看用法示例

native_set_user_agent

XuAPI
pub fn native_set_user_agent(ua string) int

用途

执行 native set user agent 操作。

参数

ua string
ua(string)

返回值

int — 该类型的值

查看用法示例

native_inject_css

XuAPI
pub fn native_inject_css(css string) int

用途

执行 native inject css 操作。

参数

css string
css(string)

返回值

int — 该类型的值

查看用法示例

native_clear_cache

XuAPI
pub fn native_clear_cache() int

用途

执行 native clear cache 操作。

参数

无需传入参数。

返回值

int — 该类型的值

查看用法示例

native_set_muted

XuAPI
pub fn native_set_muted(on int) int

用途

执行 native set muted 操作。

参数

on int
on(int)

返回值

int — 该类型的值

查看用法示例

native_set_background

XuAPI
pub fn native_set_background(hex string) int

用途

执行 native set background 操作。

参数

hex string
hex(string)

返回值

int — 该类型的值

查看用法示例

native_set_context_menu

XuAPI
pub fn native_set_context_menu(on int) int

用途

执行 native set context menu 操作。

参数

on int
on(int)

返回值

int — 该类型的值

查看用法示例

native_set_magnification

XuAPI
pub fn native_set_magnification(on int) int

用途

执行 native set magnification 操作。

参数

on int
on(int)

返回值

int — 该类型的值

查看用法示例

native_cookies_get

XuAPI
pub fn native_cookies_get() string

用途

执行 native cookies get 操作。

参数

无需传入参数。

返回值

string — 结果字符串

查看用法示例

native_cookies_clear

XuAPI
pub fn native_cookies_clear() int

用途

执行 native cookies clear 操作。

参数

无需传入参数。

返回值

int — 该类型的值

查看用法示例

($&WebView) eval

XuAPI
pub fn (wv $&WebView) eval(js string) string

用途

在 $&WebView 上执行 eval 操作。失败时抛出错误,调用方需处理或继续传播。

参数

wv $&WebView
本次调用使用的 WebView 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
js string
js(string)

返回值

string — 结果字符串

($&WebView) on

XuAPI
pub fn (wv $&WebView) on(name string)

用途

$&WebView 上的操作:于。

参数

wv $&WebView
本次调用使用的 WebView 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
name string
名字(string)

返回值

不返回值。

($&WebView) invoke

XuAPI
pub fn (wv $&WebView) invoke(name string, payload string, dispatch fn(string, string) string) string

用途

在 $&WebView 上执行 invoke 操作。

参数

wv $&WebView
本次调用使用的 WebView 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
name string
名字(string)
payload string
payload(string)
dispatch fn(string, string) string
dispatch(函数值;类型 fn(string, string) string)

返回值

string — 结果字符串

bus_emit

XuAPI
pub fn bus_emit(emit_ch chan string, name string, payload string)

用途

执行 bus emit 操作。

参数

emit_ch chan string
emit_ch(通道;类型 chan string)
name string
名字(string)
payload string
payload(string)

返回值

不返回值。

查看用法示例

native_emit

XuAPI
pub fn native_emit(name string, payload string) int

用途

执行 native emit 操作。失败时抛出错误,调用方需处理或继续传播。

参数

name string
名字(string)
payload string
payload(string)

返回值

int — 该类型的值

retry_emit

XuAPI
pub fn retry_emit(event &ui.Event) int

用途

执行 retry emit 操作。失败时抛出错误,调用方需处理或继续传播。

参数

event &ui.Event
event(只读借用,调用方仍持有原值;类型 &ui.Event)

返回值

int — 该类型的值

($&WebView) emit

XuAPI
pub fn (wv $&WebView) emit(name string, payload string) int

用途

在 $&WebView 上执行 emit 操作。

参数

wv $&WebView
本次调用使用的 WebView 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
name string
名字(string)
payload string
payload(string)

返回值

int — 该类型的值

($&WebView) emit_pending_count

XuAPI
pub fn (wv $&WebView) emit_pending_count() int

用途

$&WebView 上的操作:执行 emit pending count 操作。

参数

wv $&WebView
本次调用使用的 WebView 实例;以独占借用传入,方法可修改它,调用方仍持有实例。

返回值

int — 该类型的值

($&WebView) clear_emits

XuAPI
pub fn (wv $&WebView) clear_emits()

用途

$&WebView 上的操作:执行 clear emits 操作。

参数

wv $&WebView
本次调用使用的 WebView 实例;以独占借用传入,方法可修改它,调用方仍持有实例。

返回值

不返回值。

bind_ipc_www

XuAPI
pub fn bind_ipc_www(www_dir string, dispatch fn(string, string) string, emit_ch chan string, shell_ch chan ui.Event) int

用途

执行 bind ipc www 操作。失败时抛出错误,调用方需处理或继续传播。

参数

www_dir string
www_dir(string)
dispatch fn(string, string) string
dispatch(函数值;类型 fn(string, string) string)
emit_ch chan string
emit_ch(通道;类型 chan string)
shell_ch chan ui.Event
shell_ch(通道;类型 chan ui.Event)

返回值

int — 该类型的值

查看用法示例

bind_ipc

XuAPI
pub fn bind_ipc(page string, dispatch fn(string, string) string, emit_ch chan string, shell_ch chan ui.Event) int

用途

执行 bind ipc 操作。失败时抛出错误,调用方需处理或继续传播。

参数

page string
page(string)
dispatch fn(string, string) string
dispatch(函数值;类型 fn(string, string) string)
emit_ch chan string
emit_ch(通道;类型 chan string)
shell_ch chan ui.Event
shell_ch(通道;类型 chan ui.Event)

返回值

int — 该类型的值

serve_ipc

XuAPI
pub fn serve_ipc(addr string, page string, dispatch fn(string, string) string, emit_ch chan string, shell_ch chan ui.Event) int

用途

执行 serve ipc 操作。失败时抛出错误,调用方需处理或继续传播。

参数

addr string
地址(string)
page string
page(string)
dispatch fn(string, string) string
dispatch(函数值;类型 fn(string, string) string)
emit_ch chan string
emit_ch(通道;类型 chan string)
shell_ch chan ui.Event
shell_ch(通道;类型 chan ui.Event)

返回值

int — 该类型的值

struct InvokeRequest

XuAPI
pub struct InvokeRequest {
    pub id int
    pub window_id int
    pub generation int
    pub name string
    pub payload string
}

用途

属于特定窗口与文档的派发请求;关闭、导航、超时或取消后,迟到回复被宿主丢弃。

公开字段

id int
字段(int)
window_id int
字段(int)
generation int
字段(int)
name string
名字
payload string
字段(string)

查看用法示例

(&InvokeRequest) target

XuAPI
pub fn (request &InvokeRequest) target() ui.CanvasEvent

用途

在 &InvokeRequest 上执行 target 操作。失败时抛出错误,调用方需处理或继续传播。

参数

request &InvokeRequest
本次调用使用的 InvokeRequest 实例;以只读借用传入,调用方仍持有实例。

返回值

ui.CanvasEvent — 该类型的值

bind_ipc_requests_www

XuAPI
pub fn bind_ipc_requests_www(www_dir string,dispatch fn(InvokeRequest) string,emit_ch chan string,shell_ch chan ui.Event) int

用途

在独立 Xu worker 中派发网页请求。最多 64 个活跃额度,单体 1 MiB、共享 8 MiB;取消不强制中断回调。

参数

www_dir string
www_dir(string)
dispatch fn(InvokeRequest) string
接收 InvokeRequest,返回 UTF-8 字符串;可并发、乱序完成
emit_ch chan string
emit_ch(通道;类型 chan string)
shell_ch chan ui.Event
shell_ch(通道;类型 chan ui.Event)

返回值

派发循环结束返回 0;初始化失败抛出错误

查看用法示例

(&WebView) eval_async

XuAPI
pub fn (wv &WebView) eval_async(script &string,options &ui.RequestOptions) ui.Request

用途

执行 JavaScript,通过 ui.ev_request 返回终态,支持取消 / 超时 / 窗口和导航身份,结果最多 64 KiB。

参数

wv &WebView
本次调用使用的 WebView 实例;以只读借用传入,调用方仍持有实例。
script &string
script(只读借用,调用方仍持有原值;类型 &string)
options &ui.RequestOptions
options(只读借用,调用方仍持有原值;类型 &ui.RequestOptions)

返回值

已受理的 ui.Request;失败抛出错误

(&WebView) find_async

XuAPI
pub fn (wv &WebView) find_async(text &string,options &ui.RequestOptions) ui.Request

用途

查找网页文字,通过 ui.ev_request 返回终态,支持取消 / 超时 / 窗口和导航身份,结果最多 64 KiB。

参数

wv &WebView
本次调用使用的 WebView 实例;以只读借用传入,调用方仍持有实例。
text &string
文本(只读借用,调用方仍持有原值;类型 &string)
options &ui.RequestOptions
options(只读借用,调用方仍持有原值;类型 &ui.RequestOptions)

返回值

已受理的 ui.Request;失败抛出错误

(&WebView) cookies_async

XuAPI
pub fn (wv &WebView) cookies_async(options &ui.RequestOptions) ui.Request

用途

查询 cookie,通过 ui.ev_request 返回终态,支持取消 / 超时 / 窗口和导航身份,结果最多 64 KiB。

参数

wv &WebView
本次调用使用的 WebView 实例;以只读借用传入,调用方仍持有实例。
options &ui.RequestOptions
options(只读借用,调用方仍持有原值;类型 &ui.RequestOptions)

返回值

已受理的 ui.Request;失败抛出错误

(&WebView) clear_cookies_async

XuAPI
pub fn (wv &WebView) clear_cookies_async(options &ui.RequestOptions) ui.Request

用途

清除 cookie,通过 ui.ev_request 返回终态,支持取消 / 超时 / 窗口和导航身份,结果最多 64 KiB。

参数

wv &WebView
本次调用使用的 WebView 实例;以只读借用传入,调用方仍持有实例。
options &ui.RequestOptions
options(只读借用,调用方仍持有原值;类型 &ui.RequestOptions)

返回值

已受理的 ui.Request;失败抛出错误