mirror of
https://github.com/rustdesk/hbb_common.git
synced 2025-07-01 23:47:24 +00:00
feat: hostname as id
Signed-off-by: fufesou <linlong1266@gmail.com>
This commit is contained in:
parent
42aad01a51
commit
8e1dd7f88f
@ -64,6 +64,7 @@ rustls-platform-verifier = "0.5"
|
|||||||
rustls-pki-types = "1.11"
|
rustls-pki-types = "1.11"
|
||||||
[target.'cfg(any(target_os = "macos", target_os = "windows"))'.dependencies]
|
[target.'cfg(any(target_os = "macos", target_os = "windows"))'.dependencies]
|
||||||
tokio-native-tls = "0.3"
|
tokio-native-tls = "0.3"
|
||||||
|
whoami = "1.5.0"
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
protobuf-codegen = { version = "3.7" }
|
protobuf-codegen = { version = "3.7" }
|
||||||
|
@ -560,7 +560,7 @@ impl Config {
|
|||||||
}
|
}
|
||||||
if !id_valid {
|
if !id_valid {
|
||||||
for _ in 0..3 {
|
for _ in 0..3 {
|
||||||
if let Some(id) = Config::get_auto_id() {
|
if let Some(id) = Config::gen_id() {
|
||||||
config.id = id;
|
config.id = id;
|
||||||
store = true;
|
store = true;
|
||||||
break;
|
break;
|
||||||
@ -822,6 +822,32 @@ impl Config {
|
|||||||
std::cmp::max(CONFIG2.read().unwrap().serial, SERIAL)
|
std::cmp::max(CONFIG2.read().unwrap().serial, SERIAL)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(any(target_os = "android", target_os = "ios"))]
|
||||||
|
fn gen_id() -> Option<String> {
|
||||||
|
Self::get_auto_id()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||||
|
fn gen_id() -> Option<String> {
|
||||||
|
let hostname_as_id = BUILTIN_SETTINGS
|
||||||
|
.read()
|
||||||
|
.unwrap()
|
||||||
|
.get(keys::OPTION_ALLOW_HOSTNAME_AS_ID)
|
||||||
|
.map(|v| option2bool(keys::OPTION_ALLOW_HOSTNAME_AS_ID, v))
|
||||||
|
.unwrap_or(false);
|
||||||
|
if hostname_as_id {
|
||||||
|
match whoami::fallible::hostname() {
|
||||||
|
Ok(h) => Some(h.replace(" ", "-")),
|
||||||
|
Err(e) => {
|
||||||
|
log::warn!("Failed to get hostname, \"{}\", fallback to auto id", e);
|
||||||
|
Self::get_auto_id()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Self::get_auto_id()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn get_auto_id() -> Option<String> {
|
fn get_auto_id() -> Option<String> {
|
||||||
#[cfg(any(target_os = "android", target_os = "ios"))]
|
#[cfg(any(target_os = "android", target_os = "ios"))]
|
||||||
{
|
{
|
||||||
@ -909,7 +935,7 @@ impl Config {
|
|||||||
pub fn get_id() -> String {
|
pub fn get_id() -> String {
|
||||||
let mut id = CONFIG.read().unwrap().id.clone();
|
let mut id = CONFIG.read().unwrap().id.clone();
|
||||||
if id.is_empty() {
|
if id.is_empty() {
|
||||||
if let Some(tmp) = Config::get_auto_id() {
|
if let Some(tmp) = Config::gen_id() {
|
||||||
id = tmp;
|
id = tmp;
|
||||||
Config::set_id(&id);
|
Config::set_id(&id);
|
||||||
}
|
}
|
||||||
@ -2369,6 +2395,7 @@ pub mod keys {
|
|||||||
pub const OPTION_ALLOW_LOGON_SCREEN_PASSWORD: &str = "allow-logon-screen-password";
|
pub const OPTION_ALLOW_LOGON_SCREEN_PASSWORD: &str = "allow-logon-screen-password";
|
||||||
pub const OPTION_ONE_WAY_FILE_TRANSFER: &str = "one-way-file-transfer";
|
pub const OPTION_ONE_WAY_FILE_TRANSFER: &str = "one-way-file-transfer";
|
||||||
pub const OPTION_ALLOW_HTTPS_21114: &str = "allow-https-21114";
|
pub const OPTION_ALLOW_HTTPS_21114: &str = "allow-https-21114";
|
||||||
|
pub const OPTION_ALLOW_HOSTNAME_AS_ID: &str = "allow-hostname-as-id";
|
||||||
|
|
||||||
// flutter local options
|
// flutter local options
|
||||||
pub const OPTION_FLUTTER_REMOTE_MENUBAR_STATE: &str = "remoteMenubarState";
|
pub const OPTION_FLUTTER_REMOTE_MENUBAR_STATE: &str = "remoteMenubarState";
|
||||||
@ -2528,6 +2555,7 @@ pub mod keys {
|
|||||||
OPTION_ALLOW_LOGON_SCREEN_PASSWORD,
|
OPTION_ALLOW_LOGON_SCREEN_PASSWORD,
|
||||||
OPTION_ONE_WAY_FILE_TRANSFER,
|
OPTION_ONE_WAY_FILE_TRANSFER,
|
||||||
OPTION_ALLOW_HTTPS_21114,
|
OPTION_ALLOW_HTTPS_21114,
|
||||||
|
OPTION_ALLOW_HOSTNAME_AS_ID,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user