artifactize-tools 0.27.2

Portable scoped tools and safe file access for artifactize.
Documentation
//! Open one path or URL with the desktop's default application, without a shell.

use std::{ffi::OsStr, io, time::Duration};

use tokio_util::sync::CancellationToken;

/// Desktop handoff must not hold a sign-in or Human tool indefinitely.
const OPEN_TIMEOUT: Duration = Duration::from_secs(3);

/// The platform layer chooses the desktop's own opener. The target is one argument, never a
/// shell command or command line.
pub async fn open(target: &OsStr) -> io::Result<()> {
    open_cancellable(target, &CancellationToken::new()).await
}

/// [`open`] with the caller's own bound on how long the opener may take to hand off.
pub async fn open_within(target: &OsStr, deadline: Duration) -> io::Result<()> {
    crate::platform::open_desktop(target, deadline, &CancellationToken::new()).await
}

/// Cancel an in-flight opener and wait for its owned processes to be cleaned up.
pub async fn open_cancellable(target: &OsStr, cancellation: &CancellationToken) -> io::Result<()> {
    crate::platform::open_desktop(target, OPEN_TIMEOUT, cancellation).await
}