Skip to content

Commit

Permalink
Example implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
edfloreshz committed Dec 26, 2022
1 parent 6799f74 commit 2304583
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 43 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/target
/examples/*/target
Cargo.lock
15 changes: 3 additions & 12 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,16 @@ 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"
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"
Expand All @@ -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"
File renamed without changes.
9 changes: 0 additions & 9 deletions examples/detect/Cargo.toml

This file was deleted.

12 changes: 12 additions & 0 deletions examples/notify.rs
Original file line number Diff line number Diff line change
@@ -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)
}
}
9 changes: 0 additions & 9 deletions examples/notify/Cargo.toml

This file was deleted.

8 changes: 0 additions & 8 deletions examples/notify/src/main.rs

This file was deleted.

6 changes: 4 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

#[cfg(target_os = "macos")]
mod macos;
use std::sync::mpsc::Sender;

#[cfg(target_os = "macos")]
use macos as platform;

Expand Down Expand Up @@ -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<crate::Mode>) -> anyhow::Result<()> {
platform::notify::notify(tx).await
}
13 changes: 10 additions & 3 deletions src/windows/notify.rs
Original file line number Diff line number Diff line change
@@ -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<crate::Mode>) -> 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(())
}

0 comments on commit 2304583

Please sign in to comment.