From 230458323adac940fddc4db93d6dcce4e442c337 Mon Sep 17 00:00:00 2001 From: Eduardo Flores Date: Mon, 26 Dec 2022 02:42:57 -0700 Subject: [PATCH] Example implementation --- .gitignore | 1 + Cargo.toml | 15 +++------------ examples/{detect/src/main.rs => detect.rs} | 0 examples/detect/Cargo.toml | 9 --------- examples/notify.rs | 12 ++++++++++++ examples/notify/Cargo.toml | 9 --------- examples/notify/src/main.rs | 8 -------- src/lib.rs | 6 ++++-- src/windows/notify.rs | 13 ++++++++++--- 9 files changed, 30 insertions(+), 43 deletions(-) rename examples/{detect/src/main.rs => detect.rs} (100%) delete mode 100644 examples/detect/Cargo.toml create mode 100644 examples/notify.rs delete mode 100644 examples/notify/Cargo.toml delete mode 100644 examples/notify/src/main.rs diff --git a/.gitignore b/.gitignore index 96ef6c0..b30a90c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /target +/examples/*/target Cargo.lock diff --git a/Cargo.toml b/Cargo.toml index 93342cb..4d42019 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,6 +12,9 @@ build = "build.rs" [dependencies] anyhow = "1.0.52" +[dev-dependencies] +tokio = { version = "1.15.0", features = ["full"] } + [target.'cfg(any(target_os = "linux", target_os = "freebsd", target_os = "dragonfly", target_os = "netbsd", target_os = "openbsd"))'.dependencies] detect-desktop-environment = "0.2" dconf_rs = "0.3" @@ -19,10 +22,6 @@ dirs = "4.0" zbus = "3.0" zvariant = "3.6" rust-ini = "0.18" -ashpd = "0.3.2" -async_ashpd = { package = "ashpd", version = "0.3.2" } -tokio = { version = "1.15.0", features = ["full"] } -crossbeam = "0.8.1" [target.'cfg(windows)'.dependencies] winreg = "0.10" @@ -32,11 +31,3 @@ objc = "0.2" [target.'cfg(target_arch = "wasm32")'.dependencies] web-sys = { version = "0.3", features = [ "MediaQueryList", "Window" ] } - -[[example]] -name = "detect" -path = "examples/detect/src/main.rs" - -[[example]] -name = "notify" -path = "examples/notify/src/main.rs" diff --git a/examples/detect/src/main.rs b/examples/detect.rs similarity index 100% rename from examples/detect/src/main.rs rename to examples/detect.rs diff --git a/examples/detect/Cargo.toml b/examples/detect/Cargo.toml deleted file mode 100644 index 0d430eb..0000000 --- a/examples/detect/Cargo.toml +++ /dev/null @@ -1,9 +0,0 @@ -[package] -name = "detect" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -dark-light = "0.2.0" \ No newline at end of file diff --git a/examples/notify.rs b/examples/notify.rs new file mode 100644 index 0000000..258877f --- /dev/null +++ b/examples/notify.rs @@ -0,0 +1,12 @@ +use dark_light::*; + +#[tokio::main] +async fn main() { + let (tx, rx) = std::sync::mpsc::channel(); + tokio::spawn(async move { + notify(tx).await.unwrap(); + }); + while let Ok(mode) = rx.recv() { + println!("{:?}", mode) + } +} \ No newline at end of file diff --git a/examples/notify/Cargo.toml b/examples/notify/Cargo.toml deleted file mode 100644 index 7e0cc89..0000000 --- a/examples/notify/Cargo.toml +++ /dev/null @@ -1,9 +0,0 @@ -[package] -name = "notify" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -tokio = { version = "1.15.0", features = ["full"] } diff --git a/examples/notify/src/main.rs b/examples/notify/src/main.rs deleted file mode 100644 index c4c1733..0000000 --- a/examples/notify/src/main.rs +++ /dev/null @@ -1,8 +0,0 @@ -#[tokio::main] -async fn main() -> anyhow::Result<()> { - dark_light::notify(&change_color_scheme).await -} - -fn change_color_scheme(mode: dark_light::Mode) { - println!("Changing to {:?}", mode) -} \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index 65ff6ff..10a50ae 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -14,6 +14,8 @@ #[cfg(target_os = "macos")] mod macos; +use std::sync::mpsc::Sender; + #[cfg(target_os = "macos")] use macos as platform; @@ -90,6 +92,6 @@ pub fn detect() -> Mode { platform::detect::detect() } -pub async fn notify(callback: &dyn Fn(Mode)) -> anyhow::Result<()> { - platform::notify::notify(callback).await +pub async fn notify(tx: Sender) -> anyhow::Result<()> { + platform::notify::notify(tx).await } \ No newline at end of file diff --git a/src/windows/notify.rs b/src/windows/notify.rs index eeea9df..025a965 100644 --- a/src/windows/notify.rs +++ b/src/windows/notify.rs @@ -1,5 +1,12 @@ -use crate::Mode; +use std::sync::mpsc::Sender; -pub async fn notify(callback: &dyn Fn(Mode)) -> anyhow::Result<()> { - todo!() +const duration: std::time::Duration = std::time::Duration::from_secs(1); + +pub async fn notify(tx: Sender) -> anyhow::Result<()> { + tx.send(crate::Mode::Default)?; + std::thread::sleep(duration); + tx.send(crate::Mode::Light)?; + std::thread::sleep(duration); + tx.send(crate::Mode::Dark)?; + Ok(()) } \ No newline at end of file