Skip to main content

a7n_platform/
lib.rs

1// SPDX-License-Identifier: GPL-3.0-or-later
2
3pub mod autostart;
4pub mod clipboard;
5mod display;
6pub use display::physical_size_mm;
7pub mod fs;
8pub mod input;
9pub mod local_socket;
10pub mod notify;
11pub mod permissions;
12
13/// OS host name, bounded to the peer name limit, if available and nonempty.
14#[must_use]
15pub fn host_name() -> Option<String> {
16    let name = os_host_name()?;
17    let name: String = name
18        .chars()
19        .take(a7n_proto::limits::PEER_NAME_MAX)
20        .collect();
21    (!name.is_empty()).then_some(name)
22}
23
24#[cfg(unix)]
25fn os_host_name() -> Option<String> {
26    rustix::system::uname()
27        .nodename()
28        .to_str()
29        .ok()
30        .map(str::to_owned)
31}
32
33#[cfg(windows)]
34fn os_host_name() -> Option<String> {
35    std::env::var("COMPUTERNAME").ok()
36}
37
38#[cfg(feature = "tray")]
39pub mod tray;
40
41/// The local platform advertised in the peer handshake.
42#[must_use]
43pub const fn platform() -> a7n_proto::v1::Platform {
44    use a7n_proto::v1::Platform;
45
46    if cfg!(target_os = "macos") {
47        Platform::Macos
48    } else if cfg!(target_os = "windows") {
49        Platform::Windows
50    } else if cfg!(target_os = "linux") {
51        Platform::Linux
52    } else {
53        Platform::Unspecified
54    }
55}
56
57pub mod transfer_fs;
58
59mod network;
60pub use network::{hw_addr_for, ipv4_broadcasts, local_addr_for};