From b10982b11d576af596e345d49b24de8740a57726 Mon Sep 17 00:00:00 2001 From: Eduardo Flores Date: Thu, 9 Jan 2025 22:04:17 +0100 Subject: [PATCH] remove: conditional errors --- src/error.rs | 57 +----------------------------------- src/platforms/freedesktop.rs | 9 ++++-- 2 files changed, 8 insertions(+), 58 deletions(-) diff --git a/src/error.rs b/src/error.rs index 8856d84..3bf4e6e 100644 --- a/src/error.rs +++ b/src/error.rs @@ -7,41 +7,18 @@ pub enum Error { Io(std::io::Error), /// If the system theme mode could not be detected. DetectionFailed, - - #[cfg(any( - target_os = "linux", - target_os = "freebsd", - target_os = "dragonfly", - target_os = "netbsd", - target_os = "openbsd" - ))] /// If the XDG Desktop Portal could not be communicated with. - XdgDesktopPortal(ashpd::Error), - - #[cfg(any( - target_os = "linux", - target_os = "freebsd", - target_os = "dragonfly", - target_os = "netbsd", - target_os = "openbsd" - ))] + XdgDesktopPortal(String), /// If the timeout is reached. Timeout, - /// Failed to get persistent domain for Apple Global Domain - #[cfg(target_os = "macos")] PersistentDomainFailed, /// Failed to get AppleInterfaceStyle - #[cfg(target_os = "macos")] AppleInterfaceStyleFailed, - - #[cfg(target_arch = "wasm32")] /// If the window could not be found. WindowNotFound, - #[cfg(target_arch = "wasm32")] /// If the media query could not be executed. MediaQueryFailed, - #[cfg(target_arch = "wasm32")] /// If the media query is not supported. MediaQueryNotSupported, } @@ -51,33 +28,14 @@ impl Display for Error { match self { Error::Io(error) => write!(f, "I/O error: {}", error), Error::DetectionFailed => write!(f, "Failed to detect system theme mode"), - #[cfg(any( - target_os = "linux", - target_os = "freebsd", - target_os = "dragonfly", - target_os = "netbsd", - target_os = "openbsd" - ))] Error::XdgDesktopPortal(err) => write!(f, "XDG Desktop Portal error: {}", err), - #[cfg(any( - target_os = "linux", - target_os = "freebsd", - target_os = "dragonfly", - target_os = "netbsd", - target_os = "openbsd" - ))] Error::Timeout => write!(f, "Timeout reached"), - #[cfg(target_os = "macos")] Error::PersistentDomainFailed => { write!(f, "Failed to get persistent domain for Apple Global Domain") } - #[cfg(target_os = "macos")] Error::AppleInterfaceStyleFailed => write!(f, "Failed to get AppleInterfaceStyle"), - #[cfg(target_arch = "wasm32")] Error::WindowNotFound => write!(f, "Window not found"), - #[cfg(target_arch = "wasm32")] Error::MediaQueryFailed => write!(f, "Media query failed"), - #[cfg(target_arch = "wasm32")] Error::MediaQueryNotSupported => write!(f, "Media query not supported"), } } @@ -90,16 +48,3 @@ impl From for Error { Error::Io(error) } } - -#[cfg(any( - target_os = "linux", - target_os = "freebsd", - target_os = "dragonfly", - target_os = "netbsd", - target_os = "openbsd" -))] -impl From for Error { - fn from(error: ashpd::Error) -> Self { - Error::XdgDesktopPortal(error) - } -} diff --git a/src/platforms/freedesktop.rs b/src/platforms/freedesktop.rs index bf0ab4e..272ae7d 100644 --- a/src/platforms/freedesktop.rs +++ b/src/platforms/freedesktop.rs @@ -8,8 +8,13 @@ use async_std::{future, task}; pub fn detect() -> Result { task::block_on(future::timeout(Duration::from_millis(25), async { - let settings = XdgPortalSettings::new().await?; - let color_scheme = settings.color_scheme().await?; + let settings = XdgPortalSettings::new() + .await + .map_err(|e| Error::XdgDesktopPortal(e.to_string()))?; + let color_scheme = settings + .color_scheme() + .await + .map_err(|e| Error::XdgDesktopPortal(e.to_string()))?; Ok::(color_scheme.into()) })) .map_err(|_| Error::Timeout)?