diff --git a/.github/workflows/clippy.yml b/.github/workflows/clippy.yml index 3fc032018f..ff8cb956e4 100644 --- a/.github/workflows/clippy.yml +++ b/.github/workflows/clippy.yml @@ -41,6 +41,7 @@ jobs: cargo clippy -p sample_create_window_sys && cargo clippy -p sample_data_protection && cargo clippy -p sample_dcomp && + cargo clippy -p sample_device_watcher && cargo clippy -p sample_direct2d && cargo clippy -p sample_direct3d12 && cargo clippy -p sample_enum_windows && diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 1e3c47e034..485add340b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -91,6 +91,7 @@ jobs: cargo test --target ${{ matrix.target }} -p sample_create_window_sys && cargo test --target ${{ matrix.target }} -p sample_data_protection && cargo test --target ${{ matrix.target }} -p sample_dcomp && + cargo test --target ${{ matrix.target }} -p sample_device_watcher && cargo test --target ${{ matrix.target }} -p sample_direct2d && cargo test --target ${{ matrix.target }} -p sample_direct3d12 && cargo test --target ${{ matrix.target }} -p sample_enum_windows && @@ -128,8 +129,8 @@ jobs: cargo test --target ${{ matrix.target }} -p test_error && cargo test --target ${{ matrix.target }} -p test_event && cargo test --target ${{ matrix.target }} -p test_extensions && - cargo test --target ${{ matrix.target }} -p test_handles && cargo clean && + cargo test --target ${{ matrix.target }} -p test_handles && cargo test --target ${{ matrix.target }} -p test_helpers && cargo test --target ${{ matrix.target }} -p test_implement && cargo test --target ${{ matrix.target }} -p test_interface && diff --git a/crates/samples/device_watcher/Cargo.toml b/crates/samples/device_watcher/Cargo.toml new file mode 100644 index 0000000000..472f9db97e --- /dev/null +++ b/crates/samples/device_watcher/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "sample_device_watcher" +version = "0.0.0" +edition = "2018" + +[dependencies.windows] +path = "../../libs/windows" +features = [ + "Devices_Enumeration", + "Foundation_Collections", +] diff --git a/crates/samples/device_watcher/src/main.rs b/crates/samples/device_watcher/src/main.rs new file mode 100644 index 0000000000..4c5cd30062 --- /dev/null +++ b/crates/samples/device_watcher/src/main.rs @@ -0,0 +1,21 @@ +use windows::{core::*, Devices::Enumeration::*, Foundation::*}; + +fn main() -> Result<()> { + let watcher = DeviceInformation::CreateWatcher()?; + + watcher.Added(&TypedEventHandler::::new( + |_, info| { + println!("{}", info.as_ref().expect("info").Name()?); + Ok(()) + }, + ))?; + + watcher.EnumerationCompleted(&TypedEventHandler::new(|_, _| { + println!("done!"); + Ok(()) + }))?; + + watcher.Start()?; + std::thread::sleep(std::time::Duration::new(10, 0)); + Ok(()) +}