Skip to content

Commit 5558767

Browse files
committed
Make async-std/tokio/futures-lite optional
1 parent c22d3d7 commit 5558767

File tree

4 files changed

+34
-20
lines changed

4 files changed

+34
-20
lines changed

Cargo.toml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ targets = [
2828
]
2929

3030
[features]
31-
default = ["rwh_06", "x11", "async-std"]
32-
async-std = ["ashpd/async-std"]
33-
tokio = ["ashpd/tokio"]
31+
default = [ "rwh_06", "x11" ]
32+
async-std = ["dep:ashpd", "dep:futures-lite", "dep:async-compat", "ashpd/async-std"]
33+
tokio = ["dep:ashpd", "dep:futures-lite", "dep:async-compat", "ashpd/tokio"]
3434
serde = ["dep:serde", "dpi/serde"]
3535
rwh_04 = ["dep:rwh_04"]
3636
rwh_05 = ["dep:rwh_05"]
@@ -159,6 +159,6 @@ gdkwayland-sys = "0.18.0"
159159
x11-dl = { version = "2.21", optional = true }
160160
parking_lot = "0.12"
161161
dlopen2 = "0.8.0"
162-
ashpd = { version = "0.12", features = ["async-std"], default-features = false }
163-
futures-lite = "2.6"
164-
async-compat = "0.2"
162+
ashpd = { version = "0.12", default-features = false, optional = true }
163+
futures-lite = { version = "2.6", optional = true }
164+
async-compat = { version = "0.2", optional = true }

src/platform_impl/linux/event_loop.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -285,12 +285,15 @@ impl<T: 'static> EventLoop<T> {
285285
let is_wayland = window_target.is_wayland();
286286

287287
// Receive portal events
288-
let tx_requests_clone = window_target.window_requests_tx.clone();
289-
glib::spawn_future_local(async move {
290-
if let Err(e) = super::portal::receive_theme_changed(tx_requests_clone).await {
291-
log::debug!("Unable to receive theme changed events: {e}");
292-
}
293-
});
288+
#[cfg(any(feature = "tokio", feature = "async-std"))]
289+
{
290+
let tx_requests_clone = window_target.window_requests_tx.clone();
291+
glib::spawn_future_local(async move {
292+
if let Err(e) = super::portal::receive_theme_changed(tx_requests_clone).await {
293+
log::debug!("Unable to receive theme changed events: {e}");
294+
}
295+
});
296+
}
294297

295298
// Window Request
296299
window_requests_rx.attach(Some(&context), move |(id, request)| {

src/platform_impl/linux/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ mod icon;
99
mod keyboard;
1010
mod keycode;
1111
mod monitor;
12+
#[cfg(any(feature = "tokio", feature = "async-std"))]
1213
mod portal;
1314
mod util;
1415
mod window;

src/platform_impl/linux/window.rs

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -194,15 +194,24 @@ impl Window {
194194
}
195195

196196
// Set initial `preferred_theme` value to current portal color-scheme
197-
let ctx = glib::MainContext::default();
198-
let portal_theme = ctx.block_on(async { super::portal::theme().await });
199-
let preferred_theme = if let Ok(theme) = portal_theme {
200-
if let Some(settings) = Settings::default() {
201-
settings.set_gtk_application_prefer_dark_theme(theme == Theme::Dark);
197+
let preferred_theme = {
198+
#[cfg(any(feature = "tokio", feature = "async-std"))]
199+
{
200+
let ctx = glib::MainContext::default();
201+
let portal_theme = ctx.block_on(async { super::portal::theme().await });
202+
if let Ok(theme) = portal_theme {
203+
if let Some(settings) = Settings::default() {
204+
settings.set_gtk_application_prefer_dark_theme(theme == Theme::Dark);
205+
}
206+
Some(theme)
207+
} else {
208+
None
209+
}
210+
}
211+
#[cfg(not(any(feature = "tokio", feature = "async-std")))]
212+
{
213+
None
202214
}
203-
Some(theme)
204-
} else {
205-
None
206215
};
207216

208217
if attributes.visible {
@@ -1013,6 +1022,7 @@ impl Window {
10131022
return theme;
10141023
}
10151024

1025+
#[cfg(any(feature = "tokio", feature = "async-std"))]
10161026
if let Some(portal_theme) =
10171027
glib::MainContext::default().block_on(async { super::portal::theme().await.ok() })
10181028
{

0 commit comments

Comments
 (0)