@@ -37,38 +37,14 @@ int main(string[] argv) {
37
37
}
38
38
39
39
var battery = AstalBattery . get_default();
40
- print(" %s\n " , to_json (battery));
40
+ print(" %s\n " , Json . gobject_to_data (battery, null ));
41
41
42
42
if (monitor) {
43
- battery. notify. connect((prop) = > {
44
- if (prop. get_name() == " percentage"
45
- || prop. get_name() == " state"
46
- || prop. get_name() == " icon-name"
47
- || prop. get_name() == " time-to-full"
48
- || prop. get_name() == " time-to-empty"
49
- ) {
50
- print(" %s\n " , to_json(battery));
51
- }
43
+ battery. notify. connect(() = > {
44
+ print(" %s\n " , Json . gobject_to_data(battery, null ));
52
45
});
53
46
new GLib .MainLoop (null , false ). run();
54
47
}
55
48
56
49
return 0 ;
57
50
}
58
-
59
- private string to_json(AstalBattery . Device device) {
60
- string s = " unknown" ;
61
- if (device. state == AstalBattery . State . CHARGING )
62
- s = " charging" ;
63
- if (device. state == AstalBattery . State . DISCHARGING )
64
- s = " discharging" ;
65
- if (device. state == AstalBattery . State . FULLY_CHARGED )
66
- s = " fully_charged" ;
67
-
68
- var p = device. percentage;
69
- var i = device. icon_name;
70
- var r = device. state == AstalBattery . State . CHARGING
71
- ? device. time_to_full : device. time_to_empty;
72
-
73
- return " { \" percentage\" : %f , \" state\" : \"%s\" , \" icon_name\" : \"%s\" , \" time_remaining\" : %f }" . printf(p, s, i, r);
74
- }
0 commit comments