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