working on fav

This commit is contained in:
rustdesk 2022-01-02 21:56:04 +08:00
parent f0a6c706fa
commit 1552402907
3 changed files with 66 additions and 16 deletions

View File

@ -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::*;

View File

@ -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();

View File

@ -66,7 +66,7 @@ div.sessions-tab span.active {
}
div.search-id {
width: 200px;
width: 160px;
padding: 0;
position: relative;
display: inline-block;