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

    proton

    MoonBit bindings for webview, a tiny library for creating web-based desktop GUIs.

    webview
    webui
    gui
    web
    desktop-app
    Download zip
    Author
    Version
    0.1.1
    License
    MIT
    Last updated
    5 months ago
    Downloads
    338

    #Proton

    Proton is a MoonBit framework for native desktop apps backed by CEF. Apps use a small runtime and explicitly link only the extensions they enable.

    #Quick Start

    Install the local justjavac/proton_cli first. Generated-command examples and CEF setup expect a proton binary in target/proton-tools:

    moon install --path cli --bin target\proton-tools Copy-Item target\proton-tools\proton_cli.exe target\proton-tools\proton.exe -Force

    On Unix-like shells, copy target/proton-tools/proton_cli to target/proton-tools/proton and make it executable.

    Install CEF and build the examples:

    target\proton-tools\proton cef setup moon -C examples build --target native

    Run the CEF smoke checks:

    moon build src\cef_process --target native moon -C examples run 43_cef_bind_smoke --target native node .\scripts\e2e_cdp_smoke.mjs

    #App Startup

    Inline startup:

    import {
    "justjavac/proton"
    "justjavac/proton_ext/fs" @fs
    "justjavac/proton_ext/path" @path
    }

    async fn main {
    @proton.html("Demo", "<html></html>", width=900, height=700, debug=true)
    .extension(@fs.extension())
    .extension(@path.extension())
    .run_or_abort()
    }

    Config-file startup uses moon.proton; extensions are still declared in MoonBit code:

    async fn main {
    @proton.config("moon.proton")
    .extension(@fs.extension())
    .extension(@path.extension())
    .run_or_abort()
    }

    #Main Packages

    • justjavac/proton: app facade with @proton.html(...) and @proton.config(...)
    • justjavac/proton/webview: low-level native WebView binding
    • justjavac/proton/core: JavaScript bridge, ops dispatch, and extension host
    • justjavac/proton/runtime: app and window lifecycle
    • justjavac/proton_config: parser for moon.proton, moon.ext, and moon.mod
    • justjavac/proton_cli: developer CLI and command/event codegen
    • justjavac/proton_ext: built-in extensions such as fs, path, dialog, and shell

    #JavaScript Bridge

    Proton installs one global object:

    await window.__MoonBit__.fs.readFile("demo.txt"); await window.__MoonBit__.path.resolve({ path: "." }); window.__MoonBit__.events.on("fs.activity", console.log);

    Low-level custom calls can use:

    await window.__MoonBit__.core.invokeOp("ext:path/resolve", { path: "." });

    #Notes

    • This repository currently targets native.
    • The CEF runtime lives in .cef-cache/ and is installed by proton cef setup.
    • CEF child processes use src/cef_process; packaged apps should ship the helper beside the app executable.
    • Extension linking is explicit so apps only ship the capabilities they enable.

    #License

    MIT. See LICENSE.md.

    App

    type App

    High-level application facade for ordinary apps.

    App::debug

    fn App::debug(self : App, enabled? : Bool) -> App

    Enables debug mode for inline apps.

    App::debug_level

    fn App::debug_level(self : App, debug : Int) -> App

    Sets the debug level for inline apps.

    App::entry_asset

    fn App::entry_asset(self : App, path : String) -> App

    Overrides the primary app entry with an asset path.

    App::entry_file

    fn App::entry_file(self : App, path : String) -> App

    Overrides the primary app entry with a file path.

    App::entry_html

    fn App::entry_html(self : App, html : String) -> App

    Overrides the primary app entry with inline HTML.

    App::entry_url

    fn App::entry_url(self : App, url : String) -> App

    Overrides the primary app entry with a URL.

    App::extension

    fn App::extension(self : App, extension :
    Extension
    , options? : Json) -> App

    Links and enables one extension.

    App::extensions

    fn App::extensions(self : App, extensions :
    Extensions
    ) -> App

    Links and enables a set of extensions.

    App::run

    async fn App::run(self : App) -> Result[Unit, String]

    Runs the configured app. Command extensions, when present, stay in this process.

    App::run_or_abort

    async fn App::run_or_abort(self : App) -> Unit

    Runs the configured app and aborts with the error message on failure.

    App::size

    fn App::size(self : App, width~ : Int, height~ : Int) -> App

    Sets the primary window size.

    App::title

    fn App::title(self : App, title : String) -> App

    Sets the primary window title.

    ExtensionRegistry

    type ExtensionRegistry

    Registry of extension specs available to one application build.

    ExtensionRegistry::get

    Returns one registered extension spec by id, if present.

    ExtensionRegistry::new

    Creates an empty extension registry. Registration order is preserved so later planning and generated registry output stay deterministic.

    ExtensionRegistry::register

    Registers one extension spec and returns the same registry for chaining.

    ExtensionRegistry::registered_ids

    fn ExtensionRegistry::registered_ids(self : ExtensionRegistry) -> Array[String]

    Returns the registered extension ids in deterministic registration order.

    asset

    fn asset(title : String, path : String, width? : Int, height? : Int, debug? : Bool, resizable? : Bool) -> App

    Creates an inline asset application.

    config

    fn config(path : String) -> App

    Creates an application backed by a config file.

    create_app

    fn create_app(manifest :
    AppManifest
    , registry : ExtensionRegistry, base_dir? : String?) -> Result[
    App
    , String]

    Creates a runtime app from an already parsed manifest and extension registry. This resolves declarative extensions, prepares the runtime config, and then builds the final @wvrt.App in one step.

    create_app_from_file

    fn create_app_from_file(path : String, registry : ExtensionRegistry) -> Result[
    App
    , String]

    Loads a manifest document from disk and creates a runtime app. Relative file entries and extension base directories are resolved from the manifest file's parent directory before the runtime app is constructed.

    file

    fn file(title : String, path : String, width? : Int, height? : Int, debug? : Bool, resizable? : Bool) -> App

    Creates an inline file application.

    html

    fn html(title : String, html : String, width? : Int, height? : Int, debug? : Bool, resizable? : Bool) -> App

    Creates an inline HTML application.

    url

    fn url(title : String, url : String, width? : Int, height? : Int, debug? : Bool, resizable? : Bool) -> App

    Creates an inline URL application.