libcosmic updates
This commit is contained in:
parent
9c62f19e4b
commit
0491c4baaa
91 changed files with 3550 additions and 2300 deletions
|
|
@ -3,7 +3,10 @@ use std::ops::Deref;
|
|||
use crate::{CosmicConfigEntry, Update};
|
||||
use cosmic_settings_daemon::{Changed, ConfigProxy, CosmicSettingsDaemonProxy};
|
||||
use futures_util::SinkExt;
|
||||
use iced_futures::futures::{self, future::pending, StreamExt};
|
||||
use iced_futures::{
|
||||
futures::{self, future::pending, Stream, StreamExt},
|
||||
stream, Subscription,
|
||||
};
|
||||
|
||||
pub async fn settings_daemon_proxy() -> zbus::Result<CosmicSettingsDaemonProxy<'static>> {
|
||||
let conn = zbus::Connection::session().await?;
|
||||
|
|
@ -58,13 +61,20 @@ pub fn watcher_subscription<T: CosmicConfigEntry + Send + Sync + Default + 'stat
|
|||
config_id: &'static str,
|
||||
is_state: bool,
|
||||
) -> iced_futures::Subscription<Update<T>> {
|
||||
let id = std::any::TypeId::of::<T>();
|
||||
Subscription::run_with_id(id, watcher_stream(settings_daemon, config_id, is_state))
|
||||
}
|
||||
|
||||
fn watcher_stream<T: CosmicConfigEntry + Send + Sync + Default + 'static + Clone>(
|
||||
settings_daemon: CosmicSettingsDaemonProxy<'static>,
|
||||
config_id: &'static str,
|
||||
is_state: bool,
|
||||
) -> impl Stream<Item = Update<T>> {
|
||||
enum Change {
|
||||
Changes(Changed),
|
||||
OwnerChanged(bool),
|
||||
}
|
||||
|
||||
let id = std::any::TypeId::of::<T>();
|
||||
iced_futures::subscription::channel((is_state, config_id, id), 5, move |mut tx| async move {
|
||||
stream::channel(5, move |mut tx| async move {
|
||||
let version = T::VERSION;
|
||||
|
||||
let Ok(cosmic_config) = (if is_state {
|
||||
|
|
|
|||
|
|
@ -384,6 +384,7 @@ where
|
|||
) -> (Vec<crate::Error>, Vec<&'static str>);
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Update<T> {
|
||||
pub errors: Vec<crate::Error>,
|
||||
pub keys: Vec<&'static str>,
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
use iced_futures::futures::SinkExt;
|
||||
use iced_futures::{futures::channel::mpsc, subscription};
|
||||
use iced_futures::futures::{SinkExt, Stream};
|
||||
use iced_futures::{futures::channel::mpsc, stream};
|
||||
use notify::RecommendedWatcher;
|
||||
use std::{borrow::Cow, hash::Hash};
|
||||
|
||||
|
|
@ -24,17 +24,7 @@ pub fn config_subscription<
|
|||
config_id: Cow<'static, str>,
|
||||
config_version: u64,
|
||||
) -> iced_futures::Subscription<crate::Update<T>> {
|
||||
subscription::channel(id, 100, move |mut output| {
|
||||
let config_id = config_id.clone();
|
||||
async move {
|
||||
let config_id = config_id.clone();
|
||||
let mut state = ConfigState::Init(config_id, config_version, false);
|
||||
|
||||
loop {
|
||||
state = start_listening(state, &mut output, id).await;
|
||||
}
|
||||
}
|
||||
})
|
||||
iced_futures::Subscription::run_with_id(id, watcher_stream(config_id, config_version, false))
|
||||
}
|
||||
|
||||
pub fn config_state_subscription<
|
||||
|
|
@ -45,26 +35,30 @@ pub fn config_state_subscription<
|
|||
config_id: Cow<'static, str>,
|
||||
config_version: u64,
|
||||
) -> iced_futures::Subscription<crate::Update<T>> {
|
||||
subscription::channel(id, 100, move |mut output| {
|
||||
iced_futures::Subscription::run_with_id(id, watcher_stream(config_id, config_version, true))
|
||||
}
|
||||
|
||||
fn watcher_stream<T: 'static + Send + Sync + PartialEq + Clone + CosmicConfigEntry>(
|
||||
config_id: Cow<'static, str>,
|
||||
config_version: u64,
|
||||
is_state: bool,
|
||||
) -> impl Stream<Item = crate::Update<T>> {
|
||||
stream::channel(100, move |mut output| {
|
||||
let config_id = config_id.clone();
|
||||
async move {
|
||||
let config_id = config_id.clone();
|
||||
let mut state = ConfigState::Init(config_id, config_version, true);
|
||||
let mut state = ConfigState::Init(config_id, config_version, is_state);
|
||||
|
||||
loop {
|
||||
state = start_listening(state, &mut output, id).await;
|
||||
state = start_listening::<T>(state, &mut output).await;
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
async fn start_listening<
|
||||
I: Copy,
|
||||
T: 'static + Send + Sync + PartialEq + Clone + CosmicConfigEntry,
|
||||
>(
|
||||
async fn start_listening<T: 'static + Send + Sync + PartialEq + Clone + CosmicConfigEntry>(
|
||||
state: ConfigState<T>,
|
||||
output: &mut mpsc::Sender<crate::Update<T>>,
|
||||
id: I,
|
||||
) -> ConfigState<T> {
|
||||
use iced_futures::futures::{future::pending, StreamExt};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue