Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/geolocation/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)")
Expand Down
22 changes: 9 additions & 13 deletions packages/geolocation/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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::*;
3 changes: 3 additions & 0 deletions packages/geolocation/src/platform/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
}
}
30 changes: 30 additions & 0 deletions packages/geolocation/src/platform/unsupported.rs
Original file line number Diff line number Diff line change
@@ -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<Self, Error> {
Err(Error::Unsupported)
}
}

pub async fn get_coordinates(_geolocator: &Geolocator) -> Result<Geocoordinates, Error> {
Err(Error::Unsupported)
}

/// Listen to new events with a callback.
pub fn listen(
_geolocator: &Geolocator,
_callback: Arc<dyn Fn(Event) + Send + Sync>,
) -> 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)
}
3 changes: 3 additions & 0 deletions packages/notification/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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::{
Expand Down
10 changes: 5 additions & 5 deletions packages/window/src/size.rs
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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}" }
Expand Down Expand Up @@ -75,7 +75,7 @@ type WindowSizeResult = Result<WindowSize, WindowSizeError>;
///
/// fn App() -> Element {
/// let size = use_window_size();
///
///
/// let half_of_width = use_memo(move || {
/// let width = size.width().unwrap();
/// width / 2
Expand Down Expand Up @@ -120,7 +120,7 @@ impl<R> ReadableWindowSizeExt for R where R: Readable<Target = WindowSizeResult>
///
/// fn App() -> Element {
/// let size = use_window_size();
/// let size = size().unwrap();
/// let size = size().unwrap();
///
/// rsx! {
/// p { "Width: {size.width}" }
Expand Down Expand Up @@ -223,7 +223,7 @@ fn listen(mut window_size: Signal<WindowSizeResult>) {
///
/// fn App() -> Element {
/// let size = use_signal(get_window_size);
/// let size = size().unwrap();
/// let size = size().unwrap();
///
/// rsx! {
/// p { "Width: {size.width}" }
Expand Down
12 changes: 6 additions & 6 deletions packages/window/src/theme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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",
Expand Down Expand Up @@ -166,7 +166,7 @@ fn listen(mut theme: Signal<ThemeResult>) {

// 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<ThemeResult>) {
use dioxus_desktop::{
WindowEvent,
Expand All @@ -192,7 +192,7 @@ fn listen(mut theme: Signal<ThemeResult>) {
}

// 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<ThemeResult>) {
theme.set(Err(ThemeError::Unsupported));
}
Expand Down Expand Up @@ -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;
Expand All @@ -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)
}