mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2026-06-15 12:12:01 +08:00
feat: 初步增加 Windows 支持
This commit is contained in:
@@ -9,7 +9,15 @@ pub fn hostname_from_etc() -> String {
|
||||
|
||||
/// Current kernel hostname (`gethostname`). Used for live device info in the UI.
|
||||
pub fn hostname_uname() -> String {
|
||||
nix::unistd::gethostname()
|
||||
.map(|s| s.to_string_lossy().into_owned())
|
||||
.unwrap_or_else(|_| "unknown".to_string())
|
||||
#[cfg(unix)]
|
||||
{
|
||||
nix::unistd::gethostname()
|
||||
.map(|s| s.to_string_lossy().into_owned())
|
||||
.unwrap_or_else(|_| "unknown".to_string())
|
||||
}
|
||||
|
||||
#[cfg(not(unix))]
|
||||
{
|
||||
std::env::var("COMPUTERNAME").unwrap_or_else(|_| "unknown".to_string())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,10 +2,16 @@
|
||||
|
||||
pub mod fs;
|
||||
pub mod host;
|
||||
#[cfg(unix)]
|
||||
pub mod net;
|
||||
#[cfg(not(unix))]
|
||||
#[path = "net_disabled.rs"]
|
||||
pub mod net;
|
||||
pub mod serial;
|
||||
pub mod throttle;
|
||||
|
||||
pub use fs::{list_dir_names, read_trimmed};
|
||||
pub use host::{hostname_from_etc, hostname_uname};
|
||||
pub use net::{bind_tcp_listener, bind_udp_socket};
|
||||
pub use serial::list_serial_ports;
|
||||
pub use throttle::LogThrottler;
|
||||
|
||||
14
src/utils/net_disabled.rs
Normal file
14
src/utils/net_disabled.rs
Normal file
@@ -0,0 +1,14 @@
|
||||
use std::io;
|
||||
use std::net::{SocketAddr, TcpListener, UdpSocket};
|
||||
|
||||
pub fn bind_tcp_listener(addr: SocketAddr) -> io::Result<TcpListener> {
|
||||
let listener = TcpListener::bind(addr)?;
|
||||
listener.set_nonblocking(true)?;
|
||||
Ok(listener)
|
||||
}
|
||||
|
||||
pub fn bind_udp_socket(addr: SocketAddr) -> io::Result<UdpSocket> {
|
||||
let socket = UdpSocket::bind(addr)?;
|
||||
socket.set_nonblocking(true)?;
|
||||
Ok(socket)
|
||||
}
|
||||
12
src/utils/serial.rs
Normal file
12
src/utils/serial.rs
Normal file
@@ -0,0 +1,12 @@
|
||||
//! Cross-platform serial port discovery helpers.
|
||||
|
||||
/// Return serial port names that users can put directly into the config.
|
||||
pub fn list_serial_ports() -> Vec<String> {
|
||||
let mut ports: Vec<String> = serialport::available_ports()
|
||||
.map(|ports| ports.into_iter().map(|port| port.port_name).collect())
|
||||
.unwrap_or_default();
|
||||
|
||||
ports.sort();
|
||||
ports.dedup();
|
||||
ports
|
||||
}
|
||||
Reference in New Issue
Block a user