#Lepus WebView

    lepus-apps/lepus/webview is a MoonBit-native desktop framework built on top of webview. It provides:

    • Native windows (WebKit / WebView2)
    • Typed JS MoonBit bridge
    • Plugin-style command routing
    • Parent/child process IPC APIs

    #Architecture

    flowchart LR subgraph JS["JavaScript Runtime"] JSAPI["window.lepusBridge / window.lepusApi"] end subgraph MB["MoonBit Runtime"] WV["WebView"] PL["PluginHost + CommandRouter"] WM["WindowManager (IPC)"] APP["Managed App (parent/child)"] end subgraph NATIVE["Native Layer"] STUB["stub.c + binding.mbt"] LIB["webview C library"] end JSAPI <-->|"Command request/response"| PL PL <-->|"Cross-process command/event"| WM APP --> WM PL --> WV WV --> STUB --> LIB

    #API List

    API list below is aligned with pkg.generated.mbti.

    #WebView

    • Lifecycle: destroy, terminate
    • Window/UI: set_title, set_size, set_html, navigate
    • Window controls: minimize, maximize, unmaximize, toggle_maximize, set_fullscreen, toggle_fullscreen, close
    • Window customization: set_window_customization, enable_custom_titlebar_support, enable_transparent_background_support
    • History: back, forward, go, reload, reload_force
    • Handle: get_handle

    #Window (Managed App)

    • Setup: new, install, set_html, navigate
    • Window controls: minimize, maximize, unmaximize, toggle_maximize, set_fullscreen, toggle_fullscreen, close
    • Window customization: set_window_customization
    • History: back, forward, go, reload, reload_force
    • Run: run

    #Plugin / PluginHost / PluginContext

    • Plugin build/install: Plugin::new, PluginInternal::new, PluginHost::new, PluginHost::install, PluginHost::destroy
    • Context handlers: command_async, command_result_async, command_result_bg
    • Bridge access: PluginHost::command_bridge, PluginHost::global_name

    #Process Command IPC

    • Request/response model: ProcessCommandRequest, ProcessCommandResponse
    • Router: ProcessCommandRouter::{new, handle, handle_async, handle_result, handle_result_async, dispatch, serve, plugin}
    • Proxy: ProcessCommandProxy::{new, call, call_plugin, plugin_handler}
    • Plugin router: ProcessPluginRouter::{command, command_async, command_result, command_result_async}

    #Window Manager IPC

    • Process control: init, fork_process, spawn_process, connect_child_process
    • Window control: create_window, create_child_window, run_window, destroy_window, destroy, set_window_customization, minimize_window, maximize_window, unmaximize_window, toggle_maximize_window, set_fullscreen_window, toggle_fullscreen_window, close_window
    • Messaging: send_message, broadcast, request, respond, try_pop_message
    • Process-command serving: serve_process_commands
    • State: is_main_process, is_child_process, wait_child_noblock

    #Window Customization

    Window::new(...) and WebView::new_managed(...) support:

    • frameless : Bool
    • resizable : Bool
    • always_on_top : Bool
    • transparent : Bool
    • title_bar_style : Int (0 default, 1 hidden)
    • title_bar_overlay : Bool

    Constants:

    • @webview.TITLE_BAR_STYLE_DEFAULT
    • @webview.TITLE_BAR_STYLE_HIDDEN

    #Drag Region (-webkit-app-region: drag)

    For custom title bars, Lepus injects drag helpers automatically when one of the following is true:

    • frameless = true
    • title_bar_style = TITLE_BAR_STYLE_HIDDEN
    • title_bar_overlay = true

    You can mark draggable and interactive regions with:

    • draggable: .lepus-drag, .lepus-titlebar, [data-lepus-drag="true"]
    • non-draggable: .lepus-no-drag

    You can also use raw CSS directly:

    .titlebar { -webkit-app-region: drag; } .titlebar button { -webkit-app-region: no-drag; }

    #Example

    Run the included demo:

    moon build --target native example moon run --target native example

    Minimal managed-window example:

    ///|
    fn main {
    let win = @webview.Window(title="Lepus WebView", width=960, height=640)
    win.set_html("<html><body><h1>Hello from MoonBit</h1></body></html>")
    win.run()
    }

    #Build & Test

    moon check moon test --target native moon build --target native

    #License

    Apache-2.0

    ProcessCommandError

    type ProcessCommandError

    BindingHandle

    #external
    pub type BindingHandle

    Opaque binding record returned by moonbit_webview_bind. C allocates and owns it; MoonBit holds it only as a cookie for unbind.

    CommandBridge

    type CommandBridge[X]

    High-level command bridge using webview_bind.

    JS API:
    • window[global_name].send(name, payload) → calls MoonBit command

    CommandResponse

    pub(all) enum CommandResponse {
    Ok(Json)
    Error(String)
    } derive(Eq)

    Structured response returned from JS → MoonBit commands.

    CommandResponse::equal

    CommandResponse::not_equal

    fn CommandResponse::not_equal(x : CommandResponse, y : CommandResponse) -> Bool

    IpcMessage

    pub struct IpcMessage {
    source_window_id : Int
    target_window_id : Int
    message_type : IpcMessageType
    message_id : Int
    subtype : String
    data : String
    }

    Snapshot of one IPC message copied out of the native queue.

    IpcMessageType

    pub(all) enum IpcMessageType {
    Data
    Command
    Event
    Request
    Response
    } derive(Eq)

    IPC message kind.

    IpcMessageType::equal

    IpcMessageType::int

    fn IpcMessageType::int(self : IpcMessageType) -> Int

    IpcMessageType::not_equal

    fn IpcMessageType::not_equal(x : IpcMessageType, y : IpcMessageType) -> Bool

    Plugin

    pub struct Plugin {
    name : String
    install_scripts : Array[String]
    parent_installers : Array[(ProcessPluginRouter) -> Unit]
    child_installers : Array[(PluginContext[Unit], ProcessCommandProxy) -> Unit]
    direct_installers : Array[(PluginContext[Unit]) -> Unit]
    }

    A plugin definition that can be installed into a PluginHost.

    A plugin is typically exposed from a MoonBit module:

    pub fn plugin() -> @webview.Plugin {
    @webview.Plugin("math", fn(plugin) {
    plugin.command("sum", fn(payload : SumPayload) {
    SumReply{ total: payload.left + payload.right }
    })
    })
    }

    Managed plugins are built once and then used in both:
    • parent process: register real handlers
    • child process: register proxy handlers or direct handlers

    Plugin::Plugin

    #alias(new, deprecated="Use `Plugin()` instead")
    fn Plugin::Plugin(name : String, register : (PluginBuilder) -> Unit) -> Plugin

    Creates a managed plugin whose commands are available from JavaScript without exposing IPC details to user code.

    PluginBuilder

    pub struct PluginBuilder {
    plugin_name : String
    install_scripts : Array[String]
    parent_installers : Array[(ProcessPluginRouter) -> Unit]
    child_installers : Array[(PluginContext[Unit], ProcessCommandProxy) -> Unit]
    direct_installers : Array[(PluginContext[Unit]) -> Unit]
    }

    Registration context used while building a managed Plugin.

    PluginBuilder::command

    fn[Payload :
    FromJson
    + ToJson, Reply :
    FromJson
    + ToJson] PluginBuilder::command(self : PluginBuilder, api_name : String, callback : async (Payload) -> Reply) -> Unit

    Registers a typed async plugin command.

    PluginBuilder::command_result_async

    fn[Payload :
    FromJson
    + ToJson, Reply :
    FromJson
    + ToJson] PluginBuilder::command_result_async(self : PluginBuilder, api_name : String, callback : async (Payload) -> Reply) -> Unit

    Registers a typed async plugin command that can raise explicit command errors.

    PluginBuilder::command_sync

    fn[Payload :
    FromJson
    + ToJson, Reply :
    FromJson
    + ToJson] PluginBuilder::command_sync(self : PluginBuilder, api_name : String, callback : (Payload) -> Reply) -> Unit

    Registers a typed synchronous plugin command.

    PluginBuilder::script

    fn PluginBuilder::script(self : PluginBuilder, script : String) -> Unit

    Registers a JavaScript snippet injected when this plugin is installed.

    PluginContext

    type PluginContext[X]

    Registration context handed to a plugin while it installs its public APIs.

    PluginContext::command_async

    fn[X, Payload :
    FromJson
    , Reply : ToJson] PluginContext::command_async(self : PluginContext[X], api_name : String, callback : async (Payload) -> Reply) -> Unit

    Registers an async typed plugin command.

    The command becomes callable from JavaScript through: window.lepusApi[plugin_name][api_name](...args). The callback is spawned as a background task, non-blocking.

    PluginContext::command_result_async

    fn[X, Payload :
    FromJson
    , Reply : ToJson] PluginContext::command_result_async(self : PluginContext[X], api_name : String, callback : async (Payload) -> Reply) -> Unit

    Registers an async typed plugin command that can return explicit command errors.

    PluginContext::command_result_bg

    fn[X, Payload :
    FromJson
    , Reply : ToJson] PluginContext::command_result_bg(self : PluginContext[X], api_name : String, callback : (Payload) -> Reply raise) -> Unit

    Registers a typed plugin command that performs blocking work on a detached native thread and responds asynchronously to JavaScript.

    PluginContext::command_sync

    fn[X, Payload :
    FromJson
    , Reply : ToJson] PluginContext::command_sync(self : PluginContext[X], api_name : String, callback : (Payload) -> Reply) -> Unit

    Registers a typed synchronous plugin command.

    PluginContext::install_command_api

    fn[X] PluginContext::install_command_api(self : PluginContext[X], api_name : String, register : (String) -> Unit) -> Unit

    PluginContext::name

    fn[X] PluginContext::name(self : PluginContext[X]) -> String

    Returns the plugin name currently being installed.

    PluginContext::register_api

    fn[X] PluginContext::register_api(self : PluginContext[X], api_name : String) -> String

    PluginHost

    type PluginHost[X]

    Plugin host built on top of CommandBridge.

    On the JavaScript side this exposes:
    • window[global_name]["@@call"](plugin_name, api_name, ...args)
    • window[global_name][plugin_name][api_name](...args)

    Argument packing rule:
    • one argument: sent as-is
    • two or more arguments: sent as an array

    PluginHost::PluginHost

    #alias(new, deprecated="Use `PluginHost()` instead")
    fn[X] PluginHost::PluginHost(webview : WebView[X], global_name? : String) -> PluginHost[X]

    Creates a plugin host backed by a CommandBridge.

    global_name controls the JavaScript namespace used for plugin APIs (defaults to window.lepusApi).

    PluginHost::command_bridge

    fn[X] PluginHost::command_bridge(self : PluginHost[X]) -> CommandBridge[X]

    Returns the underlying command bridge used by the plugin host.

    PluginHost::destroy

    fn[X] PluginHost::destroy(self : PluginHost[X]) -> Unit

    Destroys the plugin host and all installed plugins.

    PluginHost::global_name

    fn[X] PluginHost::global_name(self : PluginHost[X]) -> String

    Returns the JavaScript global object name used for plugin APIs.

    PluginHost::install

    fn PluginHost::install(self : PluginHost[Unit], plugin : Plugin, proxy? : ProcessCommandProxy?) -> Unit

    Installs a plugin into the host.

    This aborts if another plugin with the same name has already been installed on this host.

    PluginHost::install_script

    fn[X] PluginHost::install_script(self : PluginHost[X], script : String) -> Unit

    ProcessCommandProxy

    pub struct ProcessCommandProxy {
    wm : WindowManager
    source_window_id : Int
    subtype : String
    }

    ProcessCommandProxy::call

    fn[Payload : ToJson, Reply :
    FromJson
    ] ProcessCommandProxy::call(self : ProcessCommandProxy, name : String, payload : Payload, target_window_id? : Int, timeout_ms? : Int) -> Reply raise ProcessCommandError

    ProcessCommandProxy::call_plugin

    fn[Payload : ToJson, Reply :
    FromJson
    ] ProcessCommandProxy::call_plugin(self : ProcessCommandProxy, plugin_name : String, api_name : String, payload : Payload, target_window_id? : Int, timeout_ms? : Int) -> Reply raise ProcessCommandError

    ProcessCommandProxy::new

    fn ProcessCommandProxy::new(wm : WindowManager, source_window_id : Int, subtype? : String) -> ProcessCommandProxy

    ProcessCommandProxy::plugin_handler

    fn[Payload : ToJson, Reply :
    FromJson
    ] ProcessCommandProxy::plugin_handler(self : ProcessCommandProxy, plugin_name : String, api_name : String, target_window_id? : Int, timeout_ms? : Int) -> ((Payload) -> Reply raise)

    Builds a typed forwarding closure for a plugin command handled by the parent process.

    ProcessCommandReplyForTest

    type ProcessCommandReplyForTest derive(
    FromJson
    )

    ProcessCommandRequest

    pub struct ProcessCommandRequest {
    name : String
    payload : Json
    } derive(ToJson,
    FromJson
    )

    IPC command request exchanged between the child webview process and the parent async dispatcher.

    ProcessCommandRequest::new

    fn[Payload : ToJson] ProcessCommandRequest::new(name : String, payload : Payload) -> ProcessCommandRequest

    ProcessCommandRequest::parse

    ProcessCommandRequest::to_json

    ProcessCommandResponse

    pub(all) enum ProcessCommandResponse {
    Ok(Json)
    Error(String)
    } derive(ToJson,
    FromJson
    )

    IPC command response returned by the parent async dispatcher.

    ProcessCommandResponse::decode_reply

    ProcessCommandResponse::error

    fn ProcessCommandResponse::error(message : String) -> ProcessCommandResponse

    ProcessCommandResponse::ok

    fn[Payload : ToJson] ProcessCommandResponse::ok(payload : Payload) -> ProcessCommandResponse

    ProcessCommandResponse::stringify

    fn ProcessCommandResponse::stringify(self : ProcessCommandResponse) -> String

    ProcessCommandResponse::to_json

    ProcessCommandRouter

    pub struct ProcessCommandRouter {
    handlers : Map[String, async (Json) -> ProcessCommandResponse]
    }

    Parent-process command router for requests coming from a child webview process.

    ProcessCommandRouter::dispatch

    Dispatches a parsed process command through the registered router handlers.

    ProcessCommandRouter::handle

    fn[Payload :
    FromJson
    , Reply : ToJson] ProcessCommandRouter::handle(self : ProcessCommandRouter, name : String, callback : (Payload) -> Reply) -> Unit

    Registers a typed synchronous command on the parent-process router.

    ProcessCommandRouter::handle_async

    fn[Payload :
    FromJson
    , Reply : ToJson] ProcessCommandRouter::handle_async(self : ProcessCommandRouter, name : String, callback : async (Payload) -> Reply) -> Unit

    Registers a typed async command on the parent-process router.

    ProcessCommandRouter::handle_result

    fn[Payload :
    FromJson
    , Reply : ToJson] ProcessCommandRouter::handle_result(self : ProcessCommandRouter, name : String, callback : (Payload) -> Reply raise) -> Unit

    Registers a typed synchronous command that can return explicit errors.

    ProcessCommandRouter::handle_result_async

    fn[Payload :
    FromJson
    , Reply : ToJson] ProcessCommandRouter::handle_result_async(self : ProcessCommandRouter, name : String, callback : async (Payload) -> Reply) -> Unit

    Registers a typed async command that can return explicit errors.

    ProcessCommandRouter::new

    Creates a parent-process command router.

    ProcessCommandRouter::plugin

    fn ProcessCommandRouter::plugin(self : ProcessCommandRouter, plugin_name : String, register : (ProcessPluginRouter) -> Unit) -> Unit

    Registers a plugin namespace on the parent-process router.

    ProcessCommandRouter::serve

    async fn ProcessCommandRouter::serve(self : ProcessCommandRouter, wm : WindowManager, child_pid : Int, subtype? : String) -> Unit

    Serves process commands from a child webview by using the registered router.

    ProcessPluginRouter

    pub struct ProcessPluginRouter {
    router : ProcessCommandRouter
    plugin_name : String
    }

    Plugin-scoped registration context for ProcessCommandRouter.

    ProcessPluginRouter::command

    fn[Payload :
    FromJson
    , Reply : ToJson] ProcessPluginRouter::command(self : ProcessPluginRouter, api_name : String, callback : (Payload) -> Reply) -> Unit

    Registers a typed synchronous plugin command on the parent-process router.

    ProcessPluginRouter::command_async

    fn[Payload :
    FromJson
    , Reply : ToJson] ProcessPluginRouter::command_async(self : ProcessPluginRouter, api_name : String, callback : async (Payload) -> Reply) -> Unit

    Registers a typed async plugin command on the parent-process router.

    ProcessPluginRouter::command_result

    fn[Payload :
    FromJson
    , Reply : ToJson] ProcessPluginRouter::command_result(self : ProcessPluginRouter, api_name : String, callback : (Payload) -> Reply raise) -> Unit

    Registers a typed synchronous plugin command that can return explicit errors.

    ProcessPluginRouter::command_result_async

    fn[Payload :
    FromJson
    , Reply : ToJson] ProcessPluginRouter::command_result_async(self : ProcessPluginRouter, api_name : String, callback : async (Payload) -> Reply) -> Unit

    Registers a typed async plugin command that can return explicit errors.

    ProcessType

    pub(all) enum ProcessType {
    Main
    Child
    Unknown
    } derive(Eq)

    Process type returned by native window manager.

    ProcessType::equal

    fn ProcessType::equal(ProcessType, ProcessType) -> Bool

    ProcessType::not_equal

    fn ProcessType::not_equal(x : ProcessType, y : ProcessType) -> Bool

    SizeHint

    pub(all) enum SizeHint {
    None
    Min
    Max
    Fixed
    }

    Window size hints

    TitleBarStyle

    pub(all) enum TitleBarStyle {
    Default
    Hidden
    } derive(Eq,
    Debug
    )

    TitleBarStyle::equal

    TitleBarStyle::not_equal

    fn TitleBarStyle::not_equal(x : TitleBarStyle, y : TitleBarStyle) -> Bool

    WebView

    type WebView[X]

    An instance of a webview window (managed via IPC).

    Example:

    let webview = @webview.WebView::new_managed(task_group)
    webview.set_title("My WebView")
    webview.set_size(800, 600, @webview.SizeHint::None)
    webview.set_html("<html><body><h1>Hello, World!</h1></body></html>")
    webview.terminate()

    WebView::back

    fn[X] WebView::back(self : WebView[X]) -> Unit

    Navigates one step back in browser history.

    WebView::close

    fn[X] WebView::close(self : WebView[X]) -> Unit

    Close native window.

    WebView::destroy

    fn[X] WebView::destroy(self : WebView[X]) -> Unit

    Destroys the webview and closes the window. Safe to call from a background thread.

    WebView::enable_custom_titlebar_support

    fn[X] WebView::enable_custom_titlebar_support(self : WebView[X]) -> Unit

    Injects CSS helper classes for Electron-like drag regions.

    • .lepus-drag: draggable zone (-webkit-app-region: drag)
    • .lepus-titlebar: titlebar draggable zone (-webkit-app-region: drag)
    • [data-lepus-drag="true"]: draggable zone (-webkit-app-region: drag)
    • .lepus-no-drag: interactive zone (-webkit-app-region: no-drag)

    WebView::enable_transparent_background_support

    fn[X] WebView::enable_transparent_background_support(self : WebView[X]) -> Unit

    Injects CSS/JS that keeps page background transparent.

    WebView::forward

    fn[X] WebView::forward(self : WebView[X]) -> Unit

    Navigates one step forward in browser history.

    WebView::get_handle

    fn[X] WebView::get_handle(self : WebView[X]) -> WebView_t

    Returns the raw WebView_t handle.

    WebView::go

    fn[X] WebView::go(self : WebView[X], delta : Int) -> Unit

    Navigates to a specific entry in browser history.

    • delta < 0: backward
    • delta > 0: forward
    • delta = 0: reload current entry

    WebView::maximize

    fn[X] WebView::maximize(self : WebView[X]) -> Unit

    Maximize native window.

    WebView::minimize

    fn[X] WebView::minimize(self : WebView[X]) -> Unit

    Minimize native window.

    WebView::navigate

    fn[X] WebView::navigate(self : WebView[X], url : String) -> Unit

    Navigates the webview to the given URL. URL may be a data URI.

    Example:
    let webview = @webview.WebView::new_managed(task_group)
    webview.navigate("https://www.example.com")
    webview.navigate("data:text/html,<h1>Hello</h1>")
    webview.terminate()

    WebView::reload

    fn[X] WebView::reload(self : WebView[X]) -> Unit

    Reloads the current page using standard browser cache policy.

    WebView::reload_force

    fn[X] WebView::reload_force(self : WebView[X]) -> Unit

    Reloads the current page and requests a revalidation from server.

    WebView::set_custom_protocol

    fn[X] WebView::set_custom_protocol(self : WebView[X], scheme : String, root_dir : String) -> Unit

    Register a custom scheme backed by a local root directory for this webview.

    WebView::set_devtools

    fn[X] WebView::set_devtools(self : WebView[X], enabled : Bool) -> Unit

    Enable or disable developer tools integration at runtime.

    WebView::set_fullscreen

    fn[X] WebView::set_fullscreen(self : WebView[X], fullscreen : Bool) -> Unit

    Set native fullscreen state.

    WebView::set_html

    fn[X] WebView::set_html(self : WebView[X], html : String) -> Unit

    Loads HTML content into the webview.

    Example:
    let webview = @webview.WebView::new_managed(task_group)
    webview.set_html("<html><body><h1>Hello, World!</h1></body></html>")
    webview.terminate()

    WebView::set_size

    fn[X] WebView::set_size(self : WebView[X], width : Int, height : Int, hints : SizeHint) -> Unit

    Updates the size of the native window.

    Remarks:
    • SizeHint::Max is not supported with GTK 4.
    • GTK 4 can only set a default size early in the window lifecycle.

    WebView::set_title

    fn[X] WebView::set_title(self : WebView[X], title : String) -> Unit

    Updates the title of the native window.

    WebView::set_traffic_light_position

    fn[X] WebView::set_traffic_light_position(self : WebView[X], x : Int, y : Int) -> Unit

    Set macOS traffic-light buttons position.

    WebView::set_window_customization

    fn[X] WebView::set_window_customization(self : WebView[X], frameless : Bool, resizable : Bool, closeable : Bool, always_on_top : Bool, transparent : Bool, title_bar_style : TitleBarStyle, title_bar_overlay : Bool) -> Unit

    Applies native custom-window style flags at runtime.

    WebView::start_drag

    fn[X] WebView::start_drag(self : WebView[X]) -> Unit

    Start native window drag/move gesture.

    WebView::terminate

    fn[X] WebView::terminate(self : WebView[X]) -> Unit

    Stops the main event loop. Safe to call from a background thread.

    WebView::toggle_fullscreen

    fn[X] WebView::toggle_fullscreen(self : WebView[X]) -> Unit

    Toggle native fullscreen state.

    WebView::toggle_maximize

    fn[X] WebView::toggle_maximize(self : WebView[X]) -> Unit

    Toggle native maximize state.

    WebView::unmaximize

    fn[X] WebView::unmaximize(self : WebView[X]) -> Unit

    Restore native window from maximized state.

    WebView_t

    #external
    pub type WebView_t

    Opaque handle returned by webview_create. C manages the underlying object.

    Window

    pub struct Window {
    title : String
    width : Int
    height : Int
    size_hint : SizeHint
    debug : Int
    devtools : Bool
    child_arg : String
    frameless : Bool
    resizable : Bool
    closeable : Bool
    always_on_top : Bool
    transparent : Bool
    title_bar_style : TitleBarStyle
    title_bar_overlay : Bool
    traffic_light_position : (Int, Int)
    enable_window_controls_plugin : Bool
    url : String
    html : String
    pending_custom_protocols : Array[(String, String)]
    runtime_window_id : Int
    plugins : Array[Plugin]
    }

    High-level managed app that owns the parent dispatcher and child webview process lifecycle.

    Window::Window

    #alias(new, deprecated="Use `Window()` instead")
    fn Window::Window(title? : String, url? : String, width? : Int, height? : Int, size_hint? : SizeHint, debug? : Int, devtools? : Bool, child_arg? : String, frameless? : Bool, resizable? : Bool, closeable? : Bool, always_on_top? : Bool, transparent? : Bool, title_bar_style? : TitleBarStyle, title_bar_overlay? : Bool, traffic_light_position? : (Int, Int), enable_window_controls_plugin? : Bool) -> Window

    Creates a managed app. The library handles the parent dispatcher and child webview process automatically.

    Window::close

    fn Window::close(self : Window) -> Unit

    Close native window.

    Window::eval

    fn Window::eval(self : Window, js : String) -> Unit

    Window::install

    fn Window::install(self : Window, plugin : Plugin) -> Unit

    Installs a managed plugin into the app.

    Window::maximize

    fn Window::maximize(self : Window) -> Unit

    Maximize native window.

    Window::minimize

    fn Window::minimize(self : Window) -> Unit

    Minimize native window.

    Window::navigate

    fn Window::navigate(self : Window, url : String) -> Unit

    Window::run

    async fn Window::run(self : Window) -> Unit

    Runs the managed app end-to-end.

    Window::set_custom_protocol

    fn Window::set_custom_protocol(self : Window, scheme : String, root_dir : String) -> Unit

    Register a custom scheme for the child webview before it navigates.

    Window::set_fullscreen

    fn Window::set_fullscreen(self : Window, fullscreen : Bool) -> Unit

    Set native fullscreen state.

    Window::set_html

    fn Window::set_html(self : Window, html : String) -> Unit

    Sets inline HTML content for the child webview.

    Window::set_traffic_light_position

    fn Window::set_traffic_light_position(self : Window, x : Int, y : Int) -> Unit

    Set macOS traffic-light buttons position.

    Window::set_window_customization

    fn Window::set_window_customization(self : Window, frameless : Bool, resizable : Bool, closeable : Bool, always_on_top : Bool, transparent : Bool, title_bar_style : TitleBarStyle, title_bar_overlay : Bool) -> Unit

    Applies native custom-window style flags.

    Window::start_drag

    fn Window::start_drag(self : Window) -> Unit

    Start native window drag/move gesture.

    Window::toggle_fullscreen

    fn Window::toggle_fullscreen(self : Window) -> Unit

    Toggle native fullscreen state.

    Window::toggle_maximize

    fn Window::toggle_maximize(self : Window) -> Unit

    Toggle native maximize state.

    Window::unmaximize

    fn Window::unmaximize(self : Window) -> Unit

    Restore native window from maximized state.

    WindowManager

    pub struct WindowManager {
    process_type : ProcessType
    window_ids : Array[Int]
    }

    Thin high-level wrapper over native window manager (stub.c wm_* APIs).

    WindowManager::broadcast

    fn WindowManager::broadcast(self : WindowManager, source_window_id : Int, subtype : String, data : String) -> Int

    Broadcast an event message.

    WindowManager::close_window

    fn WindowManager::close_window(_self : WindowManager, window_id : Int) -> Int

    Close native window.

    WindowManager::connect_child_process

    fn WindowManager::connect_child_process() -> Int

    Connect current process to the main-process IPC server and switch into child mode.

    WindowManager::create_child_window

    fn WindowManager::create_child_window(_self : WindowManager, title : String, url : String, width? : Int, height? : Int, parent_id? : Int) -> Int

    Spawn a child process window. Returns child process pid.

    WindowManager::create_window

    fn WindowManager::create_window(self : WindowManager, title : String, url : String, width? : Int, height? : Int) -> Int

    Create a native window in current process.

    WindowManager::destroy

    fn WindowManager::destroy(self : WindowManager) -> Unit

    Cleanup native WM runtime.

    WindowManager::destroy_window

    fn WindowManager::destroy_window(_self : WindowManager, window_id : Int) -> Int

    Destroy a window.

    WindowManager::fork_process

    fn WindowManager::fork_process(_self : WindowManager) -> Int

    Fork the current process. The parent receives the child pid, the child receives 0.

    WindowManager::init

    fn WindowManager::init(is_main? : Bool) -> WindowManager

    Initialize WM runtime for current process.

    • main process: pass true
    • child process: pass false

    WindowManager::is_child_process

    fn WindowManager::is_child_process(self : WindowManager) -> Bool

    Return true when running in child process.

    WindowManager::is_main_process

    fn WindowManager::is_main_process(self : WindowManager) -> Bool

    Return true when running in main process.

    WindowManager::maximize_window

    fn WindowManager::maximize_window(_self : WindowManager, window_id : Int) -> Int

    Maximize native window.

    WindowManager::minimize_window

    fn WindowManager::minimize_window(_self : WindowManager, window_id : Int) -> Int

    Minimize native window.

    WindowManager::request

    fn WindowManager::request(_self : WindowManager, source_window_id : Int, target_window_id : Int, subtype : String, data : String, timeout_ms? : Int) -> String

    Send an IPC request and wait for the response body.

    WindowManager::respond

    fn WindowManager::respond(_self : WindowManager, source_window_id : Int, target_window_id : Int, request_id : Int, data : String) -> Int

    Send an IPC response for a previously received request.

    WindowManager::run_window

    fn WindowManager::run_window(_self : WindowManager, window_id : Int) -> Int

    Run a window event loop.

    WindowManager::send_message

    fn WindowManager::send_message(_self : WindowManager, source_window_id : Int, target_window_id : Int, message_type : IpcMessageType, subtype : String, data : String) -> Int

    Send an IPC message.

    WindowManager::serve_process_commands

    async fn WindowManager::serve_process_commands(self : WindowManager, child_pid : Int, handler : async (ProcessCommandRequest) -> ProcessCommandResponse, subtype? : String) -> Unit

    WindowManager::set_devtools

    fn WindowManager::set_devtools(_self : WindowManager, window_id : Int, enabled : Bool) -> Int

    Enable or disable developer tools integration.

    WindowManager::set_fullscreen_window

    fn WindowManager::set_fullscreen_window(_self : WindowManager, window_id : Int, fullscreen : Bool) -> Int

    Set native fullscreen state.

    WindowManager::set_traffic_light_position

    fn WindowManager::set_traffic_light_position(_self : WindowManager, window_id : Int, x : Int, y : Int) -> Int

    Set macOS traffic-light buttons position.

    WindowManager::set_window_customization

    fn WindowManager::set_window_customization(_self : WindowManager, window_id : Int, frameless : Bool, resizable : Bool, closeable : Bool, always_on_top : Bool, transparent : Bool, title_bar_style : TitleBarStyle, title_bar_overlay : Bool) -> Int

    Apply native custom-window style flags.

    WindowManager::spawn_process

    fn WindowManager::spawn_process(_self : WindowManager, program : String, arg1 : String) -> Int

    Spawn a fresh child process by exec-ing the given program path with one extra argument.

    WindowManager::start_drag_window

    fn WindowManager::start_drag_window(_self : WindowManager, window_id : Int) -> Int

    Start native window drag/move gesture.

    WindowManager::toggle_fullscreen_window

    fn WindowManager::toggle_fullscreen_window(_self : WindowManager, window_id : Int) -> Int

    Toggle native fullscreen state.

    WindowManager::toggle_maximize_window

    fn WindowManager::toggle_maximize_window(_self : WindowManager, window_id : Int) -> Int

    Toggle native maximize state.

    WindowManager::try_pop_message

    fn WindowManager::try_pop_message(_self : WindowManager, queue_id : Int) -> IpcMessage?

    Try to pop one queued IPC message for the given queue id.

    WindowManager::unmaximize_window

    fn WindowManager::unmaximize_window(_self : WindowManager, window_id : Int) -> Int

    Restore native window from maximized state.

    WindowManager::wait_child_noblock

    fn WindowManager::wait_child_noblock(_self : WindowManager, pid : Int) -> Int

    Non-blocking child process status check.

    WindowState

    pub(all) enum WindowState {
    Unknown
    Created
    Running
    Hidden
    Closing
    Closed
    } derive(Eq)

    Window state mapped from native window manager.

    WindowState::equal

    fn WindowState::equal(WindowState, WindowState) -> Bool

    WindowState::int

    fn WindowState::int(self : WindowState) -> Int

    WindowState::not_equal

    fn WindowState::not_equal(x : WindowState, y : WindowState) -> Bool

    decode_process_command_response

    fn[Reply :
    FromJson
    ] decode_process_command_response(raw : String) -> Reply raise ProcessCommandError

    webview_set_custom_protocol

    fn webview_set_custom_protocol(w : WebView_t, scheme : Bytes, root_dir : Bytes) -> Int

    Register a custom scheme backed by a local root directory.

    wm_cleanup

    fn wm_cleanup() -> Unit

    Cleanup native window manager runtime.

    wm_close_window

    fn wm_close_window(window_id : Int) -> Int

    Close native window.

    wm_connect_child_process

    fn wm_connect_child_process() -> Int

    Connect the current process to the parent's IPC server and switch WM into child mode.

    wm_create_child_window

    fn wm_create_child_window(title : Bytes, url : Bytes, width : Int, height : Int, parent_window_id : Int) -> Int

    Create child-process window.

    wm_create_window

    fn wm_create_window(title : Bytes, url : Bytes, width : Int, height : Int, x : Int, y : Int, has_x : Int, has_y : Int, parent_window_id : Int) -> Int

    Create a managed native window and register it in WM.

    wm_destroy_window

    fn wm_destroy_window(window_id : Int) -> Int

    Destroy managed window.

    wm_eval_js

    fn wm_eval_js(window_id : Int, js : Bytes) -> Int

    Eval JS in managed window.

    wm_fork_process

    fn wm_fork_process() -> Int

    Fork the current process into a child that is already connected to the IPC server. Returns child pid in the parent process, 0 in the child process, and -1 on error.

    wm_get_handle

    fn wm_get_handle(window_id : Int) -> WebView_t

    Get native handle by managed window id.

    wm_get_process_id

    fn wm_get_process_id() -> Int

    Get current process id.

    wm_get_process_type

    fn wm_get_process_type() -> Int

    Get process type: 0 main, 1 child.

    wm_get_visibility

    fn wm_get_visibility(window_id : Int) -> Int

    Get managed window visibility.

    wm_init

    fn wm_init(is_main_process : Int) -> Int

    Initialize native window manager runtime.

    wm_init_js

    fn wm_init_js(window_id : Int, js : Bytes) -> Int

    Init JS in managed window.

    wm_ipc_pop_message_wire

    fn wm_ipc_pop_message_wire(window_id : Int) -> Bytes

    Pop the next queued IPC message encoded as: source i32, target i32, type i32, id i32, subtype_len i32, data_len i32, followed by subtype bytes and data bytes. Empty bytes means no message.

    wm_ipc_request_bytes

    fn wm_ipc_request_bytes(source_window_id : Int, target_window_id : Int, subtype : Bytes, data : Bytes, timeout_ms : Int) -> Bytes

    Send an IPC request and wait for the raw response bytes.

    wm_ipc_respond

    fn wm_ipc_respond(source_window_id : Int, target_window_id : Int, request_id : Int, data : Bytes) -> Int

    Send an IPC response that matches a previous request id.

    wm_ipc_send

    fn wm_ipc_send(source_window_id : Int, target_window_id : Int, message_type : Int, subtype : Bytes, data : Bytes) -> Int

    Send asynchronous IPC message.

    wm_kill_child

    fn wm_kill_child(pid : Int) -> Int

    Kill child process.

    wm_maximize_window

    fn wm_maximize_window(window_id : Int) -> Int

    Maximize native window.

    wm_minimize_window

    fn wm_minimize_window(window_id : Int) -> Int

    Minimize native window.

    wm_navigate

    fn wm_navigate(window_id : Int, url : Bytes) -> Int

    Navigate managed window to URL.

    wm_return_raw

    fn wm_return_raw(window_id : Int, seq : Bytes, status : Int, result : Bytes) -> Int

    Respond to a JS binding call on the managed window UI thread.

    wm_run_window

    fn wm_run_window(window_id : Int) -> Int

    Run managed window event loop.

    wm_run_window_async

    fn wm_run_window_async(window_id : Int) -> Int

    Start managed window event loop on a detached native thread.

    wm_set_devtools

    fn wm_set_devtools(window_id : Int, enabled : Int) -> Int

    Enable or disable developer tools integration.

    wm_set_fullscreen_window

    fn wm_set_fullscreen_window(window_id : Int, fullscreen : Int) -> Int

    Set native fullscreen state.

    wm_set_html

    fn wm_set_html(window_id : Int, html : Bytes) -> Int

    Set managed window HTML.

    wm_set_size

    fn wm_set_size(window_id : Int, width : Int, height : Int, hints : SizeHint) -> Int

    Set managed window size.

    wm_set_title

    fn wm_set_title(window_id : Int, title : Bytes) -> Int

    Set managed window title.

    wm_set_traffic_light_position

    fn wm_set_traffic_light_position(window_id : Int, x : Int, y : Int) -> Int

    Set macOS traffic-light buttons position.

    wm_set_visibility

    fn wm_set_visibility(window_id : Int, visible : Int) -> Int

    Set managed window visibility.

    wm_set_window_customization

    fn wm_set_window_customization(window_id : Int, frameless : Int, resizable : Int, closeable : Int, always_on_top : Int, transparent : Int, title_bar_style : TitleBarStyle, title_bar_overlay : Int) -> Int

    Apply native custom-window style flags.

    wm_spawn_process

    fn wm_spawn_process(program : Bytes, arg1 : Bytes) -> Int

    Spawn a fresh child process by executing the given program path with one extra argument.

    wm_start_drag_window

    fn wm_start_drag_window(window_id : Int) -> Int

    Start native window drag/move gesture.

    wm_terminate_window

    fn wm_terminate_window(window_id : Int) -> Int

    Request window termination.

    wm_toggle_fullscreen_window

    fn wm_toggle_fullscreen_window(window_id : Int) -> Int

    Toggle native fullscreen state.

    wm_toggle_maximize_window

    fn wm_toggle_maximize_window(window_id : Int) -> Int

    Toggle native maximize state.

    wm_unmaximize_window

    fn wm_unmaximize_window(window_id : Int) -> Int

    Restore native window from maximized state.

    wm_wait_child_noblock

    fn wm_wait_child_noblock(pid : Int) -> Int

    Non-blocking child wait. Returns child pid when exited, 0 when still running.