diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 8527f0d..fd7e216 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -14,3 +14,7 @@ jobs: - uses: actions/checkout@master - name: Run tests run: cargo test --verbose + - name: Add Wasm target + run: rustup target add wasm32-unknown-unknown + - name: Run tests on Wasm + run: cargo build --verbose --target wasm32-unknown-unknown diff --git a/Cargo.toml b/Cargo.toml index 9b69535..e8f11bb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,6 +13,7 @@ categories = ["gui"] [dependencies] raw-window-handle = "0.3" +thiserror = "1.0" [target.'cfg(windows)'.dependencies] clipboard-win = { version = "4.0", features = ["std"] } diff --git a/src/lib.rs b/src/lib.rs index c396478..6a940a2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -26,6 +26,24 @@ mod platform; #[path = "platform/android.rs"] mod platform; +#[cfg(not(any( + all( + unix, + not(any( + target_os = "macos", + target_os = "ios", + target_os = "android", + target_os = "emscripten" + )) + ), + target_os = "windows", + target_os = "macos", + target_os = "ios", + target_os = "android" +)))] +#[path = "platform/dummy.rs"] +mod platform; + use raw_window_handle::HasRawWindowHandle; use std::error::Error; diff --git a/src/platform/dummy.rs b/src/platform/dummy.rs new file mode 100644 index 0000000..410adc3 --- /dev/null +++ b/src/platform/dummy.rs @@ -0,0 +1,30 @@ +use crate::ClipboardProvider; + +use raw_window_handle::HasRawWindowHandle; + +struct Dummy; + +pub fn connect( + _window: &W, +) -> Result, Box> { + Ok(Box::new(Dummy)) +} + +impl ClipboardProvider for Dummy { + fn read(&self) -> Result> { + Err(Box::new(Error::Unimplemented)) + } + + fn write( + &mut self, + _contents: String, + ) -> Result<(), Box> { + Err(Box::new(Error::Unimplemented)) + } +} + +#[derive(Debug, Clone, Copy, thiserror::Error)] +enum Error { + #[error("unimplemented")] + Unimplemented, +} diff --git a/x11/src/lib.rs b/x11/src/lib.rs index 0e2b54e..346bf51 100644 --- a/x11/src/lib.rs +++ b/x11/src/lib.rs @@ -360,23 +360,28 @@ impl Worker { if event.target == self.context.atoms.targets { let data = [self.context.atoms.targets, target]; - self.context.connection.change_property32( - xproto::PropMode::REPLACE, - event.requestor, - event.property, - xproto::AtomEnum::ATOM, - &data, - ) - .expect("Change property"); + self.context + .connection + .change_property32( + xproto::PropMode::REPLACE, + event.requestor, + event.property, + xproto::AtomEnum::ATOM, + &data, + ) + .expect("Change property"); } else { - let _ = self.context.connection.change_property8( - xproto::PropMode::REPLACE, - event.requestor, - event.property, - target, - value, - ) - .expect("Change property"); + let _ = self + .context + .connection + .change_property8( + xproto::PropMode::REPLACE, + event.requestor, + event.property, + target, + value, + ) + .expect("Change property"); } let _ = xproto::send_event(