XU XUv0.8.8
中文

API

#ui/webview

import: #ui/webview

counts: 38 fns, 10 methods, 1 types, 0 consts, 0 ifaces

Attach a webview to ui.Window: load_html/url, eval, on/emit.

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
}

Purpose

Content backend for ui.Window: system WebView + IPC (`#ui/webview`). attach registers a ContentPlugin with per-OS host sources; #ui shell picks the current OS at App.run. Shell/window/menu/tray stay in #ui. two content modes (no local HTTP server in either) 1. Local — stage_www_root / bind_ipc_www + xu://app/ (scheme flag "xu"; host intercepts). Packed oneexe sets XU_UI_WWW=:mem: and serves www/icon from the binary (no TEMP extract). 2. Remote — load_url("http(s)://…"); we do not serve that origin. Adapted remote pages may still call xu://app/__xu/* (and optional xu://app/ static) into the app. UI host must be statically linked (pack_*ui_oneexe.py); no external host process.

Parameters

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

attach

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

Purpose

attach; returns WebView.

Parameters

w &mut ui.Window
writer or width (exclusive borrow; type &mut ui.Window)

Returns

WebView — a value of this type

www_root_path

XuAPI
pub fn www_root_path() string

Purpose

Www root path.

Parameters

none

Returns

string — result string

resolve_www_dir

XuAPI
pub fn resolve_www_dir(want string) string

Purpose

Resolve www dir: pack/:mem: always wins (never materialize www/ under TEMP). Else: XU_UI_WWW path > explicit dir with index.html >./www/index.html. Throws on failure.

Parameters

want string
want (string)

Returns

string — result string

stage_www_root

XuAPI
pub fn stage_www_root(dir0 string) int

Purpose

Stage www root. Throws on failure.

Parameters

dir0 string
dir0 (string)

Returns

int — a value of this type

ipc_encode_xun

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

Purpose

Ipc encode xun.

Parameters

name string
name (string)
payload string
payload (string)

Returns

string — result string

ipc_encode_result

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

Purpose

Ipc encode result.

Parameters

ok bool
ok (bool)
result string
result (string)
err string
error (string)

Returns

string — result string

ipc_decode_name

XuAPI
pub fn ipc_decode_name(raw string) string

Purpose

Ipc decode name.

Parameters

raw string
raw (string)

Returns

string — result string

ipc_decode_payload

XuAPI
pub fn ipc_decode_payload(raw string) string

Purpose

Ipc decode payload.

Parameters

raw string
raw (string)

Returns

string — result string

ipc_decode_result

XuAPI
pub fn ipc_decode_result(raw string) string

Purpose

Ipc decode result.

Parameters

raw string
raw (string)

Returns

string — result string

bridge_script

XuAPI
pub fn bridge_script() string

Purpose

Same-origin xu://app bridge; bodies are XUN documents. macOS: WKScriptMessageHandlerWithReply (postMessage → Promise). Emit is host-pushed.

Parameters

none

Returns

string — result string

app_scheme_url

XuAPI
pub fn app_scheme_url() string

Purpose

App scheme url.

Parameters

none

Returns

string — result string

default_ipc_addr

XuAPI
pub fn default_ipc_addr() string

Purpose

Deprecated: TCP IPC address (use bind_ipc + xu://app/).

Parameters

none

Returns

string — result string

default_ipc_port

XuAPI
pub fn default_ipc_port() string

Purpose

Default ipc port.

Parameters

none

Returns

string — result string

(&mut WebView) load_html

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

Purpose

Method on `&mut WebView`: load html. Throws on failure.

Parameters

wv &mut WebView
receiver &mut WebView (exclusive borrow)
html string
html (string)

Returns

int — a value of this type

(&mut WebView) load_url

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

Purpose

Method on `&mut WebView`: load url. Throws on failure.

Parameters

wv &mut WebView
receiver &mut WebView (exclusive borrow)
url string
url (string)

Returns

int — a value of this type

(&mut WebView) load_remote

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

Purpose

load_remote: remote HTTP(S) document; Xu does not host it. xu:// IPC still available to adapted pages. Throws on failure.

Parameters

wv &mut WebView
receiver &mut WebView (exclusive borrow)
url string
url (string)

Returns

int — a value of this type

(&mut WebView) load_file

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

Purpose

Method on `&mut WebView`: load file. Throws on failure.

Parameters

wv &mut WebView
receiver &mut WebView (exclusive borrow)
path string
filesystem path (string)

Returns

int — a value of this type

native_eval

XuAPI
pub fn native_eval(js string) int

Purpose

Queue JS for the native WKWebView host (file bridge). No-op under XU_UI_SIM=1. Throws on failure.

Parameters

js string
js (string)

Returns

int — a value of this type

native_reload

XuAPI
pub fn native_reload() int

Purpose

Native reload. Throws on failure.

Parameters

none

Returns

int — a value of this type

native_open_devtools

XuAPI
pub fn native_open_devtools() int

Purpose

Native open devtools. Throws on failure.

Parameters

none

Returns

int — a value of this type

native_set_zoom

XuAPI
pub fn native_set_zoom(zoom_percent int) int

Purpose

zoom_percent: 100 = 1.0, 125 = 1.25, … Throws on failure.

Parameters

zoom_percent int
zoom_percent (int)

Returns

int — a value of this type

native_go_back

XuAPI
pub fn native_go_back() int

Purpose

Native go back. Throws on failure.

Parameters

none

Returns

int — a value of this type

native_go_forward

XuAPI
pub fn native_go_forward() int

Purpose

Native go forward. Throws on failure.

Parameters

none

Returns

int — a value of this type

native_stop

XuAPI
pub fn native_stop() int

Purpose

Native stop. Throws on failure.

Parameters

none

Returns

int — a value of this type

native_print

XuAPI
pub fn native_print() int

Purpose

Native print. Throws on failure.

Parameters

none

Returns

int — a value of this type

native_eval_result

XuAPI
pub fn native_eval_result(js string) string

Purpose

Eval JS and wait for stringified result (or "err:…").

Parameters

js string
js (string)

Returns

string — result string

native_find

XuAPI
pub fn native_find(text string) int

Purpose

Native find.

Parameters

text string
text (string)

Returns

int — a value of this type

native_find_clear

XuAPI
pub fn native_find_clear() int

Purpose

Native find clear.

Parameters

none

Returns

int — a value of this type

native_set_user_agent

XuAPI
pub fn native_set_user_agent(ua string) int

Purpose

Native set user agent.

Parameters

ua string
ua (string)

Returns

int — a value of this type

native_inject_css

XuAPI
pub fn native_inject_css(css string) int

Purpose

Returns "x y w h" in screen coordinates.

Parameters

css string
css (string)

Returns

int — a value of this type

native_clear_cache

XuAPI
pub fn native_clear_cache() int

Purpose

Native clear cache.

Parameters

none

Returns

int — a value of this type

native_set_muted

XuAPI
pub fn native_set_muted(on int) int

Purpose

Native set muted.

Parameters

on int
on (int)

Returns

int — a value of this type

native_set_background

XuAPI
pub fn native_set_background(hex string) int

Purpose

Native set background.

Parameters

hex string
hex (string)

Returns

int — a value of this type

native_set_context_menu

XuAPI
pub fn native_set_context_menu(on int) int

Purpose

Native set context menu.

Parameters

on int
on (int)

Returns

int — a value of this type

native_set_magnification

XuAPI
pub fn native_set_magnification(on int) int

Purpose

Native set magnification.

Parameters

on int
on (int)

Returns

int — a value of this type

native_cookies_get

XuAPI
pub fn native_cookies_get() string

Purpose

Returns lines "name=value;domain=…;path=…".

Parameters

none

Returns

string — result string

native_cookies_clear

XuAPI
pub fn native_cookies_clear() int

Purpose

Native cookies clear.

Parameters

none

Returns

int — a value of this type

(&mut WebView) eval

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

Purpose

Call `eval` on `&mut WebView`. Throws on failure.

Parameters

wv &mut WebView
receiver &mut WebView (exclusive borrow)
js string
js (string)

Returns

string — result string

(&mut WebView) on

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

Purpose

Call `on` on `&mut WebView`.

Parameters

wv &mut WebView
receiver &mut WebView (exclusive borrow)
name string
name (string)

(&mut WebView) invoke

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

Purpose

Call `invoke` on `&mut WebView`.

Parameters

wv &mut WebView
receiver &mut WebView (exclusive borrow)
name string
name (string)
payload string
payload (string)
dispatch fn(string, string) string
dispatch (function value; type fn(string, string) string)

Returns

string — result string

bus_emit

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

Purpose

Bus emit.

Parameters

emit_ch chan string
emit_ch (channel; type chan string)
name string
name (string)
payload string
payload (string)

(&mut WebView) emit

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

Purpose

Call `emit` on `&mut WebView`.

Parameters

wv &mut WebView
receiver &mut WebView (exclusive borrow)
name string
name (string)
payload string
payload (string)

Returns

int — a value of this type

(&mut WebView) emit_pending_count

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

Purpose

Method on `&mut WebView`: emit pending count.

Parameters

wv &mut WebView
receiver &mut WebView (exclusive borrow)

Returns

int — a value of this type

(&mut WebView) clear_emits

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

Purpose

Method on `&mut WebView`: clear emits.

Parameters

wv &mut WebView
receiver &mut WebView (exclusive borrow)

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

Purpose

Bind ipc www. Throws on failure.

Parameters

www_dir string
www_dir (string)
dispatch fn(string, string) string
dispatch (function value; type fn(string, string) string)
emit_ch chan string
emit_ch (channel; type chan string)
shell_ch chan ui.Event
shell_ch (channel; type chan ui.Event)

Returns

int — a value of this type

bind_ipc

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

Purpose

bind_ipc: inline HTML → TMP www/index.html, then same as bind_ipc_www. Throws on failure.

Parameters

page string
page (string)
dispatch fn(string, string) string
dispatch (function value; type fn(string, string) string)
emit_ch chan string
emit_ch (channel; type chan string)
shell_ch chan ui.Event
shell_ch (channel; type chan ui.Event)

Returns

int — a value of this type

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

Purpose

Deprecated: TCP listen IPC. Use bind_ipc_www / bind_ipc + xu://app/. Throws on failure.

Parameters

addr string
address (string)
page string
page (string)
dispatch fn(string, string) string
dispatch (function value; type fn(string, string) string)
emit_ch chan string
emit_ch (channel; type chan string)
shell_ch chan ui.Event
shell_ch (channel; type chan ui.Event)

Returns

int — a value of this type