lepus-apps/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
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 below is aligned with pkg.generated.mbti.
- 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
- 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 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
- 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}
- 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::new(...) and WebView::new_managed(...) support:
frameless : Boolresizable : Boolalways_on_top : Booltransparent : Booltitle_bar_style : Int(0default,1hidden)title_bar_overlay : Bool
Constants:
@webview.TITLE_BAR_STYLE_DEFAULT@webview.TITLE_BAR_STYLE_HIDDEN
For custom title bars, Lepus injects drag helpers automatically when one of the following is true:
frameless = truetitle_bar_style = TITLE_BAR_STYLE_HIDDENtitle_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;
}Run the included demo:
moon build --target native example
moon run --target native exampleMinimal managed-window example:
///|
fn main {
let win = @webview.Window::new(title="Lepus WebView", width=960, height=640)
win.set_html("<html><body><h1>Hello from MoonBit</h1></body></html>")
win.run()
}moon check
moon test --target native
moon build --target nativeApache-2.0