MoonBit bindings for the Proton native desktop runtime.
Dependencies
async fn main {
@proton.html("Hello", "<h1>Hello</h1>").run_or_abort()
}@proton.config("proton.project.json")
.commands(fn(registrar) raise { registrar.bind(ping_command, ping) })
.run_or_abort()const reply = await window.__MoonBit__.core.invokeOp("ext:app/ping", {
name: "proton",
});
window.__MoonBit__.events.on("app.tick", (event) => console.log(event.payload));@proton.html("Main", main_html)
.add_window(
"settings",
"Settings",
@proton.AppEntry::Html(settings_html),
width=420,
height=320,
)pub(all) suberror AppCleanupError {
CommandExtension(CommandExtensionLifecycleError)
LifecycleHook(LifecycleHookError)
WindowDestroy(NativeError)
RuntimeDestroy(NativeError)
} derive(Debug)pub(all) suberror AppConfigurationError {
InvalidSetting(name~ : String, message~ : String)
Bootstrap(BootstrapError)
ExtensionDependencyCycle(extension_id~ : String)
ExtensionUnavailable(extension_id~ : String, requested_by~ : String?, state~ : String)
ExtensionAdaptationFailed(extension_id~ : String, error~ : ExtensionAdapterError)
InvalidJavaScriptNamespace(js_namespace~ : String)
InvalidJavaScriptApi(js_namespace~ : String, api_name~ : String)
InvalidEntryUrl(url~ : String, reason~ : String)
InvalidPermissionGrant(detail~ : String)
MissingPermissionGrant(extension_id~ : String)
} derive(Debug)pub(all) suberror AppEntryError {
ReadFailed(path~ : String, detail~ : String)
NativeLoad(action~ : String, error~ : NativeError)
ClosedDuringStartup
} derive(Debug)pub(all) suberror AppPathError {
InvalidIdentifier(identifier~ : String)
MissingHomeDirectory(platform~ : String)
PlatformProbe(NativeError)
} derive(Eq, Debug)pub(all) suberror AppRunError {
EventLoopError(String)
ConfigurationError(AppConfigurationError)
UnsupportedNativeFeature(feature~ : String)
NativeRuntimeError(action~ : String, error~ : NativeError)
CommandExtensionLifecycleError(CommandExtensionLifecycleError)
LifecycleHookError(LifecycleHookError)
EntryLoadError(AppEntryError)
BridgeStartupError(BridgeDiagnostic)
BridgeRuntimeError(BridgeDiagnostic)
CleanupFailed(primary~ : String?, failures~ : Array[AppCleanupError])
UnexpectedTaskFailure(detail~ : String)
} derive(Debug)pub(all) suberror CommandExtensionLifecycleError {
ApplicationRegistrationFailed(detail~ : String)
RegistrationFailed(extension_id~ : String, detail~ : String)
DestroyFailed(extension_id~ : String, detail~ : String)
} derive(Debug)pub(all) suberror LifecycleHookError {
ApplicationStart(index~ : Int, detail~ : String)
ApplicationShutdown(index~ : Int, detail~ : String)
WindowReady(index~ : Int, detail~ : String)
WindowClose(index~ : Int, detail~ : String)
} derive(Debug)pub(all) suberror NotificationDeliveryError {
Native(NativeError)
WaitInterrupted(detail~ : String)
} derive(Eq, Debug)pub(all) suberror WindowSessionError {
UnknownWindow(id~ : String)
AlreadyOpen(id~ : String)
StaleWindow(id~ : String)
UnknownView(id~ : String)
AlreadyExists(id~ : String)
StaleView(id~ : String)
Cancelled
OperationFailed(action~ : String, error~ : NativeError)
StartupFailed(id~ : String, error~ : AppRunError)
} derive(Debug)type Appfn App::add_window(self : App, id : String, title : String, entry : AppEntry, width? : Int, height? : Int, size_hint? : WindowSizeHint, titlebar_style? : TitlebarStyle, open_on_start? : Bool) -> Appfn[State] App::app_lifecycle(self : App, on_start~ : async (ApplicationContext) -> State, on_shutdown~ : async (State) -> Unit) -> Appfn App::on_certificate_error(self : App, handler : async (BrowserHandle, CertificateError) -> BrowserPermissionDecision noraise) -> Appfn App::on_download_event(self : App, handler : async (BrowserHandle, DownloadEvent) -> Unit noraise) -> Appfn App::on_download_request(self : App, handler : async (BrowserHandle, DownloadRequest) -> DownloadDecision noraise) -> Appfn App::on_media_permission_request(self : App, handler : async (BrowserHandle, MediaPermissionRequest) -> BrowserPermissionDecision noraise) -> Appfn App::on_navigation_request(self : App, handler : async (BrowserHandle, NavigationRequest) -> NavigationDecision noraise) -> Appfn App::on_popup_request(self : App, handler : async (BrowserHandle, PopupRequest) -> PopupDecision noraise) -> Appfn App::on_window_close_request(self : App, handler : async (WindowHandle) -> WindowCloseDecision noraise) -> Appfn App::on_window_event(self : App, handler : async (WindowHandle, WindowEvent) -> Unit noraise) -> Appfn[State] App::window_lifecycle(self : App, on_ready~ : async (WindowContext) -> State, on_close~ : async (State) -> Unit) -> Apppub struct BrowserHandle {
id : String
native_id : Int64
load_browser_url : (String) -> Unit raise WindowSessionError
load_browser_html : (String, String) -> Unit raise WindowSessionError
eval_browser_script : (String) -> Unit raise WindowSessionError
send_browser_command : (String, Int?) -> Unit raise WindowSessionError
}fn BrowserHandle::cancel_download(self : BrowserHandle, download_id : Int) -> Unit raise WindowSessionErrorfn BrowserHandle::load_html(self : BrowserHandle, html : String, base_url : String) -> Unit raise WindowSessionErrorfn BrowserHandle::reload(self : BrowserHandle, ignore_cache? : Bool) -> Unit raise WindowSessionErrorpub struct PendingUpdate {
version : String
revision : UInt64
notes_url : String?
size : Int64
channel : UpdateChannel
offer : AvailableUpdate
}async fn PendingUpdate::install(self : PendingUpdate, on_progress? : async (Int64) -> Unit noraise) -> UpdateInstallOutcomepub struct ViewHandle {
id : String
native_id : Int64
set_view_bounds : (Int, Int, Int, Int) -> Unit raise WindowSessionError
set_view_visible : (Bool) -> Unit raise WindowSessionError
set_view_z_order : (Int) -> Unit raise WindowSessionError
load_view_url : (String) -> Unit raise WindowSessionError
load_view_html : (String, String) -> Unit raise WindowSessionError
eval_view_script : (String) -> Unit raise WindowSessionError
send_view_command : (String, Int?) -> Unit raise WindowSessionError
read_view_state : () -> ViewState raise WindowSessionError
close_view : () -> Unit raise WindowSessionError
}fn ViewHandle::load_html(self : ViewHandle, html : String, base_url : String) -> Unit raise WindowSessionErrorfn ViewHandle::set_bounds(self : ViewHandle, x~ : Int, y~ : Int, width~ : Int, height~ : Int) -> Unit raise WindowSessionErrorpub struct WindowContext {
id : String
window : WindowRef
handle : WindowHandle
windows : WindowManager
tasks : TaskGroup[Unit]
events : WindowEventEmitter
}async fn[Payload : ToJson] WindowEventEmitter::emit(self : WindowEventEmitter, event : Event[Payload], payload : Payload) -> Unitpub struct WindowHandle {
id : String
native_id : Int64
show_window : () -> Unit raise WindowSessionError
hide_window : () -> Unit raise WindowSessionError
close_window : () -> Unit raise WindowSessionError
focus_window : () -> Unit raise WindowSessionError
set_window_title : (String) -> Unit raise WindowSessionError
set_window_size : (Int, Int) -> Unit raise WindowSessionError
minimize_window : () -> Unit raise WindowSessionError
maximize_window : () -> Unit raise WindowSessionError
restore_window : () -> Unit raise WindowSessionError
set_window_fullscreen : (Bool) -> Unit raise WindowSessionError
set_window_position : (Int, Int) -> Unit raise WindowSessionError
set_window_always_on_top : (Bool) -> Unit raise WindowSessionError
set_window_zoom_percent : (Int) -> Unit raise WindowSessionError
read_window_state : () -> WindowState raise WindowSessionError
browser : BrowserHandle
add_view : (String, ViewConfig) -> ViewHandle raise WindowSessionError
remove_view : (String) -> Unit raise WindowSessionError
list_views : () -> Array[ViewHandle]
find_view : (String) -> ViewHandle?
}fn WindowHandle::add_view(self : WindowHandle, id : String, config : ViewConfig) -> ViewHandle raise WindowSessionErrorfn WindowHandle::set_always_on_top(self : WindowHandle, always_on_top : Bool) -> Unit raise WindowSessionErrorfn WindowHandle::set_fullscreen(self : WindowHandle, fullscreen : Bool) -> Unit raise WindowSessionErrorfn WindowHandle::set_position(self : WindowHandle, x : Int, y : Int) -> Unit raise WindowSessionErrorfn WindowHandle::set_size(self : WindowHandle, width : Int, height : Int) -> Unit raise WindowSessionErrorfn WindowHandle::set_zoom_percent(self : WindowHandle, zoom_percent : Int) -> Unit raise WindowSessionErrorpub struct WindowManager {
open_window : async (String) -> WindowHandle raise WindowSessionError
find_window : (String) -> WindowHandle?
}async fn WindowManager::open(self : WindowManager, id : String) -> WindowHandle raise WindowSessionErrorfn asset(title : String, path : String, width? : Int, height? : Int, debug? : Bool, resizable? : Bool) -> Appfn file(title : String, path : String, width? : Int, height? : Int, debug? : Bool, resizable? : Bool) -> Appfn html(title : String, html : String, width? : Int, height? : Int, debug? : Bool, resizable? : Bool) -> Appfn url(title : String, url : String, width? : Int, height? : Int, debug? : Bool, resizable? : Bool) -> Appfn view(url : String, width~ : Int, height~ : Int, x? : Int, y? : Int, visible? : Bool, z_order? : Int, background_color? : String) -> ViewConfigMoonBit bindings for the Proton native desktop runtime.
Dependencies