Skip to content

Commit

Permalink
move everything into one crate
Browse files Browse the repository at this point in the history
  • Loading branch information
NiclasvanEyk committed Sep 1, 2024
1 parent a501d21 commit 6d62d65
Show file tree
Hide file tree
Showing 18 changed files with 94 additions and 110 deletions.
18 changes: 2 additions & 16 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 28 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,28 @@
[workspace]
resolver = "2"
members = ["crates/*"]
[package]
name = "dark-mode-daemon"
version = "0.1.0"
edition = "2021"

[dependencies]
xdg = "2.5.2"
clap = { version = "4.5.16", features = ["derive"] }

[target.'cfg(target_os = "macos")'.dependencies]
block2 = "0.5.1"
objc2 = { version = "0.5.2" }
objc2-app-kit = { version = "0.2.2", features = [
"NSApplication",
"NSResponder",
] }
objc2-foundation = { version = "0.2.2", features = [
"NSNotification",
"NSDistributedNotificationCenter",
"NSOperation",
"NSString",
"NSThread",
"NSUserDefaults",
"block2",
] }

[target.'cfg(target_os = "linux")'.dependencies]
gio = "0.20.1"
8 changes: 0 additions & 8 deletions crates/dark-mode-daemon-linux/Cargo.toml

This file was deleted.

19 changes: 0 additions & 19 deletions crates/dark-mode-daemon-linux/src/main.rs

This file was deleted.

22 changes: 0 additions & 22 deletions crates/dark-mode-daemon-macos/Cargo.toml

This file was deleted.

9 changes: 0 additions & 9 deletions crates/dark-mode-daemon/Cargo.toml

This file was deleted.

23 changes: 0 additions & 23 deletions crates/dark-mode-daemon/src/lib.rs

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
52 changes: 52 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
use std::fmt::Display;

pub mod cli;
pub mod discovery;
pub mod execution;
pub mod platform;
pub mod platform_specifics;

use clap::ValueEnum;

#[cfg(target_os = "macos")]
use crate::platform::macos::MacOSNativeAdapter;

#[cfg(target_os = "linux")]
use gsettings::{
freedesktop::FreeDesktopSettingsProvider, gnome::GnomeDesktopSettingsProvider,
GSettingsAdapter, SettingsProviderImplementation,
};

#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, ValueEnum)]
pub enum ColorMode {
Light,
Dark,
}

impl Display for ColorMode {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
ColorMode::Light => write!(f, "light"),
ColorMode::Dark => write!(f, "dark"),
}
}
}

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

#[cfg(target_os = "linux")]
fn main() {
let implementation = SettingsProviderImplementation::Gnome;

match implementation {
SettingsProviderImplementation::Gnome => {
dark_mode_daemon::cli::run(GSettingsAdapter::<GnomeDesktopSettingsProvider>::new());
}
SettingsProviderImplementation::Freedesktop => {
dark_mode_daemon::cli::run(GSettingsAdapter::<FreeDesktopSettingsProvider>::new());
}
};
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use dark_mode_daemon::ColorMode;
use crate::ColorMode;
use gio::{prelude::SettingsExtManual, Settings};

use super::SettingsProvider;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use dark_mode_daemon::ColorMode;
use crate::ColorMode;
use gio::{prelude::SettingsExtManual, Settings};

use super::SettingsProvider;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use std::result::Result;
use std::sync::mpsc::{channel, Receiver};
use std::{marker::PhantomData, sync::mpsc::Sender};

use dark_mode_daemon::execution::run_scripts;
use dark_mode_daemon::{platform_specifics::NativeAdapter, ColorMode};
use crate::execution::run_scripts;
use crate::{platform_specifics::NativeAdapter, ColorMode};
use gio::prelude::ObjectExt;
use gio::Settings;

Expand Down
1 change: 1 addition & 0 deletions src/platform/linux/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod gsettings;
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use std::error::Error;

use crate::{execution::run_scripts, platform_specifics::NativeAdapter, ColorMode};
use block2::RcBlock;
use dark_mode_daemon::{execution::run_scripts, platform_specifics::NativeAdapter, ColorMode};
use objc2_app_kit::NSApplication;
use objc2_foundation::{ns_string, MainThreadMarker, NSDistributedNotificationCenter};

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

fn current_mode() -> Result<ColorMode, Box<dyn Error>> {
unsafe {
Expand Down Expand Up @@ -57,7 +57,3 @@ impl NativeAdapter for MacOSNativeAdapter {
current_mode()
}
}

fn main() {
dark_mode_daemon::cli::run(MacOSNativeAdapter::default());
}
5 changes: 5 additions & 0 deletions src/platform/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#[cfg(target_os = "macos")]
pub mod macos;

#[cfg(target_os = "linux")]
pub mod linux;
File renamed without changes.

0 comments on commit 6d62d65

Please sign in to comment.