set config field take optional Config
This commit is contained in:
parent
0caff62a18
commit
6c933d2d55
4 changed files with 22 additions and 5 deletions
|
|
@ -71,7 +71,7 @@ serde = { version = "1.0.180", optional = true }
|
|||
slotmap = "1.0.6"
|
||||
thiserror = "1.0.44"
|
||||
tokio = { version = "1.24.2", optional = true }
|
||||
tracing = "0.1"
|
||||
tracing.workspace = true
|
||||
unicode-segmentation = "1.6"
|
||||
url = "2.4.0"
|
||||
zbus = {version = "3.14.1", default-features = false, optional = true}
|
||||
|
|
@ -152,6 +152,7 @@ exclude = ["examples/design-demo", "iced"]
|
|||
|
||||
[workspace.dependencies]
|
||||
dirs = "5.0.1"
|
||||
tracing = "0.1"
|
||||
|
||||
|
||||
[patch."https://github.com/pop-os/libcosmic"]
|
||||
|
|
|
|||
|
|
@ -9,4 +9,5 @@ proc-macro = true
|
|||
|
||||
[dependencies]
|
||||
syn = "1.0"
|
||||
quote = "1.0"
|
||||
quote = "1.0"
|
||||
tracing.workspace = true
|
||||
|
|
@ -89,11 +89,25 @@ fn impl_cosmic_config_entry_macro(ast: &syn::DeriveInput) -> TokenStream {
|
|||
Some(quote! {
|
||||
#[doc = #doc]
|
||||
///
|
||||
/// Returns `Ok(true)` when the field's value has changed and was written to disk
|
||||
pub fn #setter_name(&mut self, config: &cosmic_config::Config, value: #field_type) -> Result<bool, cosmic_config::Error> {
|
||||
/// Returns `Ok(true)` when the field's value has changed and was written to disk.
|
||||
/// Log error in case of faillure
|
||||
pub fn #setter_name(&mut self, config: &Option<cosmic_config::Config>, value: #field_type) -> Result<bool, cosmic_config::Error> {
|
||||
if self.#field_name != value {
|
||||
self.#field_name = value;
|
||||
cosmic_config::ConfigSet::set(config, stringify!(#field_name), &self.#field_name)?;
|
||||
match config {
|
||||
Some(config) => {
|
||||
if let Err(err) = cosmic_config::ConfigSet::set(config, stringify!(#field_name), &self.#field_name) {
|
||||
tracing::error!("failed to save config {:?}: {}", stringify!(#field_name), err);
|
||||
return Err(err);
|
||||
}
|
||||
}
|
||||
None => {
|
||||
tracing::error!(
|
||||
"failed to save config {}: no config handler",
|
||||
stringify!(#field_name),
|
||||
);
|
||||
}
|
||||
}
|
||||
Ok(true)
|
||||
} else {
|
||||
Ok(false)
|
||||
|
|
|
|||
|
|
@ -27,3 +27,4 @@ csscolorparser = {version = "0.6.2", features = ["serde"]}
|
|||
cosmic-config = { path = "../cosmic-config/", default-features = false, features = ["subscription", "macro"] }
|
||||
dirs.workspace = true
|
||||
thiserror = "1.0.5"
|
||||
tracing.workspace = true
|
||||
Loading…
Add table
Add a link
Reference in a new issue