File tree Expand file tree Collapse file tree 4 files changed +25
-24
lines changed Expand file tree Collapse file tree 4 files changed +25
-24
lines changed Original file line number Diff line number Diff line change @@ -164,12 +164,17 @@ impl Clients {
164
164
}
165
165
166
166
#[ cfg( feature = "upower" ) ]
167
- pub fn upower ( & mut self ) -> Arc < zbus:: fdo:: PropertiesProxy < ' static > > {
168
- self . upower
169
- . get_or_insert_with ( || {
170
- crate :: await_sync ( async { upower:: create_display_proxy ( ) . await } )
171
- } )
172
- . clone ( )
167
+ pub fn upower ( & mut self ) -> ClientResult < zbus:: fdo:: PropertiesProxy < ' static > > {
168
+ let client = match & self . upower {
169
+ Some ( client) => client. clone ( ) ,
170
+ None => {
171
+ let client = await_sync ( async { upower:: create_display_proxy ( ) . await } ) ?;
172
+ self . upower . replace ( client. clone ( ) ) ;
173
+ client
174
+ }
175
+ } ;
176
+
177
+ Ok ( client)
173
178
}
174
179
175
180
#[ cfg( feature = "volume" ) ]
Original file line number Diff line number Diff line change 1
- use crate :: register_client;
1
+ use crate :: clients:: ClientResult ;
2
+ use crate :: register_fallible_client;
2
3
use std:: sync:: Arc ;
3
4
use upower_dbus:: UPowerProxy ;
4
5
use zbus:: fdo:: PropertiesProxy ;
5
6
6
- pub async fn create_display_proxy ( ) -> Arc < PropertiesProxy < ' static > > {
7
- let dbus = Box :: pin ( zbus:: Connection :: system ( ) )
8
- . await
9
- . expect ( "failed to create connection to system bus" ) ;
7
+ pub async fn create_display_proxy ( ) -> ClientResult < PropertiesProxy < ' static > > {
8
+ let dbus = Box :: pin ( zbus:: Connection :: system ( ) ) . await ?;
10
9
11
- let device_proxy = UPowerProxy :: new ( & dbus)
12
- . await
13
- . expect ( "failed to create upower proxy" ) ;
10
+ let device_proxy = UPowerProxy :: new ( & dbus) . await ?;
14
11
15
- let display_device = device_proxy
16
- . get_display_device ( )
17
- . await
18
- . unwrap_or_else ( |_| panic ! ( "failed to get display device for {device_proxy:?}" ) ) ;
12
+ let display_device = device_proxy. get_display_device ( ) . await ?;
19
13
20
14
let path = display_device. path ( ) . to_owned ( ) ;
21
15
@@ -26,10 +20,9 @@ pub async fn create_display_proxy() -> Arc<PropertiesProxy<'static>> {
26
20
. expect ( "failed to set proxy path" )
27
21
. cache_properties ( zbus:: CacheProperties :: No )
28
22
. build ( )
29
- . await
30
- . expect ( "failed to build proxy" ) ;
23
+ . await ?;
31
24
32
- Arc :: new ( proxy)
25
+ Ok ( Arc :: new ( proxy) )
33
26
}
34
27
35
- register_client ! ( PropertiesProxy <' static >, upower) ;
28
+ register_fallible_client ! ( PropertiesProxy <' static >, upower) ;
Original file line number Diff line number Diff line change @@ -78,7 +78,10 @@ fn run_with_args() {
78
78
#[ cfg( feature = "schema" ) ]
79
79
if args. print_schema {
80
80
let schema = schemars:: schema_for!( Config ) ;
81
- println ! ( "{}" , serde_json:: to_string_pretty( & schema) . expect( "to be serializable" ) ) ;
81
+ println ! (
82
+ "{}" ,
83
+ serde_json:: to_string_pretty( & schema) . expect( "to be serializable" )
84
+ ) ;
82
85
return ;
83
86
}
84
87
Original file line number Diff line number Diff line change @@ -73,7 +73,7 @@ impl Module<gtk::Button> for UpowerModule {
73
73
) -> Result < ( ) > {
74
74
let tx = context. tx . clone ( ) ;
75
75
76
- let display_proxy = context. client :: < PropertiesProxy > ( ) ;
76
+ let display_proxy = context. try_client :: < PropertiesProxy > ( ) ? ;
77
77
78
78
spawn ( async move {
79
79
let mut prop_changed_stream = display_proxy. receive_properties_changed ( ) . await ?;
You can’t perform that action at this time.
0 commit comments