mirror of
https://github.com/rustdesk/rustdesk.git
synced 2024-11-24 12:29:04 +08:00
working on fav
This commit is contained in:
parent
f0a6c706fa
commit
1552402907
@ -688,6 +688,32 @@ impl PeerConfig {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Serialize, Deserialize, Clone)]
|
||||
pub struct Fav {
|
||||
#[serde(default)]
|
||||
pub peers: Vec<String>,
|
||||
}
|
||||
|
||||
impl Fav {
|
||||
pub fn load() -> Fav {
|
||||
let _ = CONFIG.read().unwrap(); // for lock
|
||||
match confy::load_path(&Config::file_("_fav")) {
|
||||
Ok(fav) => fav,
|
||||
Err(err) => {
|
||||
log::error!("Failed to load fav: {}", err);
|
||||
Default::default()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn store(peers: Vec<String>) {
|
||||
let f = Fav { peers };
|
||||
if let Err(err) = confy::store_path(Config::file_("_fav"), f) {
|
||||
log::error!("Failed to store fav: {}", err);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
54
src/ui.rs
54
src/ui.rs
@ -8,7 +8,7 @@ use crate::common::SOFTWARE_UPDATE_URL;
|
||||
use crate::ipc;
|
||||
use hbb_common::{
|
||||
allow_err,
|
||||
config::{Config, PeerConfig, APP_NAME, ICON},
|
||||
config::{Config, Fav, PeerConfig, APP_NAME, ICON},
|
||||
log, sleep,
|
||||
tokio::{self, time},
|
||||
};
|
||||
@ -411,22 +411,43 @@ impl UI {
|
||||
v
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn get_peer_value(id: String, p: PeerConfig) -> Value {
|
||||
let values = vec![
|
||||
id,
|
||||
p.info.username.clone(),
|
||||
p.info.hostname.clone(),
|
||||
p.info.platform.clone(),
|
||||
p.options.get("alias").unwrap_or(&"".to_owned()).to_owned(),
|
||||
];
|
||||
Value::from_iter(values)
|
||||
}
|
||||
|
||||
fn get_peer(&self, id: String) -> Value {
|
||||
let c = PeerConfig::load(&id);
|
||||
Self::get_peer_value(id, c)
|
||||
}
|
||||
|
||||
fn get_fav(&self) -> Value {
|
||||
Value::from_iter(Fav::load().peers)
|
||||
}
|
||||
|
||||
fn store_fav(&self, fav: Value) {
|
||||
let mut tmp = vec![];
|
||||
fav.values().for_each(|v| {
|
||||
if let Some(v) = v.as_string() {
|
||||
if !v.is_empty() {
|
||||
tmp.push(v);
|
||||
}
|
||||
}
|
||||
});
|
||||
Fav::store(tmp);
|
||||
}
|
||||
|
||||
fn get_recent_sessions(&mut self) -> Value {
|
||||
let peers: Vec<Value> = PeerConfig::peers()
|
||||
.iter()
|
||||
.map(|p| {
|
||||
let values = vec![
|
||||
p.0.clone(),
|
||||
p.2.info.username.clone(),
|
||||
p.2.info.hostname.clone(),
|
||||
p.2.info.platform.clone(),
|
||||
p.2.options
|
||||
.get("alias")
|
||||
.unwrap_or(&"".to_owned())
|
||||
.to_owned(),
|
||||
];
|
||||
Value::from_iter(values)
|
||||
})
|
||||
.drain(..)
|
||||
.map(|p| Self::get_peer_value(p.0, p.2))
|
||||
.collect();
|
||||
Value::from_iter(peers)
|
||||
}
|
||||
@ -599,6 +620,9 @@ impl sciter::EventHandler for UI {
|
||||
fn remove_peer(String);
|
||||
fn get_connect_status();
|
||||
fn get_recent_sessions();
|
||||
fn get_peer(String);
|
||||
fn get_fav();
|
||||
fn store_fav(Value);
|
||||
fn recent_sessions_updated();
|
||||
fn get_icon();
|
||||
fn get_msgbox();
|
||||
|
@ -66,7 +66,7 @@ div.sessions-tab span.active {
|
||||
}
|
||||
|
||||
div.search-id {
|
||||
width: 200px;
|
||||
width: 160px;
|
||||
padding: 0;
|
||||
position: relative;
|
||||
display: inline-block;
|
||||
|
Loading…
Reference in New Issue
Block a user