diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 807d7ea..6edfeac 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -28,7 +28,7 @@ jobs: os: [macos-latest, windows-latest, ubuntu-latest] steps: - - uses: actions/checkout@v1 + - uses: actions/checkout@v4 - name: Install Rust Unix if: runner.os != 'Windows' diff --git a/src/master/x11.rs b/src/master/x11.rs index 33f268b..1aad757 100644 --- a/src/master/x11.rs +++ b/src/master/x11.rs @@ -66,10 +66,11 @@ impl Master { }; loop { - let res = clipboard.load_wait( + let res = clipboard.load( clipboard.getter.atoms.clipboard, clipboard.getter.atoms.incr, clipboard.getter.atoms.property, + self.handler.sleep_interval(), ); match res { Ok(_) => { @@ -81,6 +82,7 @@ impl Master { } } }, + Err(x11_clipboard::error::Error::Timeout) => (), Err(error) => { let error = io::Error::new( io::ErrorKind::Other, diff --git a/tests/shutdown.rs b/tests/shutdown.rs index 7992377..042589b 100644 --- a/tests/shutdown.rs +++ b/tests/shutdown.rs @@ -1,3 +1,4 @@ +use std::time; use clipboard_master::{Master, ClipboardHandler, CallbackResult}; pub struct Handler; @@ -8,19 +9,20 @@ impl ClipboardHandler for Handler { } } -//TODO: Make shutdown work on Linux -//This is currently difficult due to buggy x11-clipboard lib -#[cfg(not(target_arch = "linux"))] #[test] fn should_shutdown_successfully() { + const TIMEOUT: time::Duration = time::Duration::from_secs(5); let mut master = Master::new(Handler).expect("To create master"); let shutdown = master.shutdown_channel(); std::thread::spawn(move || { - std::thread::sleep(core::time::Duration::from_secs(5)); + std::thread::sleep(TIMEOUT); println!("signal"); shutdown.signal(); }); println!("RUN"); + let now = time::Instant::now(); master.run().expect("to finish"); + assert!(now.elapsed() >= (TIMEOUT - time::Duration::from_millis(500))); + assert!(now.elapsed() <= (TIMEOUT + time::Duration::from_millis(500))); }