Skip to content

Commit

Permalink
feat(clipboard): Switch from the fork crate to the nix crate for daem…
Browse files Browse the repository at this point in the history
…onization
  • Loading branch information
CheerfulPianissimo committed Mar 19, 2024
1 parent 9608b10 commit c2a1290
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 17 deletions.
33 changes: 21 additions & 12 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion wayshot/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ dialoguer = { version = "0.11.0", features = ["fuzzy-select"] }
eyre = "0.6.8"

wl-clipboard-rs = "0.8.0"
fork = "0.1.23"
nix = { version = "0.28.0", features = ["process"] }

[[bin]]
name = "wayshot"
Expand Down
8 changes: 4 additions & 4 deletions wayshot/src/wayshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use utils::EncodingFormat;

use wl_clipboard_rs::copy::{MimeType, Options, Source};

use fork::{fork, Fork};
use nix::unistd::{fork, ForkResult};

fn select_ouput<T>(ouputs: &[T]) -> Option<usize>
where
Expand Down Expand Up @@ -136,13 +136,13 @@ fn main() -> Result<()> {
}
if cli.clipboard {
let mut opts = Options::new();
match fork() {
match unsafe { fork() } {
// Having the image persistently available on the clipboard requires a wayshot process to be alive.
// Fork the process with a child detached from the main process and have the parent exit
Ok(Fork::Parent(_)) => {
Ok(ForkResult::Parent{..}) => {
return Ok(());
}
Ok(Fork::Child) => {
Ok(ForkResult::Child) => {
opts.foreground(true); //Offer the image till somthing else is available on the clipboard
opts.copy(
Source::Bytes(buffer.into_inner().into()),
Expand Down

0 comments on commit c2a1290

Please sign in to comment.