Skip to content

Commit

Permalink
Upgrade zbus to 4
Browse files Browse the repository at this point in the history
Closes: #23
  • Loading branch information
iovxw committed Feb 26, 2024
1 parent c4c1d1e commit d0aadc5
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 21 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ license = "Unlicense"
thiserror = "1"
futures = { version = "0.3", default-features = false }
tokio = { version = "1", features = ["rt", "macros"] }
zbus = { version = "3", features = ["tokio"], default-features = false }
zbus = { version = "4", features = ["tokio"], default-features = false }
serde = { version = "1", features = ["derive"] }
80 changes: 62 additions & 18 deletions src/menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::collections::HashMap;
use std::fmt;
use std::sync::{Arc, Mutex};

use zbus::zvariant::{OwnedValue, Value};
use zbus::zvariant::{OwnedValue, Str, Value};

// pub struct Properties {
// /// Tells if the menus are in a normal state or they believe that they
Expand Down Expand Up @@ -415,7 +415,7 @@ macro_rules! if_not_default_then_insert {
{
$map.insert(
$property_name.to_string(),
Value::from($to_refarg($item.$property.clone())).into(),
OwnedValue::from($to_refarg($item.$property.clone())),
);
}
};
Expand All @@ -439,21 +439,57 @@ impl<T> RawMenuItem<T> {
filter,
r#type,
"type",
(|r: ItemType| r.to_string())
(|r: ItemType| -> Str { r.to_string().into() })
);
if_not_default_then_insert!(
properties,
self,
default,
filter,
label,
(|r: String| -> Str { r.into() })
);
if_not_default_then_insert!(properties, self, default, filter, label);
if_not_default_then_insert!(properties, self, default, filter, enabled);
if_not_default_then_insert!(properties, self, default, filter, visible);
if_not_default_then_insert!(properties, self, default, filter, icon_name);
if_not_default_then_insert!(properties, self, default, filter, icon_data);
if_not_default_then_insert!(properties, self, default, filter, shortcut);
if_not_default_then_insert!(
properties,
self,
default,
filter,
icon_name,
(|r: String| -> Str { r.into() })
);
if_not_default_then_insert!(
properties,
self,
default,
filter,
icon_data,
(|r: Vec<u8>| -> OwnedValue {
Value::from(r)
.try_into()
.expect("unreachable: Vec<u8> to OwnedValue")
})
);
if_not_default_then_insert!(
properties,
self,
default,
filter,
shortcut,
(|r: Vec<Vec<String>>| -> OwnedValue {
Value::from(r)
.try_into()
.expect("unreachable: Vec<Vec<String>> to OwnedValue")
})
);
if_not_default_then_insert!(
properties,
self,
default,
filter,
toggle_type,
(|r: ToggleType| r.to_string())
(|r: ToggleType| -> Str { r.to_string().into() })
);
if_not_default_then_insert!(
properties,
Expand All @@ -469,7 +505,7 @@ impl<T> RawMenuItem<T> {
default,
filter,
disposition,
(|r: Disposition| r.to_string())
(|r: Disposition| -> Str { r.to_string().into() })
);

properties
Expand All @@ -483,28 +519,34 @@ impl<T> RawMenuItem<T> {
if other.r#type == default.r#type {
removed_props.push("type".into());
} else {
updated_props.insert("type".into(), Value::from(other.r#type.to_string()).into());
updated_props.insert(
"type".into(),
<OwnedValue as From<Str>>::from(other.r#type.to_string().into()),
);
}
}
if self.label != other.label {
if other.label == default.label {
removed_props.push("label".into());
} else {
updated_props.insert("label".into(), Value::from(other.label.clone()).into());
updated_props.insert(
"label".into(),
<OwnedValue as From<Str>>::from(other.label.clone().into()),
);
}
}
if self.enabled != other.enabled {
if other.enabled == default.enabled {
removed_props.push("enabled".into());
} else {
updated_props.insert("enabled".into(), Value::from(other.enabled).into());
updated_props.insert("enabled".into(), OwnedValue::from(other.enabled));
}
}
if self.visible != other.visible {
if other.visible == default.visible {
removed_props.push("visible".into());
} else {
updated_props.insert("visible".into(), Value::from(other.visible).into());
updated_props.insert("visible".into(), OwnedValue::from(other.visible));
}
}
if self.icon_name != other.icon_name {
Expand All @@ -513,7 +555,7 @@ impl<T> RawMenuItem<T> {
} else {
updated_props.insert(
"icon-name".into(),
Value::from(other.icon_name.clone()).into(),
<OwnedValue as From<Str>>::from(other.icon_name.clone().into()),
);
}
}
Expand All @@ -523,7 +565,8 @@ impl<T> RawMenuItem<T> {
} else {
updated_props.insert(
"icon-data".into(),
Value::from(other.icon_data.clone()).into(),
<OwnedValue as TryFrom<Value>>::try_from(other.icon_data.clone().into())
.expect("unreachable: Vec<u8> to OwnedValue"),
);
}
}
Expand All @@ -533,7 +576,8 @@ impl<T> RawMenuItem<T> {
} else {
updated_props.insert(
"shortcut".into(),
Value::from(other.shortcut.clone()).into(),
<OwnedValue as TryFrom<Value>>::try_from(other.shortcut.clone().into())
.expect("unreachable: Vec<Vec<u8>> to OwnedValue"),
);
}
}
Expand All @@ -543,7 +587,7 @@ impl<T> RawMenuItem<T> {
} else {
updated_props.insert(
"toggle-type".into(),
Value::from(other.toggle_type.to_string()).into(),
<OwnedValue as From<Str>>::from(other.toggle_type.to_string().into()),
);
}
}
Expand All @@ -563,7 +607,7 @@ impl<T> RawMenuItem<T> {
} else {
updated_props.insert(
"disposition".into(),
Value::from(other.disposition.to_string()).into(),
<OwnedValue as From<Str>>::from(other.disposition.to_string().into()),
);
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ pub async fn run_async<T: Tray + Send + 'static>(
let result = service.id2index(id)
.ok_or_else(|| zbus::fdo::Error::InvalidArgs("id not found".to_string()))
.map(|index| service.menu_cache[index].0.to_dbus_map(&vec![name]))
.map(|value| Value::from(value).to_owned());
.map(|value| OwnedValue::from(value));
let _ = r.send(result);
}
DbusMenuMessage::Event(id, event_id, data, timestamp, r) => {
Expand Down Expand Up @@ -478,7 +478,8 @@ impl<T: Tray + Send + 'static> Service<T> {
properties: item.1,
children: item.2,
}
.into(),
.try_into()
.expect("unreachable: LayoutItem should not contain any fd"),
);
}
} else {
Expand Down

0 comments on commit d0aadc5

Please sign in to comment.