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