Skip to content

Commit

Permalink
impl From<bool> for Mode
Browse files Browse the repository at this point in the history
Use the std API instead of inventing our own
  • Loading branch information
Be-ing committed Jan 6, 2025
1 parent 85dc9d6 commit 928c891
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
7 changes: 3 additions & 4 deletions src/mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@ pub enum Mode {
Default,
}

impl Mode {
#[allow(dead_code)]
/// Creates a `Mode` value from a boolean value.
pub fn from_bool(b: bool) -> Self {
/// Creates a `Mode` value from a boolean value.
impl From<bool> for Mode {
fn from(b: bool) -> Self {
if b {
Mode::Dark
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/platforms/macos/detect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
#[cfg(any(feature = "sync", doc))]
pub mod sync {
pub fn detect() -> crate::Mode {
crate::Mode::from_bool(super::super::is_dark_mode())
super::super::is_dark_mode().into()
}
}

pub async fn detect() -> crate::Mode {
crate::Mode::from_bool(super::is_dark_mode())
super::is_dark_mode().into()
}
2 changes: 1 addition & 1 deletion src/platforms/windows/detect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub fn detect_mode() -> Mode {
let hkcu = RegKey::predef(winreg::enums::HKEY_CURRENT_USER);
if let Ok(subkey) = hkcu.open_subkey(SUBKEY) {
if let Ok(dword) = subkey.get_value::<u32, _>(VALUE) {
return Mode::from_bool(dword == 0);
return (dword == 0).into();
}
}
Mode::Light
Expand Down

0 comments on commit 928c891

Please sign in to comment.