From 6d62d65fe9eb8d3961a9843a0c12164a84f0fcf5 Mon Sep 17 00:00:00 2001 From: Niclas van Eyk Date: Sun, 1 Sep 2024 18:04:09 +0200 Subject: [PATCH] move everything into one crate --- Cargo.lock | 18 +------ Cargo.toml | 31 +++++++++-- crates/dark-mode-daemon-linux/Cargo.toml | 8 --- crates/dark-mode-daemon-linux/src/main.rs | 19 ------- crates/dark-mode-daemon-macos/Cargo.toml | 22 -------- crates/dark-mode-daemon/Cargo.toml | 9 ---- crates/dark-mode-daemon/src/lib.rs | 23 -------- {crates/dark-mode-daemon/src => src}/cli.rs | 0 .../dark-mode-daemon/src => src}/discovery.rs | 0 .../dark-mode-daemon/src => src}/execution.rs | 0 src/main.rs | 52 +++++++++++++++++++ .../platform/linux}/gsettings/freedesktop.rs | 2 +- .../platform/linux}/gsettings/gnome.rs | 2 +- .../platform/linux}/gsettings/mod.rs | 4 +- src/platform/linux/mod.rs | 1 + .../src/main.rs => src/platform/macos.rs | 8 +-- src/platform/mod.rs | 5 ++ .../src => src}/platform_specifics.rs | 0 18 files changed, 94 insertions(+), 110 deletions(-) delete mode 100644 crates/dark-mode-daemon-linux/Cargo.toml delete mode 100644 crates/dark-mode-daemon-linux/src/main.rs delete mode 100644 crates/dark-mode-daemon-macos/Cargo.toml delete mode 100644 crates/dark-mode-daemon/Cargo.toml delete mode 100644 crates/dark-mode-daemon/src/lib.rs rename {crates/dark-mode-daemon/src => src}/cli.rs (100%) rename {crates/dark-mode-daemon/src => src}/discovery.rs (100%) rename {crates/dark-mode-daemon/src => src}/execution.rs (100%) create mode 100644 src/main.rs rename {crates/dark-mode-daemon-linux/src => src/platform/linux}/gsettings/freedesktop.rs (94%) rename {crates/dark-mode-daemon-linux/src => src/platform/linux}/gsettings/gnome.rs (96%) rename {crates/dark-mode-daemon-linux/src => src/platform/linux}/gsettings/mod.rs (95%) create mode 100644 src/platform/linux/mod.rs rename crates/dark-mode-daemon-macos/src/main.rs => src/platform/macos.rs (90%) create mode 100644 src/platform/mod.rs rename {crates/dark-mode-daemon/src => src}/platform_specifics.rs (100%) diff --git a/Cargo.lock b/Cargo.lock index 5c21d35..9f24911 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -132,27 +132,13 @@ checksum = "d3fd119d74b830634cea2a0f58bbd0d54540518a14397557951e79340abc28c0" name = "dark-mode-daemon" version = "0.1.0" dependencies = [ + "block2", "clap", - "xdg", -] - -[[package]] -name = "dark-mode-daemon-linux" -version = "0.1.0" -dependencies = [ - "dark-mode-daemon", "gio", -] - -[[package]] -name = "dark-mode-daemon-macos" -version = "0.1.0" -dependencies = [ - "block2", - "dark-mode-daemon", "objc2", "objc2-app-kit", "objc2-foundation", + "xdg", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index a848b85..c47c75d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/crates/dark-mode-daemon-linux/Cargo.toml b/crates/dark-mode-daemon-linux/Cargo.toml deleted file mode 100644 index a4a9fb1..0000000 --- a/crates/dark-mode-daemon-linux/Cargo.toml +++ /dev/null @@ -1,8 +0,0 @@ -[package] -name = "dark-mode-daemon-linux" -version = "0.1.0" -edition = "2021" - -[dependencies] -dark-mode-daemon = { path = "../dark-mode-daemon" } -gio = "0.20.1" diff --git a/crates/dark-mode-daemon-linux/src/main.rs b/crates/dark-mode-daemon-linux/src/main.rs deleted file mode 100644 index 92d736e..0000000 --- a/crates/dark-mode-daemon-linux/src/main.rs +++ /dev/null @@ -1,19 +0,0 @@ -mod gsettings; - -use gsettings::{ - freedesktop::FreeDesktopSettingsProvider, gnome::GnomeDesktopSettingsProvider, - GSettingsAdapter, SettingsProviderImplementation, -}; - -fn main() { - let implementation = SettingsProviderImplementation::Gnome; - - match implementation { - SettingsProviderImplementation::Gnome => { - dark_mode_daemon::cli::run(GSettingsAdapter::::new()); - } - SettingsProviderImplementation::Freedesktop => { - dark_mode_daemon::cli::run(GSettingsAdapter::::new()); - } - }; -} diff --git a/crates/dark-mode-daemon-macos/Cargo.toml b/crates/dark-mode-daemon-macos/Cargo.toml deleted file mode 100644 index 7a0ae49..0000000 --- a/crates/dark-mode-daemon-macos/Cargo.toml +++ /dev/null @@ -1,22 +0,0 @@ -[package] -name = "dark-mode-daemon-macos" -version = "0.1.0" -edition = "2021" - -[dependencies] -block2 = "0.5.1" -dark-mode-daemon = { path = "../dark-mode-daemon" } -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", -] } diff --git a/crates/dark-mode-daemon/Cargo.toml b/crates/dark-mode-daemon/Cargo.toml deleted file mode 100644 index 4906bad..0000000 --- a/crates/dark-mode-daemon/Cargo.toml +++ /dev/null @@ -1,9 +0,0 @@ -[package] -name = "dark-mode-daemon" -description = "The core logic for the os-specific dark-mode-daemon binaries." -version = "0.1.0" -edition = "2021" - -[dependencies] -xdg = "2.5.2" -clap = { version = "4.5.16", features = ["derive"] } diff --git a/crates/dark-mode-daemon/src/lib.rs b/crates/dark-mode-daemon/src/lib.rs deleted file mode 100644 index b135ce5..0000000 --- a/crates/dark-mode-daemon/src/lib.rs +++ /dev/null @@ -1,23 +0,0 @@ -use std::fmt::Display; - -pub mod cli; -pub mod discovery; -pub mod execution; -pub mod platform_specifics; - -use clap::ValueEnum; - -#[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"), - } - } -} diff --git a/crates/dark-mode-daemon/src/cli.rs b/src/cli.rs similarity index 100% rename from crates/dark-mode-daemon/src/cli.rs rename to src/cli.rs diff --git a/crates/dark-mode-daemon/src/discovery.rs b/src/discovery.rs similarity index 100% rename from crates/dark-mode-daemon/src/discovery.rs rename to src/discovery.rs diff --git a/crates/dark-mode-daemon/src/execution.rs b/src/execution.rs similarity index 100% rename from crates/dark-mode-daemon/src/execution.rs rename to src/execution.rs diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..a2ea94e --- /dev/null +++ b/src/main.rs @@ -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::::new()); + } + SettingsProviderImplementation::Freedesktop => { + dark_mode_daemon::cli::run(GSettingsAdapter::::new()); + } + }; +} diff --git a/crates/dark-mode-daemon-linux/src/gsettings/freedesktop.rs b/src/platform/linux/gsettings/freedesktop.rs similarity index 94% rename from crates/dark-mode-daemon-linux/src/gsettings/freedesktop.rs rename to src/platform/linux/gsettings/freedesktop.rs index 3fa7729..56d8b41 100644 --- a/crates/dark-mode-daemon-linux/src/gsettings/freedesktop.rs +++ b/src/platform/linux/gsettings/freedesktop.rs @@ -1,4 +1,4 @@ -use dark_mode_daemon::ColorMode; +use crate::ColorMode; use gio::{prelude::SettingsExtManual, Settings}; use super::SettingsProvider; diff --git a/crates/dark-mode-daemon-linux/src/gsettings/gnome.rs b/src/platform/linux/gsettings/gnome.rs similarity index 96% rename from crates/dark-mode-daemon-linux/src/gsettings/gnome.rs rename to src/platform/linux/gsettings/gnome.rs index 0cbf553..9462ac6 100644 --- a/crates/dark-mode-daemon-linux/src/gsettings/gnome.rs +++ b/src/platform/linux/gsettings/gnome.rs @@ -1,4 +1,4 @@ -use dark_mode_daemon::ColorMode; +use crate::ColorMode; use gio::{prelude::SettingsExtManual, Settings}; use super::SettingsProvider; diff --git a/crates/dark-mode-daemon-linux/src/gsettings/mod.rs b/src/platform/linux/gsettings/mod.rs similarity index 95% rename from crates/dark-mode-daemon-linux/src/gsettings/mod.rs rename to src/platform/linux/gsettings/mod.rs index e5bac33..18c83a8 100644 --- a/crates/dark-mode-daemon-linux/src/gsettings/mod.rs +++ b/src/platform/linux/gsettings/mod.rs @@ -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; diff --git a/src/platform/linux/mod.rs b/src/platform/linux/mod.rs new file mode 100644 index 0000000..0a44c4f --- /dev/null +++ b/src/platform/linux/mod.rs @@ -0,0 +1 @@ +pub mod gsettings; diff --git a/crates/dark-mode-daemon-macos/src/main.rs b/src/platform/macos.rs similarity index 90% rename from crates/dark-mode-daemon-macos/src/main.rs rename to src/platform/macos.rs index ebfc291..d16e69d 100644 --- a/crates/dark-mode-daemon-macos/src/main.rs +++ b/src/platform/macos.rs @@ -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> { unsafe { @@ -57,7 +57,3 @@ impl NativeAdapter for MacOSNativeAdapter { current_mode() } } - -fn main() { - dark_mode_daemon::cli::run(MacOSNativeAdapter::default()); -} diff --git a/src/platform/mod.rs b/src/platform/mod.rs new file mode 100644 index 0000000..a392f87 --- /dev/null +++ b/src/platform/mod.rs @@ -0,0 +1,5 @@ +#[cfg(target_os = "macos")] +pub mod macos; + +#[cfg(target_os = "linux")] +pub mod linux; diff --git a/crates/dark-mode-daemon/src/platform_specifics.rs b/src/platform_specifics.rs similarity index 100% rename from crates/dark-mode-daemon/src/platform_specifics.rs rename to src/platform_specifics.rs