From 33f683d5ed247ceb2f3cbc7b5d57ec5554315631 Mon Sep 17 00:00:00 2001 From: dvdmgl Date: Tue, 15 Jul 2025 16:56:53 +0100 Subject: [PATCH] fix cfg target and add unsupported to geolocation - fix cfg target in window - add unsupported to geolocation - android and ios theme it's not supported by tao Issue #80 --- packages/geolocation/src/core.rs | 5 ++++ packages/geolocation/src/lib.rs | 22 ++++++-------- packages/geolocation/src/platform/mod.rs | 3 ++ .../geolocation/src/platform/unsupported.rs | 30 +++++++++++++++++++ packages/notification/src/lib.rs | 3 ++ packages/window/src/size.rs | 10 +++---- packages/window/src/theme.rs | 12 ++++---- 7 files changed, 61 insertions(+), 24 deletions(-) create mode 100644 packages/geolocation/src/platform/unsupported.rs diff --git a/packages/geolocation/src/core.rs b/packages/geolocation/src/core.rs index c2f0e80..f7ea3ad 100644 --- a/packages/geolocation/src/core.rs +++ b/packages/geolocation/src/core.rs @@ -88,6 +88,7 @@ impl Geolocator { /// Describes errors that may occur when utilizing the geolocation abstraction. #[derive(Debug, Clone)] pub enum Error { + Unsupported, NotInitialized, AccessDenied, Poisoned, @@ -98,6 +99,10 @@ impl std::error::Error for Error {} impl fmt::Display for Error { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self { + Error::Unsupported => write!( + f, + "the geolocation feature is not supported on this platform" + ), Error::NotInitialized => write!(f, "not initialized"), Error::AccessDenied => { write!(f, "access denied (access may have been revoked during use)") diff --git a/packages/geolocation/src/lib.rs b/packages/geolocation/src/lib.rs index 3f03a9d..e39ef46 100644 --- a/packages/geolocation/src/lib.rs +++ b/packages/geolocation/src/lib.rs @@ -1,14 +1,10 @@ //! Interact with location services. - -cfg_if::cfg_if! { - if #[cfg(any(windows, target_family = "wasm"))] { - pub mod core; - pub mod platform; - pub mod use_geolocation; - pub use self::core::*; - pub use self::use_geolocation::*; - } - else { - compile_error!("the `geolocation` feature is only available on wasm and windows targets"); - } -} +//! +//! ## Platform-specific: +//! +//! **Android / iOS / Linux / Mac:** Unsupported. +pub mod core; +pub mod platform; +pub mod use_geolocation; +pub use self::core::*; +pub use self::use_geolocation::*; diff --git a/packages/geolocation/src/platform/mod.rs b/packages/geolocation/src/platform/mod.rs index e74ecd0..da01031 100644 --- a/packages/geolocation/src/platform/mod.rs +++ b/packages/geolocation/src/platform/mod.rs @@ -5,5 +5,8 @@ cfg_if::cfg_if! { } else if #[cfg(target_family = "wasm")] { mod wasm; pub use self::wasm::*; + } else { + mod unsupported; + pub use self::unsupported::*; } } diff --git a/packages/geolocation/src/platform/unsupported.rs b/packages/geolocation/src/platform/unsupported.rs new file mode 100644 index 0000000..a8b214e --- /dev/null +++ b/packages/geolocation/src/platform/unsupported.rs @@ -0,0 +1,30 @@ +use std::sync::Arc; + +use crate::core::{Error, Event, Geocoordinates, PowerMode}; + +/// Represents the HAL's geolocator. +pub struct Geolocator; + +impl Geolocator { + /// Create a new Geolocator for the device. + pub fn new() -> Result { + Err(Error::Unsupported) + } +} + +pub async fn get_coordinates(_geolocator: &Geolocator) -> Result { + Err(Error::Unsupported) +} + +/// Listen to new events with a callback. +pub fn listen( + _geolocator: &Geolocator, + _callback: Arc, +) -> Result<(), Error> { + Err(Error::Unsupported) +} + +/// Set the device's power mode. +pub fn set_power_mode(_geolocator: &mut Geolocator, _power_mode: PowerMode) -> Result<(), Error> { + Err(Error::Unsupported) +} diff --git a/packages/notification/src/lib.rs b/packages/notification/src/lib.rs index 84d9156..72cfdfb 100644 --- a/packages/notification/src/lib.rs +++ b/packages/notification/src/lib.rs @@ -1,6 +1,9 @@ //! Send desktop notifications. //! //! This crate only supports desktop targets (Windows, MacOS, & Linux). +//! ## Platform-specific: +//! +//! **Android / iOS / wasm:** Unsupported. #![deny(missing_docs)] use std::{ diff --git a/packages/window/src/size.rs b/packages/window/src/size.rs index 5b03889..0f28f7b 100644 --- a/packages/window/src/size.rs +++ b/packages/window/src/size.rs @@ -1,6 +1,6 @@ //! Window size utilities. //! -//! Acces the window size directly in your Dioxus app. +//! Access the window size directly in your Dioxus app. //! //! #### Platform Support //! Window size is available on every platform. @@ -13,7 +13,7 @@ //! //! fn App() -> Element { //! let size = use_window_size(); -//! let size = size().unwrap(); +//! let size = size().unwrap(); //! //! rsx! { //! p { "Width: {size.width}" } @@ -75,7 +75,7 @@ type WindowSizeResult = Result; /// /// fn App() -> Element { /// let size = use_window_size(); -/// +/// /// let half_of_width = use_memo(move || { /// let width = size.width().unwrap(); /// width / 2 @@ -120,7 +120,7 @@ impl ReadableWindowSizeExt for R where R: Readable /// /// fn App() -> Element { /// let size = use_window_size(); -/// let size = size().unwrap(); +/// let size = size().unwrap(); /// /// rsx! { /// p { "Width: {size.width}" } @@ -223,7 +223,7 @@ fn listen(mut window_size: Signal) { /// /// fn App() -> Element { /// let size = use_signal(get_window_size); -/// let size = size().unwrap(); +/// let size = size().unwrap(); /// /// rsx! { /// p { "Width: {size.width}" } diff --git a/packages/window/src/theme.rs b/packages/window/src/theme.rs index b8cbf13..7db8f69 100644 --- a/packages/window/src/theme.rs +++ b/packages/window/src/theme.rs @@ -6,7 +6,7 @@ //! We recommend using either [`Result::unwrap_or`] or [`Result::unwrap_or_default`] to do this. //! //! #### Platform Support -//! Theme is available for Web, Windows, & Mac. Linux is unsupported and Android/iOS has not been tested. +//! Theme is available for Web, Windows, & Mac. Linux is unsupported and Android/iOS are not supported. //! //! # Examples //! An example of using the theme to determine which class to use. @@ -17,7 +17,7 @@ //! #[component] //! fn App() -> Element { //! let theme = use_system_theme(); -//! +//! //! // Default to a light theme in the event of an error. //! let class = match theme().unwrap_or(Theme::Light) { //! Theme::Light => "bg-light", @@ -166,7 +166,7 @@ fn listen(mut theme: Signal) { // The listener implementation for desktop targets. (not linux) // This should only be called once. -#[cfg(not(target_family = "wasm"))] +#[cfg(not(any(target_family = "wasm", target_os = "linux")))] fn listen(mut theme: Signal) { use dioxus_desktop::{ WindowEvent, @@ -192,7 +192,7 @@ fn listen(mut theme: Signal) { } // The listener implementation for unsupported targets. -#[cfg(target_os = "linux")] +#[cfg(any(target_os = "linux", target_os = "android", target_os = "ios"))] fn listen(mut theme: Signal) { theme.set(Err(ThemeError::Unsupported)); } @@ -253,7 +253,7 @@ fn get_theme_platform() -> ThemeResult { } // The desktop (except linux) implementation to get the system theme. -#[cfg(not(target_family = "wasm"))] +#[cfg(any(target_os = "windows", target_os = "macos"))] fn get_theme_platform() -> ThemeResult { use dioxus_desktop::DesktopContext; use dioxus_desktop::tao::window::Theme as TaoTheme; @@ -272,7 +272,7 @@ fn get_theme_platform() -> ThemeResult { } // Implementation for unsupported platforms. -#[cfg(not(any(target_family = "wasm", target_os = "windows", target_os = "macos")))] +#[cfg(any(target_os = "linux", target_os = "android", target_os = "ios"))] fn get_theme_platform() -> ThemeResult { Err(ThemeError::Unsupported) }