mirror of
https://github.com/weyne85/rustdesk.git
synced 2025-10-29 17:00:05 +00:00
refactor peer alias
This commit is contained in:
@@ -7,11 +7,11 @@ use std::{
|
||||
use flutter_rust_bridge::{StreamSink, SyncReturn, ZeroCopyBuffer};
|
||||
use serde_json::json;
|
||||
|
||||
use hbb_common::ResultType;
|
||||
use hbb_common::{
|
||||
config::{self, LocalConfig, PeerConfig, ONLINE},
|
||||
fs, log,
|
||||
};
|
||||
use hbb_common::{message_proto::Hash, ResultType};
|
||||
|
||||
use crate::flutter::{self, SESSIONS};
|
||||
use crate::start_server;
|
||||
@@ -567,9 +567,20 @@ pub fn main_forget_password(id: String) {
|
||||
|
||||
pub fn main_get_recent_peers() -> String {
|
||||
if !config::APP_DIR.read().unwrap().is_empty() {
|
||||
let peers: Vec<(String, config::PeerInfoSerde)> = PeerConfig::peers()
|
||||
let peers: Vec<HashMap<&str, String>> = PeerConfig::peers()
|
||||
.drain(..)
|
||||
.map(|(id, _, p)| (id, p.info))
|
||||
.map(|(id, _, p)| {
|
||||
HashMap::<&str, String>::from_iter([
|
||||
("id", id),
|
||||
("username", p.info.username.clone()),
|
||||
("hostname", p.info.hostname.clone()),
|
||||
("platform", p.info.platform.clone()),
|
||||
(
|
||||
"alias",
|
||||
p.options.get("alias").unwrap_or(&"".to_owned()).to_owned(),
|
||||
),
|
||||
])
|
||||
})
|
||||
.collect();
|
||||
serde_json::ser::to_string(&peers).unwrap_or("".to_owned())
|
||||
} else {
|
||||
@@ -579,9 +590,20 @@ pub fn main_get_recent_peers() -> String {
|
||||
|
||||
pub fn main_load_recent_peers() {
|
||||
if !config::APP_DIR.read().unwrap().is_empty() {
|
||||
let peers: Vec<(String, config::PeerInfoSerde)> = PeerConfig::peers()
|
||||
let peers: Vec<HashMap<&str, String>> = PeerConfig::peers()
|
||||
.drain(..)
|
||||
.map(|(id, _, p)| (id, p.info))
|
||||
.map(|(id, _, p)| {
|
||||
HashMap::<&str, String>::from_iter([
|
||||
("id", id),
|
||||
("username", p.info.username.clone()),
|
||||
("hostname", p.info.hostname.clone()),
|
||||
("platform", p.info.platform.clone()),
|
||||
(
|
||||
"alias",
|
||||
p.options.get("alias").unwrap_or(&"".to_owned()).to_owned(),
|
||||
),
|
||||
])
|
||||
})
|
||||
.collect();
|
||||
if let Some(s) = flutter::GLOBAL_EVENT_STREAM
|
||||
.read()
|
||||
@@ -603,11 +625,20 @@ pub fn main_load_recent_peers() {
|
||||
pub fn main_load_fav_peers() {
|
||||
if !config::APP_DIR.read().unwrap().is_empty() {
|
||||
let favs = get_fav();
|
||||
let peers: Vec<(String, config::PeerInfoSerde)> = PeerConfig::peers()
|
||||
let peers: Vec<HashMap<&str, String>> = PeerConfig::peers()
|
||||
.into_iter()
|
||||
.filter_map(|(id, _, peer)| {
|
||||
.filter_map(|(id, _, p)| {
|
||||
if favs.contains(&id) {
|
||||
Some((id, peer.info))
|
||||
Some(HashMap::<&str, String>::from_iter([
|
||||
("id", id),
|
||||
("username", p.info.username.clone()),
|
||||
("hostname", p.info.hostname.clone()),
|
||||
("platform", p.info.platform.clone()),
|
||||
(
|
||||
"alias",
|
||||
p.options.get("alias").unwrap_or(&"".to_owned()).to_owned(),
|
||||
),
|
||||
]))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
|
||||
17
src/ui.rs
17
src/ui.rs
@@ -18,7 +18,7 @@ use hbb_common::{
|
||||
tokio::{self, sync::mpsc, time},
|
||||
};
|
||||
|
||||
use crate::common::{get_app_name};
|
||||
use crate::common::get_app_name;
|
||||
use crate::ipc;
|
||||
use crate::ui_interface::{
|
||||
check_mouse_time, closing, create_shortcut, current_is_wayland, fix_login_wayland,
|
||||
@@ -73,9 +73,7 @@ fn check_connect_status(
|
||||
let (tx, rx) = mpsc::unbounded_channel::<ipc::Data>();
|
||||
let password = Arc::new(Mutex::new(String::default()));
|
||||
let cloned_password = password.clone();
|
||||
std::thread::spawn(move || {
|
||||
crate::ui_interface::check_connect_status_(reconnect, rx)
|
||||
});
|
||||
std::thread::spawn(move || crate::ui_interface::check_connect_status_(reconnect, rx));
|
||||
(status, options, tx, password)
|
||||
}
|
||||
|
||||
@@ -525,9 +523,16 @@ impl UI {
|
||||
fn get_lan_peers(&self) -> String {
|
||||
let peers = get_lan_peers()
|
||||
.into_iter()
|
||||
.map(|(id, peer)| (id, peer.username, peer.hostname, peer.platform))
|
||||
.map(|mut peer| {
|
||||
(
|
||||
peer.remove("id").unwrap_or_default(),
|
||||
peer.remove("username").unwrap_or_default(),
|
||||
peer.remove("hostname").unwrap_or_default(),
|
||||
peer.remove("platform").unwrap_or_default(),
|
||||
)
|
||||
})
|
||||
.collect::<Vec<(String, String, String, String)>>();
|
||||
serde_json::to_string(&peers).unwrap_or_default()
|
||||
serde_json::to_string(&get_lan_peers()).unwrap_or_default()
|
||||
}
|
||||
|
||||
fn get_uuid(&self) -> String {
|
||||
|
||||
@@ -648,19 +648,17 @@ pub fn discover() {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn get_lan_peers() -> Vec<(String, config::PeerInfoSerde)> {
|
||||
pub fn get_lan_peers() -> Vec<HashMap<&'static str, String>> {
|
||||
config::LanPeers::load()
|
||||
.peers
|
||||
.iter()
|
||||
.map(|peer| {
|
||||
(
|
||||
peer.id.clone(),
|
||||
config::PeerInfoSerde {
|
||||
username: peer.username.clone(),
|
||||
hostname: peer.hostname.clone(),
|
||||
platform: peer.platform.clone(),
|
||||
},
|
||||
)
|
||||
HashMap::<&str, String>::from_iter([
|
||||
("id", peer.id.clone()),
|
||||
("username", peer.username.clone()),
|
||||
("hostname", peer.hostname.clone()),
|
||||
("platform", peer.platform.clone()),
|
||||
])
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user