1
- use std:: str:: FromStr ;
2
1
use std:: time:: Duration ;
3
2
4
3
use crossbeam_channel:: Sender ;
@@ -72,7 +71,7 @@ impl ConfigBlock for Rofication {
72
71
shared_config : SharedConfig ,
73
72
_tx_update_request : Sender < Task > ,
74
73
) -> Result < Self > {
75
- let text = TextWidget :: new ( id, 0 , shared_config. clone ( ) )
74
+ let text = TextWidget :: new ( id, 0 , shared_config)
76
75
. with_text ( "?" )
77
76
. with_icon ( "bell" ) ?
78
77
. with_state ( State :: Good ) ;
@@ -98,12 +97,10 @@ impl Block for Rofication {
98
97
self . text . set_texts ( self . format . render ( & values) ?) ;
99
98
if status. crit > 0 {
100
99
self . text . set_state ( State :: Critical )
100
+ } else if status. num > 0 {
101
+ self . text . set_state ( State :: Warning )
101
102
} else {
102
- if status. num > 0 {
103
- self . text . set_state ( State :: Warning )
104
- } else {
105
- self . text . set_state ( State :: Good )
106
- }
103
+ self . text . set_state ( State :: Good )
107
104
}
108
105
self . text . set_icon ( "bell" ) ?;
109
106
}
@@ -148,27 +145,15 @@ fn rofication_status(socket_path: &str) -> Result<RotificationStatus> {
148
145
} ;
149
146
150
147
// Request count
151
- match stream. write ( b"num\n " ) {
152
- Err ( _) => {
153
- return Err ( BlockError (
154
- "rofication" . to_string ( ) ,
155
- "Failed to write to socket" . to_string ( ) ,
156
- ) )
157
- }
158
- Ok ( _) => { }
159
- } ;
148
+ stream
149
+ . write ( b"num\n " )
150
+ . block_error ( "rofication" , "Failed to write to socket" ) ?;
160
151
161
152
// Response must be two comma separated integers: regular and critical
162
153
let mut buffer = String :: new ( ) ;
163
- match stream. read_to_string ( & mut buffer) {
164
- Err ( _) => {
165
- return Err ( BlockError (
166
- "rofication" . to_string ( ) ,
167
- "Failed to read from socket" . to_string ( ) ,
168
- ) )
169
- }
170
- Ok ( _) => { }
171
- } ;
154
+ stream
155
+ . read_to_string ( & mut buffer)
156
+ . block_error ( "rofication" , "Failed to read from socket" ) ?;
172
157
173
158
let values = buffer. split ( ',' ) . collect :: < Vec < & str > > ( ) ;
174
159
if values. len ( ) != 2 {
@@ -178,24 +163,12 @@ fn rofication_status(socket_path: &str) -> Result<RotificationStatus> {
178
163
) ) ;
179
164
}
180
165
181
- let num = match values[ 0 ] . parse :: < u64 > ( ) {
182
- Ok ( num) => num,
183
- Err ( _) => {
184
- return Err ( BlockError (
185
- "rofication" . to_string ( ) ,
186
- "Failed to parse num" . to_string ( ) ,
187
- ) )
188
- }
189
- } ;
190
- let crit = match values[ 1 ] . parse :: < u64 > ( ) {
191
- Ok ( crit) => crit,
192
- Err ( _) => {
193
- return Err ( BlockError (
194
- "rofication" . to_string ( ) ,
195
- "Failed to parse crit" . to_string ( ) ,
196
- ) )
197
- }
198
- } ;
166
+ let num = values[ 0 ]
167
+ . parse :: < u64 > ( )
168
+ . block_error ( "rofication" , "Failed to parse num" ) ?;
169
+ let crit = values[ 1 ]
170
+ . parse :: < u64 > ( )
171
+ . block_error ( "rofication" , "Failed to parse crit" ) ?;
199
172
200
173
Ok ( RotificationStatus { num, crit } )
201
174
}
0 commit comments