Skip to content

Commit 3270532

Browse files
committed
Make async-std/tokio/futures-lite optional
1 parent 03ca810 commit 3270532

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,13 +28,13 @@ targets = [
2828
]
2929

3030
[features]
31-
default = [ "rwh_06", "x11", "async-std" ]
32-
async-std = ["ashpd/async-std"]
31+
default = [ "rwh_06", "x11" ]
32+
async-std = ["dep:ashpd", "dep:futures-lite", "dep:async-compat", "ashpd/async-std"]
3333
rwh_04 = [ "dep:rwh_04" ]
3434
rwh_05 = [ "dep:rwh_05" ]
3535
rwh_06 = [ "dep:rwh_06" ]
3636
serde = [ "dep:serde", "dpi/serde" ]
37-
tokio = ["ashpd/tokio"]
37+
tokio = ["dep:ashpd", "dep:futures-lite", "dep:async-compat", "ashpd/tokio"]
3838
x11 = [ "dep:gdkx11-sys", "dep:x11-dl" ]
3939

4040
[workspace]
@@ -158,6 +158,6 @@ gdkwayland-sys = "0.18.0"
158158
x11-dl = { version = "2.21", optional = true }
159159
parking_lot = "0.12"
160160
dlopen2 = "0.8.0"
161-
ashpd = { version = "0.12", default-features = false }
162-
futures-lite = "2.6"
163-
async-compat = "0.2"
161+
ashpd = { version = "0.12", default-features = false, optional = true }
162+
futures-lite = { version = "2.6", optional = true }
163+
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
@@ -286,12 +286,15 @@ impl<T: 'static> EventLoop<T> {
286286
let is_wayland = window_target.is_wayland();
287287

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

296299
// Window Request
297300
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
@@ -197,15 +197,24 @@ impl Window {
197197
}
198198

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

211220
if attributes.visible {
@@ -1016,6 +1025,7 @@ impl Window {
10161025
return theme;
10171026
}
10181027

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

0 commit comments

Comments
 (0)