Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Default variant #25

Merged
merged 2 commits into from Dec 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/freedesktop.rs
Expand Up @@ -90,7 +90,7 @@ pub fn detect() -> Mode {
DesktopEnvironment::Gnome => detect_gtk("/org/gnome/desktop/interface/gtk-theme"),
DesktopEnvironment::Mate => detect_gtk("/org/mate/desktop/interface/gtk-theme"),
DesktopEnvironment::Unity => detect_gtk("/org/gnome/desktop/interface/gtk-theme"),
_ => Mode::Light,
_ => Mode::Default,
},
}
}
2 changes: 2 additions & 0 deletions src/lib.rs
Expand Up @@ -8,6 +8,7 @@
//! match mode {
//! dark_light::Mode::Dark => {},
//! dark_light::Mode::Light => {},
//! dark_light::Mode::Default => {},
//! }
//! ```

Expand Down Expand Up @@ -63,6 +64,7 @@ mod platform {
pub enum Mode {
Dark,
Light,
Default,
}

impl Mode {
Expand Down
16 changes: 7 additions & 9 deletions src/windows.rs
@@ -1,17 +1,15 @@
use crate::Mode;
use winreg::RegKey;

const SUBKEY: &str = "Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize";
const VALUE: &str = "AppsUseLightTheme";

pub fn detect() -> Mode {
let hkcu = RegKey::predef(winreg::enums::HKEY_CURRENT_USER);
if let Ok(subkey) =
hkcu.open_subkey("Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize")
{
if let Ok(dword) = subkey.get_value::<u32, _>("AppsUseLightTheme") {
Mode::from(dword == 0)
} else {
Mode::Light
if let Ok(subkey) = hkcu.open_subkey(SUBKEY) {
if let Ok(dword) = subkey.get_value::<u32, _>(VALUE) {
return Mode::from(dword == 0);
}
} else {
Mode::Light
}
Mode::Light
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you mean:

Suggested change
Mode::Light
Mode::Default

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Default was added to comply with the FreeDesktop specification, I don't think it really applies to Windows or macOS.

}