This version of the module is deprecated: This package is deprecated. moonbit-community/proton should be preferred.

    #Proton Native

    justjavac/proton/native is the direct MoonBit FFI binding for the standalone Proton native dynamic library.

    The public API uses Proton-owned Runtime and Window values. Raw native handles are intentionally not part of the public surface.

    ///|
    test "native ABI is loaded" {
    inspect(abi_version(), content="1")
    let info = runtime_info().unwrap()
    inspect(info.abi_version, content="1")
    assert_true(info.build_mode == "abi-only" || info.build_mode == "runtime")
    assert_true(info.runtime_available == (info.build_mode == "runtime"))
    assert_true(info.features.contains("event_polling"))
    assert_true(info.features.contains("bridge_polling"))
    }

    Runtime configuration is typed on the MoonBit side and serialized to the stable proton_* C ABI JSON format.

    ///|
    test "typed runtime config JSON" {
    let config = RuntimeConfig::new(
    runtime_root="app-runtime",
    helper_path="cef_process.exe",
    cache_dir="cache",
    )
    let json = config.to_json_string()
    assert_true(json.contains("\"abi_version\":1"))
    assert_true(json.contains("\"runtime_root\":\"app-runtime\""))
    assert_true(json.contains("\"helper_path\":\"cef_process.exe\""))
    assert_true(json.contains("\"cache_dir\":\"cache\""))
    }

    For packaged Proton runtimes, prefer RuntimeConfig::bundled(). It asks proton.dll to use the install layout beside the loaded DLL, including bin/cef_process.exe, instead of requiring application code to hard-code paths.

    ///|
    test "bundled runtime config JSON" {
    let json = RuntimeConfig::bundled(cache_dir="cache").to_json_string()
    assert_true(json.contains("\"use_bundled\":true"))
    assert_true(json.contains("\"cache_dir\":\"cache\""))
    }

    The default no-engine build supports fake runtime/window handles for ABI and binding validation. Real runtime configs that include runtime_root or helper_path, or use RuntimeConfig::bundled(), are treated as engine configs and must pass RuntimeConfig::probe.

    ///|
    test "runtime and window lifecycle" {
    let runtime = Runtime::new().unwrap()
    let window = Window::new(
    runtime,
    config=WindowConfig::new(
    title="Proton",
    width=320,
    height=240,
    initial_url="about:blank",
    ),
    ).unwrap()
    match runtime.poll_event() {
    Ok(Some(event)) => inspect(event.event_type(), content="window_created")
    _ => fail("expected window_created")
    }
    debug_inspect(
    window.load_html("<p>Hello Proton</p>", "proton://app/"),
    content="Ok(())",
    )
    debug_inspect(window.destroy(), content="Ok(())")
    debug_inspect(runtime.destroy(), content="Ok(())")
    }

    Runtime::wait is a low-level pump primitive used by the root facade. It reports which kinds of work may be ready, and the caller still drains events or bridge requests through the poll APIs.

    ///|
    test "runtime wait event readiness" {
    let runtime = Runtime::new().unwrap()
    let empty = runtime
    .wait(interest_mask=runtime_wait_event, timeout_ms=0)
    .unwrap()
    inspect(empty.is_timeout(), content="true")
    let window = Window::new(runtime).unwrap()
    let ready = runtime
    .wait(interest_mask=runtime_wait_event, timeout_ms=0)
    .unwrap()
    inspect(ready.has_event(), content="true")
    match runtime.poll_event() {
    Ok(Some(event)) => inspect(event.event_type(), content="window_created")
    _ => fail("expected window_created")
    }
    debug_inspect(window.destroy(), content="Ok(())")
    debug_inspect(runtime.destroy(), content="Ok(())")
    }

    BridgeConfig

    pub(all) struct BridgeConfig {
    raw_json : String?
    ops : Array[String]
    max_payload_bytes : Int
    request_timeout_ms : Int
    dev_origins : Array[String]
    dev_bootstrap_script : String?
    } derive(Eq,
    Debug
    )

    BridgeConfig::new

    fn BridgeConfig::new(ops~ : Array[String], max_payload_bytes? : Int, request_timeout_ms? : Int, dev_origins? : Array[String], dev_bootstrap_script? : String?) -> BridgeConfig

    BridgeConfig::to_json_string

    fn BridgeConfig::to_json_string(self : BridgeConfig) -> String

    BridgeConfig::unsafe_from_json

    fn BridgeConfig::unsafe_from_json(raw_json : String) -> BridgeConfig

    BridgeRequest

    pub(all) struct BridgeRequest {
    request_id : Int64
    window : Int64
    op : String
    payload : Json
    page_instance : String?
    } derive(
    Debug
    )

    BridgeRequest::op

    fn BridgeRequest::op(self : BridgeRequest) -> String

    BridgeRequest::page_instance

    fn BridgeRequest::page_instance(self : BridgeRequest) -> String?

    BridgeRequest::payload

    fn BridgeRequest::payload(self : BridgeRequest) -> Json

    BridgeRequest::request_id

    fn BridgeRequest::request_id(self : BridgeRequest) -> Int64

    BridgeRequest::window

    fn BridgeRequest::window(self : BridgeRequest) -> Int64

    BridgeResponse

    pub(all) enum BridgeResponse {
    Ok(request_id~ : Int64, payload~ : Json)
    Err(request_id~ : Int64, code~ : String, message~ : String)
    } derive(
    Debug
    )

    BridgeResponse::to_json_string

    fn BridgeResponse::to_json_string(self : BridgeResponse) -> String

    NativeError

    pub(all) struct NativeError {
    status : Int
    message : String
    } derive(Eq,
    Debug
    )

    ProcessResult

    pub(all) enum ProcessResult {
    MainProcess
    SubprocessHandled(Int)
    } derive(Eq,
    Debug
    )

    Runtime

    type Runtime

    Runtime::destroy

    fn Runtime::destroy(self : Runtime) -> Result[Unit, NativeError]

    Runtime::do_message_loop_work

    fn Runtime::do_message_loop_work(self : Runtime) -> Result[Unit, NativeError]

    Runtime::new

    fn Runtime::new(config? : RuntimeConfig) -> Result[Runtime, NativeError]

    Runtime::poll_bridge_request

    fn Runtime::poll_bridge_request(self : Runtime) -> Result[BridgeRequest?, NativeError]

    Runtime::poll_bridge_request_json

    fn Runtime::poll_bridge_request_json(self : Runtime) -> Result[String?, NativeError]

    Runtime::poll_event

    fn Runtime::poll_event(self : Runtime) -> Result[RuntimeEvent?, NativeError]

    Runtime::poll_event_json

    fn Runtime::poll_event_json(self : Runtime) -> Result[String?, NativeError]

    Runtime::quit

    fn Runtime::quit(self : Runtime) -> Result[Unit, NativeError]

    Runtime::respond_bridge_request

    fn Runtime::respond_bridge_request(self : Runtime, response : BridgeResponse) -> Result[Unit, NativeError]

    Runtime::run

    fn Runtime::run(self : Runtime) -> Result[Unit, NativeError]

    Runtime::wait

    fn Runtime::wait(self : Runtime, interest_mask~ : Int, timeout_ms~ : Int) -> Result[RuntimeWaitReady, NativeError]

    RuntimeConfig

    type RuntimeConfig derive(Eq,
    Debug
    )

    RuntimeConfig::bundled

    fn RuntimeConfig::bundled(helper_path? : String, cache_dir? : String, remote_debugging_port? : Int) -> RuntimeConfig

    helper_path, when set, overrides the subprocess executable the bundled runtime launches. On macOS the helper must run from a nested .app so Chromium's outer-bundle walk yields the same base bundle id as the browser; otherwise the MachPort rendezvous service names mismatch and every child process terminates. Framework and resource discovery still run relative to the loaded libproton, so only the helper needs an explicit path.

    RuntimeConfig::new

    fn RuntimeConfig::new(runtime_root? : String, helper_path? : String, resources_dir? : String, locales_dir? : String, cache_dir? : String, remote_debugging_port? : Int) -> RuntimeConfig

    RuntimeConfig::probe

    fn RuntimeConfig::probe(self : RuntimeConfig) -> Result[Unit, NativeError]

    RuntimeConfig::to_json_string

    fn RuntimeConfig::to_json_string(self : RuntimeConfig) -> String

    RuntimeConfig::unsafe_from_json

    fn RuntimeConfig::unsafe_from_json(raw_json : String) -> RuntimeConfig

    RuntimeEvent

    type RuntimeEvent derive(Eq,
    Debug
    )

    RuntimeEvent::event_type

    fn RuntimeEvent::event_type(self : RuntimeEvent) -> String

    RuntimeEvent::has_window

    fn RuntimeEvent::has_window(self : RuntimeEvent) -> Bool

    RuntimeEvent::is_window_closed

    fn RuntimeEvent::is_window_closed(self : RuntimeEvent) -> Bool

    RuntimeEvent::is_window_created

    fn RuntimeEvent::is_window_created(self : RuntimeEvent) -> Bool

    RuntimeInfo

    pub(all) struct RuntimeInfo {
    abi_version : Int
    runtime_available : Bool
    build_mode : String
    platform : String
    features : Array[String]
    } derive(Eq,
    Debug
    ,
    FromJson
    )

    RuntimeWaitReady

    pub(all) struct RuntimeWaitReady {
    mask : Int
    } derive(Eq,
    Debug
    )

    RuntimeWaitReady::has_bridge

    fn RuntimeWaitReady::has_bridge(self : RuntimeWaitReady) -> Bool

    RuntimeWaitReady::has_event

    fn RuntimeWaitReady::has_event(self : RuntimeWaitReady) -> Bool

    RuntimeWaitReady::has_platform

    fn RuntimeWaitReady::has_platform(self : RuntimeWaitReady) -> Bool

    RuntimeWaitReady::is_timeout

    fn RuntimeWaitReady::is_timeout(self : RuntimeWaitReady) -> Bool

    RuntimeWaitReady::mask

    fn RuntimeWaitReady::mask(self : RuntimeWaitReady) -> Int

    Window

    type Window

    Window::close

    fn Window::close(self : Window) -> Result[Unit, NativeError]

    Window::destroy

    fn Window::destroy(self : Window) -> Result[Unit, NativeError]

    Window::eval

    fn Window::eval(self : Window, script : String) -> Result[Unit, NativeError]

    Window::focus

    fn Window::focus(self : Window) -> Result[Unit, NativeError]

    Window::hide

    fn Window::hide(self : Window) -> Result[Unit, NativeError]

    Window::install_bridge

    fn Window::install_bridge(self : Window, config : BridgeConfig) -> Result[Unit, NativeError]

    Window::load_html

    fn Window::load_html(self : Window, html : String, base_url : String) -> Result[Unit, NativeError]

    Window::load_url

    fn Window::load_url(self : Window, url : String) -> Result[Unit, NativeError]

    Window::new

    fn Window::new(runtime : Runtime, config? : WindowConfig) -> Result[Window, NativeError]

    Window::set_size

    fn Window::set_size(self : Window, width : Int, height : Int) -> Result[Unit, NativeError]

    Window::set_title

    fn Window::set_title(self : Window, title : String) -> Result[Unit, NativeError]

    Window::show

    fn Window::show(self : Window) -> Result[Unit, NativeError]

    WindowConfig

    type WindowConfig derive(Eq,
    Debug
    )

    WindowConfig::new

    fn WindowConfig::new(title? : String, width? : Int, height? : Int, initial_url? : String) -> WindowConfig

    WindowConfig::to_json_string

    fn WindowConfig::to_json_string(self : WindowConfig) -> String

    WindowConfig::unsafe_from_json

    fn WindowConfig::unsafe_from_json(raw_json : String) -> WindowConfig

    abi_version

    fn abi_version() -> Int

    execute_process

    fn execute_process(config? : RuntimeConfig) -> Result[ProcessResult, NativeError]

    last_error_message

    fn last_error_message() -> String

    probe_runtime

    fn probe_runtime(config? : RuntimeConfig) -> Result[Unit, NativeError]

    runtime_info

    fn runtime_info() -> Result[RuntimeInfo, NativeError]

    runtime_info_json

    fn runtime_info_json() -> Result[String, NativeError]

    runtime_wait_all

    let runtime_wait_all : Int

    runtime_wait_bridge

    let runtime_wait_bridge : Int

    runtime_wait_event

    let runtime_wait_event : Int

    runtime_wait_none

    let runtime_wait_none : Int

    runtime_wait_platform

    let runtime_wait_platform : Int