update iced

This commit is contained in:
Ashley Wulber 2024-10-30 22:51:08 -04:00 committed by Ashley Wulber
parent 11faa567f3
commit 5b5cd77e7c
45 changed files with 2360 additions and 1537 deletions

View file

@ -1,7 +1,10 @@
// Copyright 2023 System76 <info@system76.com>
// SPDX-License-Identifier: GPL-3.0-only
use cosmic::{iced, widget::icon};
use cosmic::{
iced::{self, Subscription},
widget::icon,
};
use futures::{FutureExt, StreamExt};
use zbus::zvariant::{self, OwnedValue};
@ -82,7 +85,7 @@ impl StatusNotifierItem {
// TODO: Only fetch changed part of layout, if that's any faster
pub fn layout_subscription(&self) -> iced::Subscription<Result<Layout, String>> {
let menu_proxy = self.menu_proxy.clone();
iced::subscription::run_with_id(
Subscription::run_with_id(
format!("status-notifier-item-{}", &self.name),
async move {
let initial = futures::stream::once(get_layout(menu_proxy.clone()));

View file

@ -3,8 +3,8 @@
// TODO: Both this and server proxy could emit same events, have way to generate stream from either?
use cosmic::iced;
use futures::StreamExt;
use cosmic::iced::{self, Subscription};
use futures::{stream, StreamExt};
use crate::subscriptions::status_notifier_item::StatusNotifierItem;
@ -26,24 +26,23 @@ enum State {
}
pub fn subscription() -> iced::Subscription<Event> {
iced::subscription::unfold(
Subscription::run_with_id(
"status-notifier-watcher",
State::NotConnected,
|state| async move {
stream::unfold(State::NotConnected, |state| async move {
match state {
State::NotConnected => match connect().await {
Ok((connection, stream)) => {
(Event::Connected(connection), State::Connected(stream))
Some((Event::Connected(connection), State::Connected(stream)))
}
Err(err) => (Event::Error(err.to_string()), State::Failed),
Err(err) => Some((Event::Error(err.to_string()), State::Failed)),
},
State::Connected(mut stream) => match stream.next().await {
Some(event) => (event, State::Connected(stream)),
None => iced::futures::future::pending().await,
Some(event) => Some((event, State::Connected(stream))),
None => None,
},
State::Failed => iced::futures::future::pending().await,
State::Failed => None,
}
},
}),
)
}