1- use anyhow:: { Result , anyhow } ;
1+ use anyhow:: { Context , Result } ;
22use std:: sync:: { Arc , atomic:: AtomicBool } ;
33
44use iwdrs:: session:: Session ;
@@ -49,11 +49,10 @@ impl AccessPoint {
4949 pub async fn new ( session : Arc < Session > ) -> Result < Self > {
5050 let iwd_access_point = session
5151 . access_points ( )
52- . await
53- . unwrap ( )
52+ . await ?
5453 . pop ( )
55- . ok_or ( anyhow ! ( "no ap found" ) ) ?;
56- let iwd_access_point_diagnostic = session. access_points_diagnostics ( ) . await . unwrap ( ) . pop ( ) ;
54+ . context ( "no ap found" ) ?;
55+ let iwd_access_point_diagnostic = session. access_points_diagnostics ( ) . await ? . pop ( ) ;
5756
5857 let has_started = iwd_access_point. has_started ( ) . await ?;
5958 let name = iwd_access_point. name ( ) . await ?;
@@ -217,13 +216,13 @@ impl AccessPoint {
217216 }
218217
219218 pub async fn refresh ( & mut self ) -> Result < ( ) > {
220- let iwd_access_point = self . session . access_points ( ) . await . unwrap ( ) . pop ( ) . unwrap ( ) ;
221- let iwd_access_point_diagnostic = self
219+ let iwd_access_point = self
222220 . session
223- . access_points_diagnostics ( )
224- . await
225- . unwrap ( )
226- . pop ( ) ;
221+ . access_points ( )
222+ . await ?
223+ . pop ( )
224+ . context ( "No AP found" ) ?;
225+ let iwd_access_point_diagnostic = self . session . access_points_diagnostics ( ) . await ?. pop ( ) ;
227226
228227 self . has_started = iwd_access_point. has_started ( ) . await ?;
229228 self . name = iwd_access_point. name ( ) . await ?;
@@ -247,7 +246,12 @@ impl AccessPoint {
247246 }
248247
249248 pub async fn scan ( & self , sender : UnboundedSender < Event > ) -> Result < ( ) > {
250- let iwd_access_point = self . session . access_points ( ) . await . unwrap ( ) . pop ( ) . unwrap ( ) ;
249+ let iwd_access_point = self
250+ . session
251+ . access_points ( )
252+ . await ?
253+ . pop ( )
254+ . context ( "No AP found" ) ?;
251255 match iwd_access_point. scan ( ) . await {
252256 Ok ( ( ) ) => Notification :: send (
253257 "Start Scanning" . to_string ( ) ,
@@ -261,7 +265,12 @@ impl AccessPoint {
261265 }
262266
263267 pub async fn start ( & self , sender : UnboundedSender < Event > ) -> Result < ( ) > {
264- let iwd_access_point = self . session . access_points ( ) . await . unwrap ( ) . pop ( ) . unwrap ( ) ;
268+ let iwd_access_point = self
269+ . session
270+ . access_points ( )
271+ . await ?
272+ . pop ( )
273+ . context ( "No AP found" ) ?;
265274 match iwd_access_point
266275 . start ( self . ssid . value ( ) , self . psk . value ( ) )
267276 . await
@@ -280,7 +289,12 @@ impl AccessPoint {
280289 }
281290
282291 pub async fn stop ( & self , sender : UnboundedSender < Event > ) -> Result < ( ) > {
283- let iwd_access_point = self . session . access_points ( ) . await . unwrap ( ) . pop ( ) . unwrap ( ) ;
292+ let iwd_access_point = self
293+ . session
294+ . access_points ( )
295+ . await ?
296+ . pop ( )
297+ . context ( "No AP found" ) ?;
284298 match iwd_access_point. stop ( ) . await {
285299 Ok ( ( ) ) => {
286300 Notification :: send ( "AP Stopped" . to_string ( ) , NotificationLevel :: Info , & sender) ?
0 commit comments