mirror of
https://github.com/rustdesk/rustdesk.git
synced 2026-03-18 18:51:08 +03:00
win,linux remove desktop wallpaper
Signed-off-by: 21pages <pages21@163.com>
This commit is contained in:
@@ -5,7 +5,9 @@ use desktop::Desktop;
|
||||
use hbb_common::config::CONFIG_OPTION_ALLOW_LINUX_HEADLESS;
|
||||
pub use hbb_common::platform::linux::*;
|
||||
use hbb_common::{
|
||||
allow_err, bail,
|
||||
allow_err,
|
||||
anyhow::anyhow,
|
||||
bail,
|
||||
config::Config,
|
||||
libc::{c_char, c_int, c_long, c_void},
|
||||
log,
|
||||
@@ -26,6 +28,7 @@ use std::{
|
||||
time::{Duration, Instant},
|
||||
};
|
||||
use users::{get_user_by_name, os::unix::UserExt};
|
||||
use wallpaper;
|
||||
|
||||
type Xdo = *const c_void;
|
||||
|
||||
@@ -1311,3 +1314,41 @@ NoDisplay=false
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub struct WallPaperRemover {
|
||||
old_path: String,
|
||||
old_path_dark: Option<String>, // ubuntu 22.04 light/dark theme have different uri
|
||||
}
|
||||
|
||||
impl WallPaperRemover {
|
||||
pub fn new() -> ResultType<Self> {
|
||||
let start = std::time::Instant::now();
|
||||
let old_path = wallpaper::get().map_err(|e| anyhow!(e.to_string()))?;
|
||||
let old_path_dark = wallpaper::get_dark().ok();
|
||||
if old_path.is_empty() && old_path_dark.clone().unwrap_or_default().is_empty() {
|
||||
bail!("already solid color");
|
||||
}
|
||||
wallpaper::set_from_path("").map_err(|e| anyhow!(e.to_string()))?;
|
||||
wallpaper::set_dark_from_path("").ok();
|
||||
log::info!(
|
||||
"created wallpaper remover, old_path:{:?}, old_path_dark:{:?}, elapsed:{:?}",
|
||||
old_path,
|
||||
old_path_dark,
|
||||
start.elapsed(),
|
||||
);
|
||||
Ok(Self {
|
||||
old_path,
|
||||
old_path_dark,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for WallPaperRemover {
|
||||
fn drop(&mut self) {
|
||||
allow_err!(wallpaper::set_from_path(&self.old_path).map_err(|e| anyhow!(e.to_string())));
|
||||
if let Some(old_path_dark) = &self.old_path_dark {
|
||||
allow_err!(wallpaper::set_dark_from_path(old_path_dark.as_str())
|
||||
.map_err(|e| anyhow!(e.to_string())));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user