File tree 3 files changed +9
-20
lines changed
3 files changed +9
-20
lines changed Original file line number Diff line number Diff line change @@ -34,24 +34,13 @@ fn entry(
34
34
} ) ;
35
35
}
36
36
} ;
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 ( ) ,
52
42
}
53
- } ,
54
- } ;
43
+ } ) ?;
55
44
56
45
Ok ( ( key, value) )
57
46
}
Original file line number Diff line number Diff line change @@ -21,10 +21,10 @@ pub enum Error {
21
21
key : CString ,
22
22
} ,
23
23
24
- #[ error( "value in key {key} is invalid UTF-8 : {e}" ) ]
24
+ #[ error( "value in key {key} is invalid JSON : {e}" ) ]
25
25
ValueInvalid {
26
26
#[ source]
27
- e : Utf8Error ,
27
+ e : serde_jsonc :: Error ,
28
28
key : String ,
29
29
} ,
30
30
}
Original file line number Diff line number Diff line change @@ -97,7 +97,7 @@ macro_rules! waybar_module {
97
97
( $ty: ty) => {
98
98
#[ allow( non_upper_case_globals) ]
99
99
#[ 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 ;
101
101
102
102
#[ allow( clippy:: not_unsafe_ptr_arg_deref) ]
103
103
#[ unsafe ( no_mangle) ]
You can’t perform that action at this time.
0 commit comments