Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Theme update #138

Merged
merged 18 commits into from
Aug 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ animated-image = ["image", "dep:async-fs", "tokio?/io-util", "tokio?/fs"]
apply = "0.3.0"
derive_setters = "0.1.5"
lazy_static = "1.4.0"
palette = "0.7"
palette = "0.7.3"
tokio = { version = "1.24.2", optional = true }
sctk = { package = "smithay-client-toolkit", git = "https://github.com/smithay/client-toolkit", optional = true, rev = "c9940f4"}
slotmap = "1.0.6"
Expand Down
99 changes: 42 additions & 57 deletions cosmic-config/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use iced_futures::futures::SinkExt;
#[cfg(feature = "subscription")]
use iced_futures::futures::channel::mpsc;
#[cfg(feature = "subscription")]
use iced_futures::subscription;
use iced_futures::{futures::channel::mpsc, subscription};
use notify::{
event::{EventKind, ModifyKind},
RecommendedWatcher, Watcher,
Expand Down Expand Up @@ -319,91 +318,77 @@ pub fn config_subscription<
config_id: Cow<'static, str>,
config_version: u64,
) -> iced_futures::Subscription<(I, Result<T, (Vec<crate::Error>, T)>)> {
subscription::unfold(
id,
ConfigState::Init(config_id, config_version),
move |state| start_listening_loop(id, state),
)
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);

loop {
state = start_listening(state, &mut output, id).await;
}
}
})
}

#[cfg(feature = "subscription")]
async fn start_listening<
I: Copy,
T: 'static + Send + Sync + PartialEq + Clone + CosmicConfigEntry,
>(
id: I,
state: ConfigState<T>,
) -> (
Option<(I, Result<T, (Vec<crate::Error>, T)>)>,
ConfigState<T>,
) {
output: &mut mpsc::Sender<(I, Result<T, (Vec<crate::Error>, T)>)>,
id: I,
) -> ConfigState<T> {
use iced_futures::futures::{future::pending, StreamExt};

match state {
ConfigState::Init(config_id, version) => {
let (tx, rx) = mpsc::channel(100);
let config = match Config::new(&config_id, version) {
Ok(c) => c,
Err(_) => return (None, ConfigState::Failed),
Err(_) => return ConfigState::Failed,
};
let watcher = match config.watch(move |_helper, _keys| {
let mut tx = tx.clone();
let _ = tx.try_send(());
}) {
Ok(w) => w,
Err(_) => return (None, ConfigState::Failed),
Err(_) => return ConfigState::Failed,
};
let msg = T::get_entry(&config);
_ = output.send((id, msg)).await;

match T::get_entry(&config) {
Ok(t) => (
Some((id, Ok(t.clone()))),
ConfigState::Waiting(t, watcher, rx, config),
),
Err((errors, t)) => (
Some((id, Err((errors, t.clone())))),
ConfigState::Waiting(t, watcher, rx, config),
),
Ok(t) => {
_ = output.send((id, Ok(t.clone()))).await;
ConfigState::Waiting(t, watcher, rx, config)
}
Err((errors, t)) => {
_ = output.send((id, Err((errors, t.clone())))).await;
ConfigState::Waiting(t, watcher, rx, config)
}
}
}
ConfigState::Waiting(old, watcher, mut rx, config) => match rx.next().await {
ConfigState::Waiting(mut old, watcher, mut rx, config) => match rx.next().await {
Some(_) => match T::get_entry(&config) {
Ok(t) => (
Ok(t) => {
if t != old {
Some((id, Ok(t.clone())))
} else {
None
},
ConfigState::Waiting(t, watcher, rx, config),
),
Err((errors, t)) => (
old = t;
_ = output.send((id, Ok(old.clone()))).await;
}
ConfigState::Waiting(old, watcher, rx, config)
}
Err((errors, t)) => {
if t != old {
Some((id, Err((errors, t.clone()))))
} else {
None
},
ConfigState::Waiting(t, watcher, rx, config),
),
old = t;
_ = output.send((id, Err((errors, old.clone())))).await;
}
ConfigState::Waiting(old, watcher, rx, config)
}
},

None => (None, ConfigState::Failed),
None => ConfigState::Failed,
},
ConfigState::Failed => pending().await,
}
}

#[cfg(feature = "subscription")]
async fn start_listening_loop<
I: Copy,
T: 'static + Send + Sync + PartialEq + Clone + CosmicConfigEntry,
>(
id: I,
mut state: ConfigState<T>,
) -> ((I, Result<T, (Vec<crate::Error>, T)>), ConfigState<T>) {
loop {
let (update, new_state) = start_listening(id, state).await;
state = new_state;
if let Some(update) = update {
return (update, state);
}
}
}
12 changes: 3 additions & 9 deletions cosmic-theme/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,15 @@ rustdoc-args = ["--cfg", "docsrs"]
[features]
default = []
no-default = []
contrast-derivation = ["float-cmp"]
theme-from-image = ["kmeans_colors", "contrast-derivation", "float-cmp", "image"]
hex-color = ["hex"]
theme-from-image = ["kmeans_colors", "image"]

[dependencies]
palette = {version = "0.7", features = ["serializing"] }
anyhow = "1.0"
hex = {version = "0.4.3", optional = true}
palette = {version = "0.7.3", features = ["serializing"] }
almost = "0.2"
kmeans_colors = { version = "0.5", features = ["palette_color"], default-features = false, optional = true }
image = {version = "0.24.1", optional = true }
float-cmp = { version = "0.9.0", optional = true }
serde = { version = "1.0.129", features = ["derive"] }
ron = "0.8"
lazy_static = "1.4.0"
csscolorparser = {version = "0.6.2", features = ["serde"]}
directories = { git = "https://github.com/edfloreshz/directories-rs", version = "4.0.1" }
cosmic-config = { path = "../cosmic-config/", default-features = false, features = ["subscription"] }

170 changes: 0 additions & 170 deletions cosmic-theme/src/color_picker/exact.rs

This file was deleted.

Loading