README

#proton/core

moonbit-community/proton/core owns the bridge between native MoonBit code and page JavaScript.

It provides:

  • op registration and dispatch
  • command host dispatch over the IPC protocol
  • window.__MoonBit__ bridge wiring
  • extension events

Application lifecycle and app composition belong in the root proton facade, which drives the native Proton dynamic library.

#
CommandPermissionError

pub(all) suberror CommandPermissionError {
Missing(extension_id~ : String)
Foreign(expected~ : String, actual~ : String)
} derive(Eq,
Debug
)

A command attempted to use a capability outside its request grant.

#
CommandPermissionError::message

fn CommandPermissionError::message(self : CommandPermissionError) -> String

#
OpDispatchError

pub(all) suberror OpDispatchError {
InvalidPayload(name~ : String, detail~ : String)
UnknownOp(name~ : String)
HandlerFailed(name~ : String, detail~ : String)
HostClosed
AsyncHandlerRequiresAsync(name~ : String)
} derive(Eq,
Debug
)

Failures while decoding and invoking one registered operation.

#
OpDispatchError::message

fn OpDispatchError::message(self : OpDispatchError) -> String

#
OpRegistrationError

pub(all) suberror OpRegistrationError {
EmptyName
DuplicateName(name~ : String)
HostClosed
RegistrationSealed
} derive(Eq,
Debug
)

Failures while adding command handlers to an operation registry.

#
OpRegistrationError::message

fn OpRegistrationError::message(self : OpRegistrationError) -> String

#
AppCommandHost

type AppCommandHost

Command host for user app code.

The framework decides how this host is connected to the window runtime. App authors register commands and run the host without depending on the underlying IPC implementation.

#
AppCommandHost::close

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

Closes this command host and rejects future dispatches.

#
AppCommandHost::dispatch_ipc

Dispatches one IPC request on the current async loop.

#
AppCommandHost::dispatch_ipc_with_context

Dispatches one IPC request with request-scoped context.

#
AppCommandHost::new

fn AppCommandHost::new(expose_error_details? : Bool) -> AppCommandHost

Creates an empty app command host.

Handler diagnostics remain in backend logs by default. Set expose_error_details only for a trusted development frontend.

#
AppCommandHost::op

fn[Payload :
FromJson
, Reply : ToJson] AppCommandHost::op(self : AppCommandHost, name : String, callback : (Payload) -> Reply raise?) -> Unit raise OpRegistrationError

Registers a synchronous app command.

#
AppCommandHost::op_async

fn[Payload :
FromJson
, Reply : ToJson] AppCommandHost::op_async(self : AppCommandHost, name : String, callback : async (Payload) -> Reply) -> Unit raise OpRegistrationError

Registers an async app command.

#
AppCommandHost::op_async_with_context

fn[Payload :
FromJson
, Reply : ToJson] AppCommandHost::op_async_with_context(self : AppCommandHost, name : String, callback : async (AppCommandRequestContext, Payload) -> Reply) -> Unit raise OpRegistrationError

Registers an async app command that receives request-scoped context.

#
AppCommandHost::registered_ops

fn AppCommandHost::registered_ops(self : AppCommandHost) -> Array[String]

Returns registered command names in registration order.

#
AppCommandHost::seal_registrations

fn AppCommandHost::seal_registrations(self : AppCommandHost) -> Unit

Prevents later command registration while keeping existing commands usable.

#
AppCommandRequestContext

pub struct AppCommandRequestContext {
window : Int64
window_id : String
source_origin : String
page_instance : String?
permission_extension : String?
permission_scope_value : Json?
tasks :
TaskGroup
[Unit]
wake_signal : RuntimeWakeSignal
emit_event : async (
ContractRoute
, String, Json) -> Unit noraise
}

Request-scoped context for one bridged app command dispatch.

#
AppCommandRequestContext::emit

async fn[Payload : ToJson] AppCommandRequestContext::emit(self : AppCommandRequestContext, event :
Event
[Payload], payload : Payload) -> Unit

Emits a typed event to the renderer page that issued this command.

#
AppCommandRequestContext::page_instance

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

Returns the renderer page instance that issued this request, when the context came from the native bridge.

#
AppCommandRequestContext::permission_scope

fn AppCommandRequestContext::permission_scope(self : AppCommandRequestContext, extension_id : String) -> Json raise CommandPermissionError

Returns this request's extension-specific permission scope.

#
AppCommandRequestContext::source_origin

fn AppCommandRequestContext::source_origin(self : AppCommandRequestContext) -> String

#
AppCommandRequestContext::task_group

Returns the task group owned by this command lifecycle.

Child tasks are cancelled and joined when the issuing window closes.

#
AppCommandRequestContext::wait_for_wake

async fn AppCommandRequestContext::wait_for_wake(self : AppCommandRequestContext, revision : Int64) -> Unit

#
AppCommandRequestContext::wake_revision

fn AppCommandRequestContext::wake_revision(self : AppCommandRequestContext) -> Int64

#
AppCommandRequestContext::wake_signal

#
AppCommandRequestContext::window

#
AppCommandRequestContext::window_id

fn AppCommandRequestContext::window_id(self : AppCommandRequestContext) -> String

#
MbtProcessHost

type MbtProcessHost

Command host intended to run in the MBT process.

The host is independent from the browser window, so application code can use normal MoonBit syntax, state, and async handlers without living in the GUI process.

#
MbtProcessHost::close

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

Closes this host and rejects future dispatches.

#
MbtProcessHost::dispatch_async

Dispatches one decoded IPC request on the current async loop.

User command hosts use this path so async ops run inside the user process event loop instead of creating a nested event loop elsewhere.

#
MbtProcessHost::dispatch_async_with_context

Dispatches one decoded IPC request with request-scoped context.

#
MbtProcessHost::new

fn MbtProcessHost::new(expose_error_details? : Bool) -> MbtProcessHost

Creates an empty MBT-side command host.

Handler diagnostics remain in backend logs by default. Set expose_error_details only for a trusted development frontend.

#
MbtProcessHost::op

fn[Payload :
FromJson
, Reply : ToJson] MbtProcessHost::op(self : MbtProcessHost, name : String, callback : (Payload) -> Reply raise?) -> Unit raise OpRegistrationError

Registers a synchronous MBT-side op.

#
MbtProcessHost::op_async

fn[Payload :
FromJson
, Reply : ToJson] MbtProcessHost::op_async(self : MbtProcessHost, name : String, callback : async (Payload) -> Reply) -> Unit raise OpRegistrationError

Registers an async MBT-side op.

#
MbtProcessHost::op_async_with_context

fn[Payload :
FromJson
, Reply : ToJson] MbtProcessHost::op_async_with_context(self : MbtProcessHost, name : String, callback : async (AppCommandRequestContext, Payload) -> Reply) -> Unit raise OpRegistrationError

Registers an async MBT-side op that receives request-scoped context.

#
MbtProcessHost::registered_ops

fn MbtProcessHost::registered_ops(self : MbtProcessHost) -> Array[String]

Returns registered op names in registration order.

#
RuntimeWakeSignal

pub struct RuntimeWakeSignal {
revision : Int64
condition :
Cond

}

Scheduler-local notification shared by the runtime pump and command tasks. The revision makes waiting race-free when a notification arrives between a native poll and suspension on the condition variable.

#
RuntimeWakeSignal::new

#
RuntimeWakeSignal::notify

fn RuntimeWakeSignal::notify(self : RuntimeWakeSignal) -> Unit

#
RuntimeWakeSignal::revision

fn RuntimeWakeSignal::revision(self : RuntimeWakeSignal) -> Int64

#
RuntimeWakeSignal::wait_for_change

async fn RuntimeWakeSignal::wait_for_change(self : RuntimeWakeSignal, revision : Int64) -> Unit

#
TemplateReplacement

type TemplateReplacement

#
moonbit_global_name

fn moonbit_global_name() -> String

Returns the root JavaScript namespace used by Proton runtime helpers. JavaScript bridges and generated helper scripts should agree on this value when exposing Proton functionality on window.

#
moonbit_op_binding_name

fn moonbit_op_binding_name() -> String

Returns the native binding name used by the op bridge. Native dispatch glue and injected runtime scripts both use this name to route op calls through the same binding.

#
render_js_template

fn render_js_template(template : String, replacements : Array[TemplateReplacement]) -> String

Applies a sequence of token replacements to a JavaScript template string. Replacements are processed in order, which allows later entries to build on earlier substitutions when generating runtime helper scripts.

#
replacement

fn replacement(token : String, value : String) -> TemplateReplacement

Creates a single token replacement entry for render_js_template. This keeps call sites readable when several template tokens need to be substituted together.

Powered by MoonBit

Site sourceReport issuePackagesBuild queueSkillsStatistics

© 2026 mooncakes.io