MoonBit bindings for the Proton native desktop runtime.
Dependencies
async fn main {
@proton.html("Hello", "<h1>Hello</h1>")
.identifier("dev.proton.hello")
.run_or_abort()
}@proton.html("Commands", html)
.identifier("dev.proton.commands")
.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(status~ : Int, detail~ : String)
RuntimeDestroy(status~ : Int, detail~ : String)
} derive(Debug)pub(all) suberror AppConfigurationError {
InvalidSetting(name~ : String, message~ : String)
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)
InvalidRendererCapability(detail~ : String)
} derive(Debug)pub(all) suberror AppEntryError {
ReadFailed(path~ : String, detail~ : String)
PlatformLoad(action~ : String, status~ : Int, detail~ : String)
ClosedDuringStartup
} derive(Debug)pub(all) suberror AppPathError {
MissingApplicationIdentifier
InvalidIdentifier(identifier~ : String)
MissingHomeDirectory(platform~ : String)
MissingEnvironmentPath(name~ : String, platform~ : String)
MissingExecutablePath
UnsupportedPath(kind~ : String, platform~ : String)
InvalidPathOverride(kind~ : String, path~ : String, reason~ : String)
SystemPath(kind~ : String, status~ : Int, detail~ : String)
PlatformProbe(status~ : Int, detail~ : String)
} derive(Eq, Debug)pub(all) suberror AppRunError {
EventLoopError(String)
ConfigurationError(AppConfigurationError)
LoggingInitializationFailed(detail~ : String)
UnsupportedNativeFeature(feature~ : String)
RuntimeOperationFailed(action~ : String, status~ : Int, detail~ : String)
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)
EventSourceStartFailed(extension_id~ : String, detail~ : String)
DestroyFailed(extension_id~ : String, detail~ : String)
} derive(Debug)fn CommandExtensionLifecycleError::output(self : CommandExtensionLifecycleError, logger : &Logger) -> Unitpub(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)fn NotificationDeliveryError::not_equal(x : NotificationDeliveryError, y : NotificationDeliveryError) -> Boolpub(all) suberror WindowSessionError {
UnknownWindow(id~ : String)
AlreadyOpen(id~ : String)
ApplicationQuitting
StaleWindow(id~ : String)
UnknownView(id~ : String)
AlreadyExists(id~ : String)
StaleView(id~ : String)
Cancelled
OperationFailed(action~ : String, status~ : Int, detail~ : String)
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::capability(self : App, capability : RendererCapability, targets? : Array[RendererTarget]) -> Appfn App::commands(self : App, register : (CommandRegistrar) -> Unit raise, targets? : Array[RendererTarget]) -> Appfn App::on_browser_event(self : App, handler : async (BrowserHandle, BrowserEvent) -> Unit noraise) -> 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_launch_input(self : App, handler : async (ApplicationContext, RuntimeLaunchInput) -> Unit 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 ApplicationContext {
tasks : TaskGroup[Unit]
windows : WindowManager
locale_preferences : LocalePreferences
request_quit : () -> Unit
application_identifier : String
application_executable : String
application_arguments : Array[String]
url_schemes : Array[String]
}fn ApplicationContext::is_default_protocol_client(self : ApplicationContext, scheme : String, executable? : String, arguments? : Array[String]) -> Bool raise AppControlErrorfn ApplicationContext::relaunch(self : ApplicationContext, options? : RelaunchOptions) -> Unit raise AppControlErrorfn ApplicationContext::remove_default_protocol_client(self : ApplicationContext, scheme : String, executable? : String, arguments? : Array[String]) -> Bool raise AppControlErrorfn ApplicationContext::set_as_default_protocol_client(self : ApplicationContext, scheme : String, executable? : String, arguments? : Array[String]) -> Bool raise AppControlErrorpub(all) enum BrowserEvent {
LoadingChanged(is_loading~ : Bool)
Navigated(url~ : String)
TitleUpdated(title~ : String)
LoadFailed(url~ : String, error_code~ : Int, error_text~ : String)
FoundInPage(result~ : FindInPageResult)
PdfPrinted(result~ : PdfPrintResult)
} derive(Eq, Debug)pub 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
focus_browser : () -> Unit raise WindowSessionError
send_browser_command : (String, Int?) -> Unit raise WindowSessionError
download_browser_url : (String) -> Unit raise WindowSessionError
print_browser : () -> Unit raise WindowSessionError
print_browser_to_pdf : (String, PdfPrintOptions) -> Int raise WindowSessionError
find_browser_in_page : (String, Bool, Bool, Bool) -> Int raise WindowSessionError
stop_browser_find : (Bool) -> Unit raise WindowSessionError
set_browser_zoom_percent : (Int) -> Unit raise WindowSessionError
read_browser_zoom_percent : () -> Int raise WindowSessionError
set_browser_audio_muted : (Bool) -> Unit raise WindowSessionError
read_browser_audio_muted : () -> Bool raise WindowSessionError
read_browser_navigation_state : () -> (Bool, Bool) raise WindowSessionError
read_browser_focused : () -> Bool raise WindowSessionError
read_browser_devtools_opened : () -> Bool raise WindowSessionError
read_browser_state : () -> BrowserState raise WindowSessionError
session_handle : SessionHandle
}fn BrowserHandle::cancel_download(self : BrowserHandle, download_id : Int) -> Unit raise WindowSessionErrorfn BrowserHandle::find_in_page(self : BrowserHandle, text : String, forward? : Bool, match_case? : Bool, find_next? : Bool) -> Int raise WindowSessionErrorfn BrowserHandle::load_html(self : BrowserHandle, html : String, base_url : String) -> Unit raise WindowSessionErrorfn BrowserHandle::print_to_pdf(self : BrowserHandle, path : String, options? : PdfPrintOptions) -> Int raise WindowSessionErrorfn BrowserHandle::reload(self : BrowserHandle, ignore_cache? : Bool) -> Unit raise WindowSessionErrorfn BrowserHandle::set_audio_muted(self : BrowserHandle, muted : Bool) -> Unit raise WindowSessionErrorfn BrowserHandle::set_zoom_percent(self : BrowserHandle, zoom_percent : Int) -> Unit raise WindowSessionErrorfn BrowserHandle::stop_find_in_page(self : BrowserHandle, clear_selection? : Bool) -> Unit raise WindowSessionErrorfn BrowserPermissionDecision::not_equal(x : BrowserPermissionDecision, y : BrowserPermissionDecision) -> Boolpub(all) struct Cookie {
name : String
value : String
domain : String
path : String
secure : Bool
http_only : Bool
same_site : CookieSameSite
expiration_date : Double?
} derive(Eq, Debug)fn LastWindowClosedPolicy::not_equal(x : LastWindowClosedPolicy, y : LastWindowClosedPolicy) -> Boolfn MediaPermissionRequest::not_equal(x : MediaPermissionRequest, y : MediaPermissionRequest) -> Boolfn Menu::popup(self : Menu, window : WindowHandle, x : Int, y : Int) -> Unit raise WindowSessionErrorpub struct MenuItem {
kind : Int
id : String?
label : String?
key : String?
role : MenuItemRole?
submenu : Menu?
enabled : Bool
visible : Bool
checked : Bool?
}pub(all) struct PdfPrintOptions {
landscape : Bool
print_background : Bool
scale : Double
paper_width : Double
paper_height : Double
prefer_css_page_size : Bool
margins : PdfPrintMargins
page_ranges : String
display_header_footer : Bool
header_template : String
footer_template : String
generate_tagged_pdf : Bool
generate_document_outline : Bool
} derive(Eq, Debug)fn PdfPrintOptions::PdfPrintOptions(landscape? : Bool, print_background? : Bool, scale? : Double, paper_width? : Double, paper_height? : Double, prefer_css_page_size? : Bool, margins? : PdfPrintMargins, page_ranges? : String, display_header_footer? : Bool, header_template? : String, footer_template? : String, generate_tagged_pdf? : Bool, generate_document_outline? : Bool) -> PdfPrintOptionspub 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) -> UpdateInstallOutcomefn RelaunchOptions::RelaunchOptions(executable? : String, arguments? : Array[String]) -> RelaunchOptionspub struct RendererTarget {
window : String
bundled : Bool
}pub struct SessionHandle {
id : String
native_id : Int64
read_cookies : async (String?, Bool) -> Array[Cookie] raise WindowSessionError
write_cookie : (String, String, String, String?, String?, Bool, Bool, CookieSameSite) -> Unit raise WindowSessionError
remove_cookies : (String?, String?) -> Unit raise WindowSessionError
flush_cookie_store : () -> Unit raise WindowSessionError
clear_http_cache : () -> Unit raise WindowSessionError
}fn SessionHandle::delete_cookies(self : SessionHandle, url? : String, name? : String) -> Unit raise WindowSessionErrorasync fn SessionHandle::get_cookies(self : SessionHandle, url? : String, include_http_only? : Bool) -> Array[Cookie] raise WindowSessionErrorfn SessionHandle::set_cookie(self : SessionHandle, url : String, name : String, value : String, domain? : String, path? : String, secure? : Bool, http_only? : Bool, same_site? : CookieSameSite) -> Unit raise WindowSessionErrorpub struct ViewConfig {
x : Int
y : Int
width : Int
height : Int
visible : Bool
z_order : Int
initial_url : String
background_color : String?
}fn ViewConfig::ViewConfig(width~ : Int, height~ : Int, x? : Int, y? : Int, visible? : Bool, z_order? : Int, initial_url? : String, background_color? : String) -> ViewConfigpub(all) enum ViewEvent {
LoadingChanged(is_loading~ : Bool)
Navigated(url~ : String)
TitleUpdated(title~ : String)
LoadFailed(url~ : String, error_code~ : Int, error_text~ : String)
FoundInPage(result~ : FindInPageResult)
Closed
} derive(Eq, Debug)pub 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
set_view_zoom_percent : (Int) -> Unit raise WindowSessionError
read_view_zoom_percent : () -> Int raise WindowSessionError
set_view_audio_muted : (Bool) -> Unit raise WindowSessionError
read_view_audio_muted : () -> Bool raise WindowSessionError
load_view_url : (String) -> Unit raise WindowSessionError
load_view_html : (String, String) -> Unit raise WindowSessionError
eval_view_script : (String) -> Unit raise WindowSessionError
focus_view : () -> Unit raise WindowSessionError
send_view_command : (String, Int?) -> Unit raise WindowSessionError
find_view_in_page : (String, Bool, Bool, Bool) -> Int raise WindowSessionError
stop_view_find : (Bool) -> Unit raise WindowSessionError
read_view_navigation_state : () -> (Bool, Bool) raise WindowSessionError
read_view_focused : () -> Bool raise WindowSessionError
read_view_devtools_opened : () -> Bool raise WindowSessionError
read_view_state : () -> ViewState raise WindowSessionError
close_view : () -> Unit raise WindowSessionError
}fn ViewHandle::find_in_page(self : ViewHandle, text : String, forward? : Bool, match_case? : Bool, find_next? : Bool) -> Int raise WindowSessionErrorfn 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 WindowSessionErrorfn ViewHandle::set_zoom_percent(self : ViewHandle, zoom_percent : Int) -> Unit raise WindowSessionErrorfn ViewHandle::stop_find_in_page(self : ViewHandle, clear_selection? : Bool) -> Unit raise WindowSessionErrorpub struct WindowContext {
id : String
handle : WindowHandle
windows : WindowManager
tasks : TaskGroup[Unit]
events : WindowEventEmitter
locale_preferences : LocalePreferences
}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
show_window_inactive : () -> 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_icon : (String) -> Unit raise WindowSessionError
set_window_parent : (WindowHandle?, Bool) -> Unit raise WindowSessionError
set_window_size : (Int, Int) -> Unit raise WindowSessionError
set_window_content_size : (Int, Int) -> Unit raise WindowSessionError
read_window_content_size : () -> (Int, Int) 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_kiosk : (Bool) -> Unit raise WindowSessionError
set_window_position : (Int, Int) -> Unit raise WindowSessionError
set_window_always_on_top : (Bool) -> Unit raise WindowSessionError
set_window_resizable : (Bool) -> Unit raise WindowSessionError
set_window_minimum_size : (Int, Int) -> Unit raise WindowSessionError
set_window_maximum_size : (Int, Int) -> Unit raise WindowSessionError
set_window_aspect_ratio : (Double) -> Unit raise WindowSessionError
set_window_movable : (Bool) -> Unit raise WindowSessionError
set_window_opacity : (Double) -> Unit raise WindowSessionError
set_window_skip_taskbar : (Bool) -> Unit raise WindowSessionError
set_window_content_protection : (Bool) -> Unit raise WindowSessionError
set_window_minimizable : (Bool) -> Unit raise WindowSessionError
set_window_maximizable : (Bool) -> Unit raise WindowSessionError
set_window_closable : (Bool) -> Unit raise WindowSessionError
set_window_button_visibility : (Bool) -> Unit raise WindowSessionError
set_window_focusable : (Bool) -> Unit raise WindowSessionError
set_window_fullscreenable : (Bool) -> Unit raise WindowSessionError
set_window_has_shadow : (Bool) -> Unit raise WindowSessionError
set_window_ignore_mouse_events : (Bool, Bool) -> Unit raise WindowSessionError
set_window_background_color : (String) -> Unit raise WindowSessionError
set_window_visible_on_all_workspaces : (Bool) -> Unit raise WindowSessionError
set_window_enabled : (Bool) -> Unit raise WindowSessionError
set_window_menu : (MenuBar?) -> Unit raise WindowSessionError
set_window_zoom_percent : (Int) -> Unit raise WindowSessionError
set_window_progress_bar : (Double) -> Unit raise WindowSessionError
flash_window_frame : (Bool) -> Unit raise WindowSessionError
popup_window_menu : (Menu, Int, 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_aspect_ratio(self : WindowHandle, aspect_ratio : Double) -> Unit raise WindowSessionErrorfn WindowHandle::set_background_color(self : WindowHandle, color : String) -> Unit raise WindowSessionErrorfn WindowHandle::set_bounds(self : WindowHandle, x~ : Int, y~ : Int, width~ : Int, height~ : Int) -> Unit raise WindowSessionErrorfn WindowHandle::set_closable(self : WindowHandle, closable : Bool) -> Unit raise WindowSessionErrorfn WindowHandle::set_content_protection(self : WindowHandle, enabled : Bool) -> Unit raise WindowSessionErrorfn WindowHandle::set_content_size(self : WindowHandle, width : Int, height : Int) -> Unit raise WindowSessionErrorfn WindowHandle::set_focusable(self : WindowHandle, focusable : Bool) -> Unit raise WindowSessionErrorfn WindowHandle::set_fullscreen(self : WindowHandle, fullscreen : Bool) -> Unit raise WindowSessionErrorfn WindowHandle::set_fullscreenable(self : WindowHandle, fullscreenable : Bool) -> Unit raise WindowSessionErrorfn WindowHandle::set_has_shadow(self : WindowHandle, has_shadow : Bool) -> Unit raise WindowSessionErrorfn WindowHandle::set_ignore_mouse_events(self : WindowHandle, ignore : Bool, forward : Bool) -> Unit raise WindowSessionErrorfn WindowHandle::set_maximizable(self : WindowHandle, maximizable : Bool) -> Unit raise WindowSessionErrorfn WindowHandle::set_maximum_size(self : WindowHandle, width : Int, height : Int) -> Unit raise WindowSessionErrorfn WindowHandle::set_minimizable(self : WindowHandle, minimizable : Bool) -> Unit raise WindowSessionErrorfn WindowHandle::set_minimum_size(self : WindowHandle, width : Int, height : Int) -> Unit raise WindowSessionErrorfn WindowHandle::set_opacity(self : WindowHandle, opacity : Double) -> Unit raise WindowSessionErrorfn WindowHandle::set_parent(self : WindowHandle, parent : WindowHandle?, modal? : Bool) -> Unit raise WindowSessionErrorfn WindowHandle::set_position(self : WindowHandle, x : Int, y : Int) -> Unit raise WindowSessionErrorfn WindowHandle::set_progress_bar(self : WindowHandle, progress : Double) -> Unit raise WindowSessionErrorfn WindowHandle::set_resizable(self : WindowHandle, resizable : Bool) -> Unit raise WindowSessionErrorfn WindowHandle::set_size(self : WindowHandle, width : Int, height : Int) -> Unit raise WindowSessionErrorfn WindowHandle::set_skip_taskbar(self : WindowHandle, skip : Bool) -> Unit raise WindowSessionErrorfn WindowHandle::set_visible_on_all_workspaces(self : WindowHandle, visible : Bool) -> Unit raise WindowSessionErrorfn WindowHandle::set_window_button_visibility(self : WindowHandle, visible : Bool) -> 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 WindowSessionErrorpub(all) struct WindowState {
x : Int
y : Int
width : Int
height : Int
monitor : WindowMonitor
zoom_percent : Int
visible : Bool
focused : Bool
minimized : Bool
maximized : Bool
fullscreen : Bool
always_on_top : Bool
theme : String
} derive(Eq, Debug)fn app_path() -> Stringfn 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 is_packaged() -> Boolfn resource_dir() -> Stringfn 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) -> ViewConfigInstall
Download zipMoonBit bindings for the Proton native desktop runtime.
Dependencies