Skip to content

Commit 6d567d9

Browse files
committed
Update to waybar ABI version 2.
Dependent on Alexays/Waybar#3969 being merged, obviously.
1 parent cce6035 commit 6d567d9

File tree

3 files changed

+9
-20
lines changed

3 files changed

+9
-20
lines changed

waybar-cffi/src/config.rs

+6-17
Original file line numberDiff line numberDiff line change
@@ -34,24 +34,13 @@ fn entry(
3434
});
3535
}
3636
};
37-
38-
// Annoyingly, waybar provides the value as a bare string if it's JSON,
39-
// but _also_ provides a bare string if it was a literal string. All we
40-
// can do for now is to try to parse it as JSON, then fall back on
41-
// treating it as a string if that fails.
42-
//
43-
// On the bright side, deserialisation into the configuration type
44-
// should then fail.
45-
let value = CStr::from_ptr((*entry).value);
46-
let value = match serde_jsonc::from_slice(value.to_bytes()) {
47-
Ok(value) => value,
48-
Err(_) => match value.to_str() {
49-
Ok(value) => serde_jsonc::Value::String(value.to_string()),
50-
Err(e) => {
51-
return Err(Error::ValueInvalid { e, key });
37+
let value =
38+
serde_jsonc::from_slice(CStr::from_ptr((*entry).value).to_bytes()).map_err(|e| {
39+
Error::ValueInvalid {
40+
e,
41+
key: key.clone(),
5242
}
53-
},
54-
};
43+
})?;
5544

5645
Ok((key, value))
5746
}

waybar-cffi/src/error.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ pub enum Error {
2121
key: CString,
2222
},
2323

24-
#[error("value in key {key} is invalid UTF-8: {e}")]
24+
#[error("value in key {key} is invalid JSON: {e}")]
2525
ValueInvalid {
2626
#[source]
27-
e: Utf8Error,
27+
e: serde_jsonc::Error,
2828
key: String,
2929
},
3030
}

waybar-cffi/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ macro_rules! waybar_module {
9797
($ty:ty) => {
9898
#[allow(non_upper_case_globals)]
9999
#[unsafe(no_mangle)]
100-
pub static wbcffi_version: $crate::sys::libc::size_t = 1;
100+
pub static wbcffi_version: $crate::sys::libc::size_t = 2;
101101

102102
#[allow(clippy::not_unsafe_ptr_arg_deref)]
103103
#[unsafe(no_mangle)]

0 commit comments

Comments
 (0)