From 1389a2e86e69f326544d2a143ace64e48f3d797c Mon Sep 17 00:00:00 2001 From: ShootingStarDragons Date: Tue, 19 Dec 2023 16:25:24 +0800 Subject: [PATCH] fix: png to user dir --- Cargo.lock | 11 +++++++++++ Cargo.toml | 1 + src/main.rs | 1 + src/screenshot.rs | 6 ++++-- src/utils.rs | 10 ++++++++++ 5 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 src/utils.rs diff --git a/Cargo.lock b/Cargo.lock index 8218e63..51514fe 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4602,6 +4602,16 @@ dependencies = [ "tiny-skia-path 0.10.0", ] +[[package]] +name = "uzers" +version = "0.11.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76d283dc7e8c901e79e32d077866eaf599156cbf427fffa8289aecc52c5c3f63" +dependencies = [ + "libc", + "log", +] + [[package]] name = "valuable" version = "0.1.0" @@ -5260,6 +5270,7 @@ dependencies = [ "tracing", "tracing-subscriber", "url", + "uzers", "wayland-client", "wayland-protocols", "wayland-protocols-misc", diff --git a/Cargo.toml b/Cargo.toml index 8284a1f..d7d42bf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -57,3 +57,4 @@ toml = "0.8.8" csscolorparser = "0.6.2" notify = "6.1.1" futures = "0.3.29" +uzers = "0.11.3" diff --git a/src/main.rs b/src/main.rs index c60269f..063059e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,4 @@ +mod utils; mod access; mod remotedesktop; mod request; diff --git a/src/screenshot.rs b/src/screenshot.rs index 6167600..b0f0246 100644 --- a/src/screenshot.rs +++ b/src/screenshot.rs @@ -6,6 +6,7 @@ use zbus::zvariant::{DeserializeDict, SerializeDict, Type, Value}; use zbus::{dbus_interface, fdo, zvariant::ObjectPath}; use crate::PortalResponse; +use crate::utils::USER_RUNNING_DIR; #[derive(DeserializeDict, SerializeDict, Type)] #[zvariant(signature = "dict")] @@ -122,12 +123,13 @@ impl ScreenShotBackend { .screenshot_all(false) .map_err(|e| zbus::Error::Failure(format!("Wayland screencopy failed, {e}")))? }; - image_buffer.save("/tmp/wayshot.png").map_err(|e| { + let savepath = USER_RUNNING_DIR.join("wayshot.png"); + image_buffer.save(&savepath).map_err(|e| { zbus::Error::Failure(format!("Cannot save to /tmp/wayshot.png, e: {e}")) })?; tracing::info!("Shot Finished"); Ok(PortalResponse::Success(Screenshot { - uri: url::Url::from_file_path("/tmp/wayshot.png").unwrap(), + uri: url::Url::from_file_path(savepath).unwrap(), })) } diff --git a/src/utils.rs b/src/utils.rs new file mode 100644 index 0000000..6267802 --- /dev/null +++ b/src/utils.rs @@ -0,0 +1,10 @@ +use std::path::PathBuf; + +use once_cell::sync::Lazy; + +use uzers::get_current_uid; + +pub static USER_RUNNING_DIR: Lazy = Lazy::new(|| { + let uid = get_current_uid(); + PathBuf::from("/run/user").join(uid.to_string()) +});