Skip to content

Commit

Permalink
refactoring + dark_light-based windows impl
Browse files Browse the repository at this point in the history
  • Loading branch information
NiclasvanEyk committed Sep 15, 2024
1 parent e4377de commit 1bfd6f3
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 8 deletions.
6 changes: 6 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,9 @@ dark-light = { git = "https://github.com/frewsxcv/rust-dark-light", version = "1
futures = "0.3.30"
tokio = { version = "1.40.0", features = ["rt", "rt-multi-thread"] }
anyhow = "1.0.89"

[target.'cfg(target_os = "windows")'.dependencies]
dark-light = { git = "https://github.com/frewsxcv/rust-dark-light", version = "1.1.1", rev = "77ae4349f11a556cef9c683803a832f171253479" }
futures = "0.3.30"
tokio = { version = "1.40.0", features = ["rt", "rt-multi-thread"] }
anyhow = "1.0.89"
9 changes: 7 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,15 @@ pub mod platform;

#[cfg(target_os = "macos")]
fn main() {
crate::cli::run(crate::platform::macos::MacOSNativeAdapter);
crate::cli::run(crate::platform::macos::MacOsAdapter::default());
}

#[cfg(target_os = "linux")]
fn main() {
crate::cli::run(crate::platform::linux::LinuxAdapter::default());
crate::cli::run(crate::platform::dark_light::DarkLightAdapter::default());
}

#[cfg(target_os = "windows")]
fn main() {
crate::cli::run(crate::platform::dark_light::DarkLightAdapter::default());
}
5 changes: 3 additions & 2 deletions src/platform/linux/mod.rs → src/platform/dark_light.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::execution::run_scripts;
use crate::{mode::ColorMode, platform::NativeAdapter};

#[derive(Default)]
pub struct LinuxAdapter {}
pub struct DarkLightAdapter {}

async fn run_scripts_on_mode_change(verbose: bool) -> anyhow::Result<()> {
while let Some(mode) = dark_light::subscribe().await?.next().await {
Expand All @@ -21,7 +21,8 @@ async fn run_scripts_on_mode_change(verbose: bool) -> anyhow::Result<()> {

Ok(())
}
impl NativeAdapter for LinuxAdapter {

impl NativeAdapter for DarkLightAdapter {
fn run_daemon(&self, verbose: bool) {
tokio::runtime::Builder::new_multi_thread()
.enable_all()
Expand Down
2 changes: 2 additions & 0 deletions src/platform/linux.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@


4 changes: 2 additions & 2 deletions src/platform/macos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use objc2_app_kit::NSApplication;
use objc2_foundation::{ns_string, MainThreadMarker, NSDistributedNotificationCenter};

#[derive(Default)]
pub(crate) struct MacOSNativeAdapter {}
pub(crate) struct MacOsAdapter {}

fn current_mode() -> Result<ColorMode, Box<dyn Error>> {
unsafe {
Expand All @@ -28,7 +28,7 @@ fn current_mode() -> Result<ColorMode, Box<dyn Error>> {
}
}

impl NativeAdapter for MacOSNativeAdapter {
impl NativeAdapter for MacOsAdapter {
fn run_daemon(&self, verbose: bool) {
unsafe {
let notification_center = NSDistributedNotificationCenter::defaultCenter();
Expand Down
4 changes: 2 additions & 2 deletions src/platform/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#[cfg(target_os = "macos")]
pub mod macos;

#[cfg(target_os = "linux")]
pub mod linux;
#[cfg(any(target_os = "windows", target_os = "linux"))]
pub mod dark_light;

use crate::mode::ColorMode;
use std::error::Error;
Expand Down

0 comments on commit 1bfd6f3

Please sign in to comment.