proton_auto_launch

    Cross-platform auto-launch helpers for MoonBit, inspired by Teamwork/node-auto-launch.

    desktop
    autostart
    startup
    auto-launch
    native
    windows
    macos
    linux
    Download zip
    Version
    0.2.10
    License
    Apache-2.0
    Last updated
    3 hours ago
    Downloads
    6K

    #moonbit-community/proton_auto_launch

    CI

    Cross-platform auto-launch helpers for MoonBit.

    #Example

    ///|
    test "public api can be called" {
    ignore(@proton_auto_launch.current_platform())
    ignore(@proton_auto_launch.is_supported())

    let launcher = @proton_auto_launch.new(
    "MoonBit Demo",
    path=match @proton_auto_launch.current_platform() {
    Windows => "C:\\Program Files\\MoonBit\\moonbit.exe"
    Macos => "/Applications/MoonBit.app/Contents/MacOS/MoonBit"
    Linux => "/usr/bin/moonbit"
    Unsupported => "/unsupported"
    },
    launch_in_background=true,
    extra_arguments=["--serve"],
    )

    match launcher {
    Ok(value) => {
    ignore(value.name())
    ignore(value.path())
    ignore(value.identifier())
    }
    Err(_) => ()
    }
    }

    AutoLaunch

    pub struct AutoLaunch {
    config : AutoLaunchConfig
    }

    Stores the normalized auto-launch configuration for one application.

    AutoLaunch values are created through new after validation and normalization have already completed. Callers therefore get a stable, reusable handle that can be queried or applied multiple times without having to repeat path validation or identifier generation.

    AutoLaunch::disable

    fn AutoLaunch::disable(self : AutoLaunch) -> Result[Unit, AutoLaunchError]

    Disable auto-launch for this configuration on the current platform.

    Missing entries are treated as already-disabled and therefore do not produce an error in the native backend.

    AutoLaunch::enable

    fn AutoLaunch::enable(self : AutoLaunch) -> Result[Unit, AutoLaunchError]

    Enable auto-launch for this configuration on the current platform.

    On supported platforms this creates or updates the corresponding startup entry:

    • Windows: writes the current-user Run registry value
    • macOS: writes a LaunchAgent plist under ~/Library/LaunchAgents
    • Linux: writes an XDG autostart desktop entry under ~/.config/autostart

    Returns Ok(()) when the entry was written successfully.

    AutoLaunch::identifier

    fn AutoLaunch::identifier(self : AutoLaunch) -> String

    Returns the stable backend identifier used for the registry value or file name.

    This value is derived from name unless the caller provided identifier explicitly. It is sanitized for backend-safe usage and is what ties enable(), disable(), and is_enabled() to the same platform entry.

    AutoLaunch::is_enabled

    fn AutoLaunch::is_enabled(self : AutoLaunch) -> Result[Bool, AutoLaunchError]

    Check whether the auto-launch entry currently exists for this configuration.

    This is an existence check against the backend entry identified by identifier(). It does not attempt to prove that the entry still contains the exact expected command line beyond the backend's own lookup semantics.

    AutoLaunch::name

    fn AutoLaunch::name(self : AutoLaunch) -> String

    Returns the configured human-readable application name.

    This is the display name used in generated desktop-entry style metadata. It may contain spaces and punctuation and is independent from the backend identifier used for file names or registry keys.

    AutoLaunch::path

    fn AutoLaunch::path(self : AutoLaunch) -> String

    Returns the resolved absolute executable path that will be launched.

    The value returned here is always the normalized absolute path that passed constructor validation, either from the explicit path argument or from the current executable path discovered by the native backend.

    AutoLaunchConfig

    type AutoLaunchConfig

    Canonical auto-launch settings shared by all platform backends.

    AutoLaunchError

    pub enum AutoLaunchError {
    EmptyName
    EmptyExecutablePath
    EmptyBackgroundArgument
    ExecutablePathUnavailable
    HomeDirectoryUnavailable
    RelativeExecutablePath(String)
    UnsupportedPlatform(Platform)
    NativeFailure(action~ : String, message~ : String)
    } derive(Eq,
    Debug
    )

    Errors returned by auto_launch operations.

    The error model is intentionally small and stable:

    • validation errors describe incorrect input supplied by the caller
    • discovery errors describe missing runtime information such as the current executable path or home directory
    • NativeFailure reports a backend-specific failure message produced by the underlying platform API

    This enum derives Eq and implements Show, which makes it convenient to inspect in tests and to print in user-facing diagnostics.

    AutoLaunchError::equal

    AutoLaunchError::not_equal

    fn AutoLaunchError::not_equal(x : AutoLaunchError, y : AutoLaunchError) -> Bool

    AutoLaunchError::output

    fn AutoLaunchError::output(self : AutoLaunchError, logger : &Logger) -> Unit

    AutoLaunchError::to_string

    fn AutoLaunchError::to_string(self : AutoLaunchError) -> String

    BackendKind

    type BackendKind derive(Eq,
    Debug
    )

    Internal backend categories for supported startup mechanisms.

    BackendKind::equal

    fn BackendKind::equal(BackendKind, BackendKind) -> Bool

    BackendKind::not_equal

    fn BackendKind::not_equal(x : BackendKind, y : BackendKind) -> Bool

    FileEntry

    type FileEntry derive(Eq,
    Debug
    )

    A rendered file-based auto-launch entry ready to be written to disk.

    FileEntry::equal

    fn FileEntry::equal(FileEntry, FileEntry) -> Bool

    FileEntry::not_equal

    fn FileEntry::not_equal(x : FileEntry, y : FileEntry) -> Bool

    Platform

    pub enum Platform {
    Windows
    Macos
    Linux
    Unsupported
    } derive(Eq,
    Debug
    )

    Enumerates the operating systems that this package can detect at runtime.

    The value is derived from the active native backend rather than from build-time configuration alone, so it reflects the platform that the current executable is actually running on.
    impl Show for Platform

    Platform::equal

    fn Platform::equal(Platform, Platform) -> Bool

    Platform::not_equal

    fn Platform::not_equal(x : Platform, y : Platform) -> Bool

    Platform::output

    fn Platform::output(self : Platform, logger : &Logger) -> Unit

    Platform::to_repr

    Platform::to_string

    fn Platform::to_string(self : Platform) -> String

    current_platform

    fn current_platform() -> Platform

    Detects the current runtime platform for the active native build.

    This function is a lightweight probe over the native FFI layer. It is safe to call repeatedly and is primarily useful for platform-specific setup, conditional logging, or selecting example paths in applications and tests.

    is_supported

    fn is_supported() -> Bool

    Returns true when the current runtime platform has a supported auto-launch backend in this package.

    Supported platforms currently map to these backends:

    • Windows: current-user Run registry value
    • Macos: per-user LaunchAgent plist
    • Linux: XDG autostart desktop entry

    Unsupported means the package was compiled or executed in an environment for which no native backend is implemented.

    new

    fn new(name : String, path? : String, launch_in_background? : Bool, background_arg? : String, extra_arguments? : Array[String], identifier? : String) -> Result[AutoLaunch, AutoLaunchError]

    Create an auto-launch configuration for the current platform.

    name is the human-readable application name shown in generated desktop entries. path defaults to the current executable path when omitted.

    When launch_in_background is true, the package appends background_arg before any extra_arguments. This mirrors the common --hidden startup convention used by desktop applications.

    identifier controls the stable registry value or file name used by the backend. When omitted, it is derived from name.

    Returns Err(AutoLaunchError) when validation fails, when the current platform is unsupported, or when the executable path cannot be discovered.

    The resulting value is reusable: you can keep it around and call enable(), disable(), and is_enabled() multiple times.

    Example

    let launcher = @proton_auto_launch.new(
    "MoonBit Demo",
    path="/usr/bin/moonbit",
    launch_in_background=true,
    extra_arguments=["--serve"],
    )

    Powered by MoonBit

    Site sourceReport issuePackagesBuild queueSkillsStatistics

    © 2026 mooncakes.io