Skip to content

Commit

Permalink
fix: png to user dir
Browse files Browse the repository at this point in the history
  • Loading branch information
Decodetalkers committed Dec 19, 2023
1 parent 051c11f commit 1389a2e
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 2 deletions.
11 changes: 11 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,4 @@ toml = "0.8.8"
csscolorparser = "0.6.2"
notify = "6.1.1"
futures = "0.3.29"
uzers = "0.11.3"
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
mod utils;
mod access;
mod remotedesktop;
mod request;
Expand Down
6 changes: 4 additions & 2 deletions src/screenshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down Expand Up @@ -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(),
}))
}

Expand Down
10 changes: 10 additions & 0 deletions src/utils.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
use std::path::PathBuf;

use once_cell::sync::Lazy;

use uzers::get_current_uid;

pub static USER_RUNNING_DIR: Lazy<PathBuf> = Lazy::new(|| {
let uid = get_current_uid();
PathBuf::from("/run/user").join(uid.to_string())
});

0 comments on commit 1389a2e

Please sign in to comment.