Skip to main content

a7n_platform/
lib.rs

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