Skip to content

Commit 33f683d

Browse files
committed
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
1 parent e2c601b commit 33f683d

File tree

7 files changed

+61
-24
lines changed

7 files changed

+61
-24
lines changed

packages/geolocation/src/core.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ impl Geolocator {
8888
/// Describes errors that may occur when utilizing the geolocation abstraction.
8989
#[derive(Debug, Clone)]
9090
pub enum Error {
91+
Unsupported,
9192
NotInitialized,
9293
AccessDenied,
9394
Poisoned,
@@ -98,6 +99,10 @@ impl std::error::Error for Error {}
9899
impl fmt::Display for Error {
99100
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
100101
match self {
102+
Error::Unsupported => write!(
103+
f,
104+
"the geolocation feature is not supported on this platform"
105+
),
101106
Error::NotInitialized => write!(f, "not initialized"),
102107
Error::AccessDenied => {
103108
write!(f, "access denied (access may have been revoked during use)")

packages/geolocation/src/lib.rs

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
//! Interact with location services.
2-
3-
cfg_if::cfg_if! {
4-
if #[cfg(any(windows, target_family = "wasm"))] {
5-
pub mod core;
6-
pub mod platform;
7-
pub mod use_geolocation;
8-
pub use self::core::*;
9-
pub use self::use_geolocation::*;
10-
}
11-
else {
12-
compile_error!("the `geolocation` feature is only available on wasm and windows targets");
13-
}
14-
}
2+
//!
3+
//! ## Platform-specific:
4+
//!
5+
//! **Android / iOS / Linux / Mac:** Unsupported.
6+
pub mod core;
7+
pub mod platform;
8+
pub mod use_geolocation;
9+
pub use self::core::*;
10+
pub use self::use_geolocation::*;

packages/geolocation/src/platform/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,8 @@ cfg_if::cfg_if! {
55
} else if #[cfg(target_family = "wasm")] {
66
mod wasm;
77
pub use self::wasm::*;
8+
} else {
9+
mod unsupported;
10+
pub use self::unsupported::*;
811
}
912
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
use std::sync::Arc;
2+
3+
use crate::core::{Error, Event, Geocoordinates, PowerMode};
4+
5+
/// Represents the HAL's geolocator.
6+
pub struct Geolocator;
7+
8+
impl Geolocator {
9+
/// Create a new Geolocator for the device.
10+
pub fn new() -> Result<Self, Error> {
11+
Err(Error::Unsupported)
12+
}
13+
}
14+
15+
pub async fn get_coordinates(_geolocator: &Geolocator) -> Result<Geocoordinates, Error> {
16+
Err(Error::Unsupported)
17+
}
18+
19+
/// Listen to new events with a callback.
20+
pub fn listen(
21+
_geolocator: &Geolocator,
22+
_callback: Arc<dyn Fn(Event) + Send + Sync>,
23+
) -> Result<(), Error> {
24+
Err(Error::Unsupported)
25+
}
26+
27+
/// Set the device's power mode.
28+
pub fn set_power_mode(_geolocator: &mut Geolocator, _power_mode: PowerMode) -> Result<(), Error> {
29+
Err(Error::Unsupported)
30+
}

packages/notification/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
//! Send desktop notifications.
22
//!
33
//! This crate only supports desktop targets (Windows, MacOS, & Linux).
4+
//! ## Platform-specific:
5+
//!
6+
//! **Android / iOS / wasm:** Unsupported.
47
#![deny(missing_docs)]
58

69
use std::{

packages/window/src/size.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Window size utilities.
22
//!
3-
//! Acces the window size directly in your Dioxus app.
3+
//! Access the window size directly in your Dioxus app.
44
//!
55
//! #### Platform Support
66
//! Window size is available on every platform.
@@ -13,7 +13,7 @@
1313
//!
1414
//! fn App() -> Element {
1515
//! let size = use_window_size();
16-
//! let size = size().unwrap();
16+
//! let size = size().unwrap();
1717
//!
1818
//! rsx! {
1919
//! p { "Width: {size.width}" }
@@ -75,7 +75,7 @@ type WindowSizeResult = Result<WindowSize, WindowSizeError>;
7575
///
7676
/// fn App() -> Element {
7777
/// let size = use_window_size();
78-
///
78+
///
7979
/// let half_of_width = use_memo(move || {
8080
/// let width = size.width().unwrap();
8181
/// width / 2
@@ -120,7 +120,7 @@ impl<R> ReadableWindowSizeExt for R where R: Readable<Target = WindowSizeResult>
120120
///
121121
/// fn App() -> Element {
122122
/// let size = use_window_size();
123-
/// let size = size().unwrap();
123+
/// let size = size().unwrap();
124124
///
125125
/// rsx! {
126126
/// p { "Width: {size.width}" }
@@ -223,7 +223,7 @@ fn listen(mut window_size: Signal<WindowSizeResult>) {
223223
///
224224
/// fn App() -> Element {
225225
/// let size = use_signal(get_window_size);
226-
/// let size = size().unwrap();
226+
/// let size = size().unwrap();
227227
///
228228
/// rsx! {
229229
/// p { "Width: {size.width}" }

packages/window/src/theme.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
//! We recommend using either [`Result::unwrap_or`] or [`Result::unwrap_or_default`] to do this.
77
//!
88
//! #### Platform Support
9-
//! Theme is available for Web, Windows, & Mac. Linux is unsupported and Android/iOS has not been tested.
9+
//! Theme is available for Web, Windows, & Mac. Linux is unsupported and Android/iOS are not supported.
1010
//!
1111
//! # Examples
1212
//! An example of using the theme to determine which class to use.
@@ -17,7 +17,7 @@
1717
//! #[component]
1818
//! fn App() -> Element {
1919
//! let theme = use_system_theme();
20-
//!
20+
//!
2121
//! // Default to a light theme in the event of an error.
2222
//! let class = match theme().unwrap_or(Theme::Light) {
2323
//! Theme::Light => "bg-light",
@@ -166,7 +166,7 @@ fn listen(mut theme: Signal<ThemeResult>) {
166166

167167
// The listener implementation for desktop targets. (not linux)
168168
// This should only be called once.
169-
#[cfg(not(target_family = "wasm"))]
169+
#[cfg(not(any(target_family = "wasm", target_os = "linux")))]
170170
fn listen(mut theme: Signal<ThemeResult>) {
171171
use dioxus_desktop::{
172172
WindowEvent,
@@ -192,7 +192,7 @@ fn listen(mut theme: Signal<ThemeResult>) {
192192
}
193193

194194
// The listener implementation for unsupported targets.
195-
#[cfg(target_os = "linux")]
195+
#[cfg(any(target_os = "linux", target_os = "android", target_os = "ios"))]
196196
fn listen(mut theme: Signal<ThemeResult>) {
197197
theme.set(Err(ThemeError::Unsupported));
198198
}
@@ -253,7 +253,7 @@ fn get_theme_platform() -> ThemeResult {
253253
}
254254

255255
// The desktop (except linux) implementation to get the system theme.
256-
#[cfg(not(target_family = "wasm"))]
256+
#[cfg(any(target_os = "windows", target_os = "macos"))]
257257
fn get_theme_platform() -> ThemeResult {
258258
use dioxus_desktop::DesktopContext;
259259
use dioxus_desktop::tao::window::Theme as TaoTheme;
@@ -272,7 +272,7 @@ fn get_theme_platform() -> ThemeResult {
272272
}
273273

274274
// Implementation for unsupported platforms.
275-
#[cfg(not(any(target_family = "wasm", target_os = "windows", target_os = "macos")))]
275+
#[cfg(any(target_os = "linux", target_os = "android", target_os = "ios"))]
276276
fn get_theme_platform() -> ThemeResult {
277277
Err(ThemeError::Unsupported)
278278
}

0 commit comments

Comments
 (0)