Crate sysuri

Crate sysuri 

Source
Expand description

§sysuri

A cross-platform Rust crate for registering custom URI schemes with the operating system.

§Features

  • Cross-platform support (Windows, macOS, Linux)
  • Simple API for registering and unregistering URI schemes
  • Callback-based URI handling
  • No unsafe code
  • Comprehensive error handling

§Quick Start

use sysuri::{UriScheme, register};
use std::path::PathBuf;
use std::env;

// Get the current executable path
let exe = env::current_exe().unwrap();

// Create a URI scheme
let scheme = UriScheme::new(
    "myapp",
    "My Application Protocol",
    exe
);

// Register it with the OS
register(&scheme).unwrap();

§URI Handler

When your application is launched via a custom URI, the URI is typically passed as a command-line argument. You can use the parse_args function to extract it:

use sysuri::parse_args;

fn main() {
    if let Some(uri) = parse_args() {
        println!("Opened with URI: {}", uri);
        // Handle the URI...
    } else {
        println!("Normal application startup");
        // Run normal application logic...
    }
}

Structs§

FnHandler
A simple function-based URI handler
UriScheme
Represents a custom URI scheme registration

Enums§

Error
Errors that can occur during URI registration and handling

Traits§

UriHandler
Handler for incoming URI requests

Functions§

extract_scheme
Extract the scheme from a URI
handle_uri
Handle a URI by calling the registered handler
is_registered
Check if a URI scheme is already registered
parse_args
Parse command-line arguments to find a URI
register
Register a URI scheme with the operating system
register_handler
Register a URI handler callback
should_handle_uri
Check if the application should run in URI handler mode
unregister
Unregister a URI scheme from the operating system

Type Aliases§

Result
Result type alias for sysuri operations