a7n-platform 0.19.0

Native desktop backends for the Apeirogon software KVM
Documentation
// SPDX-License-Identifier: GPL-3.0-or-later

pub mod autostart;
pub mod clipboard;
mod display;
pub use display::physical_size_mm;
pub mod fs;
pub mod input;
pub mod local_socket;
pub mod notify;
pub mod permissions;

/// OS host name, bounded to the peer name limit, if available and nonempty.
#[must_use]
pub fn host_name() -> Option<String> {
    let name = os_host_name()?;
    let name: String = name
        .chars()
        .take(a7n_proto::limits::PEER_NAME_MAX)
        .collect();
    (!name.is_empty()).then_some(name)
}

#[cfg(unix)]
fn os_host_name() -> Option<String> {
    rustix::system::uname()
        .nodename()
        .to_str()
        .ok()
        .map(str::to_owned)
}

#[cfg(windows)]
fn os_host_name() -> Option<String> {
    std::env::var("COMPUTERNAME").ok()
}

#[cfg(feature = "tray")]
pub mod tray;

/// The local platform advertised in the peer handshake.
#[must_use]
pub const fn platform() -> a7n_proto::v1::Platform {
    use a7n_proto::v1::Platform;

    if cfg!(target_os = "macos") {
        Platform::Macos
    } else if cfg!(target_os = "windows") {
        Platform::Windows
    } else if cfg!(target_os = "linux") {
        Platform::Linux
    } else {
        Platform::Unspecified
    }
}

pub mod transfer_fs;

mod network;
pub use network::{hw_addr_for, ipv4_broadcasts, local_addr_for};