feat: libcosmic iced 0.14 rebase

This commit is contained in:
Ashley Wulber 2026-03-17 16:56:55 -04:00 committed by GitHub
parent 0020132e63
commit cf7fc32adf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
47 changed files with 2731 additions and 1869 deletions

View file

@ -1,6 +1,8 @@
// Copyright 2024 System76 <info@system76.com>
// SPDX-License-Identifier: MPL-2.0
use crate::Wrapper;
use super::Event;
use cosmic_dbus_networkmanager::nm::NetworkManager;
use futures::{SinkExt, StreamExt};
@ -18,13 +20,13 @@ pub fn active_conns_subscription<I: 'static + Hash + Copy + Send + Sync + Debug>
id: I,
conn: Connection,
) -> iced_futures::Subscription<Event> {
Subscription::run_with_id(
id,
Subscription::run_with(Wrapper { id, conn: conn }, |Wrapper { id: _id, conn }| {
let conn = conn.clone();
stream::channel(50, move |output| async move {
watch(conn, output).await;
futures::future::pending().await
}),
)
})
})
}
pub async fn watch(conn: zbus::Connection, mut output: futures::channel::mpsc::Sender<Event>) {

View file

@ -6,6 +6,7 @@ pub use cosmic_dbus_networkmanager::interface::enums::{
ActiveConnectionState, DeviceState, DeviceType,
};
use core::hash;
use cosmic_dbus_networkmanager::nm::NetworkManager;
use futures::{SinkExt, StreamExt};
use iced_futures::{self, Subscription, stream};
@ -166,12 +167,35 @@ pub fn subscription<I: 'static + Hash + Copy + Send + Sync + Debug>(
has_popup: bool,
conn: Connection,
) -> iced_futures::Subscription<Event> {
Subscription::run_with_id(
(id, has_popup),
stream::channel(50, move |output| async move {
watch(conn, has_popup, output).await;
futures::future::pending().await
}),
struct Wrapper<I> {
id: I,
has_popup: bool,
conn: Connection,
}
impl<I: Hash> Hash for Wrapper<I> {
fn hash<H: hash::Hasher>(&self, state: &mut H) {
self.id.hash(state);
self.has_popup.hash(state);
}
}
Subscription::run_with(
Wrapper {
id,
has_popup,
conn,
},
|Wrapper {
id,
has_popup,
conn,
}| {
let conn = conn.clone();
let has_popup = *has_popup;
stream::channel(50, move |output| async move {
watch(conn, has_popup, output).await;
futures::future::pending().await
})
},
)
}

View file

@ -9,7 +9,7 @@ pub mod hw_address;
pub mod nm_secret_agent;
pub mod wireless_enabled;
use std::{collections::HashMap, fmt::Debug, sync::Arc, time::Duration};
use std::{collections::HashMap, fmt::Debug, hash::Hash, sync::Arc, time::Duration};
use available_wifi::NetworkType;
pub use cosmic_dbus_networkmanager as dbus;
@ -41,6 +41,17 @@ use self::{
pub type SSID = Arc<str>;
pub type UUID = Arc<str>;
pub(crate) struct Wrapper<I> {
id: I,
conn: zbus::Connection,
}
impl<I: Hash> Hash for Wrapper<I> {
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
self.id.hash(state);
}
}
#[derive(thiserror::Error, Debug)]
pub enum Error {
#[error("failed to list bluetooth devices with rfkill")]
@ -121,13 +132,25 @@ pub fn subscription<I: Copy + Debug + std::hash::Hash + 'static>(
id: I,
conn: zbus::Connection,
) -> iced_futures::Subscription<Event> {
Subscription::run_with_id(
id,
stream::channel(50, |output| async move {
watch(conn, output).await;
futures::future::pending().await
}),
)
struct Wrapper<I> {
id: I,
conn: zbus::Connection,
}
impl<I: Hash> Hash for Wrapper<I> {
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
self.id.hash(state);
}
}
Subscription::run_with(Wrapper { id, conn }, |Wrapper { id, conn }| {
let conn = conn.clone();
stream::channel(
50,
|output: futures::channel::mpsc::Sender<Event>| async move {
watch(conn, output).await;
futures::future::pending().await
},
)
})
}
pub async fn watch(conn: zbus::Connection, mut output: futures::channel::mpsc::Sender<Event>) {

View file

@ -135,11 +135,15 @@ pub fn secret_agent_stream(
identifier: impl AsRef<str>,
rx: tokio::sync::mpsc::Receiver<Request>,
) -> impl Stream<Item = Event> {
iced_futures::stream::channel(4, move |mut msg_tx| async move {
if let Err(e) = secret_agent_stream_impl(identifier.as_ref(), msg_tx.clone(), rx).await {
let _ = msg_tx.send(Event::Failed(e)).await;
}
})
iced_futures::stream::channel(
4,
move |mut msg_tx: futures::channel::mpsc::Sender<Event>| async move {
if let Err(e) = secret_agent_stream_impl(identifier.as_ref(), msg_tx.clone(), rx).await
{
let _ = msg_tx.send(Event::Failed(e)).await;
}
},
)
}
async fn secret_agent_stream_impl(

View file

@ -1,6 +1,8 @@
// Copyright 2024 System76 <info@system76.com>
// SPDX-License-Identifier: MPL-2.0
use crate::Wrapper;
use super::Event;
use cosmic_dbus_networkmanager::nm::NetworkManager;
use futures::{SinkExt, StreamExt};
@ -18,13 +20,13 @@ pub fn wireless_enabled_subscription<I: 'static + Hash + Copy + Send + Sync + De
id: I,
conn: Connection,
) -> iced_futures::Subscription<Event> {
Subscription::run_with_id(
id,
Subscription::run_with(Wrapper { id, conn: conn }, |Wrapper { id: _id, conn }| {
let conn = conn.clone();
stream::channel(50, move |output| async move {
watch(conn, output).await;
futures::future::pending().await
}),
)
})
})
}
pub async fn watch(conn: zbus::Connection, mut output: futures::channel::mpsc::Sender<Event>) {