Skip to content

Commit

Permalink
refactor: get_color_scheme
Browse files Browse the repository at this point in the history
  • Loading branch information
edfloreshz committed Jan 9, 2025
1 parent 16f56a1 commit 9d9c85e
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/platforms/freedesktop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,19 @@ use ashpd::desktop::settings::Settings as XdgPortalSettings;
use async_std::{future, task};

pub fn detect() -> Result<Mode, Error> {
task::block_on(async {
future::timeout(Duration::from_millis(25), get_color_scheme())
let get_color_scheme = async {
let settings = XdgPortalSettings::new().await?;
let color_scheme = settings.color_scheme().await?;
Ok(color_scheme.into())
};

let timeout = async {
future::timeout(Duration::from_millis(25), get_color_scheme)
.await
.map_err(|_| Error::Timeout)?
})
}
};

pub(crate) async fn get_color_scheme() -> Result<Mode, Error> {
let settings = XdgPortalSettings::new().await?;
let color_scheme = settings.color_scheme().await?;
Ok(color_scheme.into())
task::block_on(timeout)
}

impl From<PortalColorScheme> for Mode {
Expand Down

0 comments on commit 9d9c85e

Please sign in to comment.