1
- use ashpd:: desktop:: account:: UserInformation ;
2
- use ashpd:: WindowIdentifier ;
3
1
use glib:: clone;
4
2
use gtk:: prelude:: * ;
5
3
use gtk:: { glib, Application , ApplicationWindow , Button } ;
@@ -35,21 +33,7 @@ fn build_ui(app: &Application) {
35
33
#[ weak]
36
34
button,
37
35
async move {
38
- // Get native of button for window identifier
39
- let native = button. native( ) . expect( "Need to be able to get native." ) ;
40
- // Get window identifier so that the dialog will be modal to the main window
41
- let identifier = WindowIdentifier :: from_native( & native) . await ;
42
- let request = UserInformation :: request( )
43
- . reason( "App would like to access user information." )
44
- . identifier( identifier)
45
- . send( )
46
- . await ;
47
-
48
- if let Ok ( response) = request. and_then( |r| r. response( ) ) {
49
- println!( "User name: {}" , response. name( ) ) ;
50
- } else {
51
- println!( "Could not access user information." )
52
- }
36
+ fetch_user_information( button) . await
53
37
}
54
38
) ) ;
55
39
} ) ;
@@ -65,3 +49,30 @@ fn build_ui(app: &Application) {
65
49
// Present window
66
50
window. present ( ) ;
67
51
}
52
+
53
+ #[ cfg( target_os = "linux" ) ]
54
+ async fn fetch_user_information ( button : Button ) {
55
+ use ashpd:: desktop:: account:: UserInformation ;
56
+ use ashpd:: WindowIdentifier ;
57
+
58
+ // Get native of button for window identifier
59
+ let native = button. native ( ) . expect ( "Need to be able to get native." ) ;
60
+ // Get window identifier so that the dialog will be modal to the main window
61
+ let identifier = WindowIdentifier :: from_native ( & native) . await ;
62
+ let request = UserInformation :: request ( )
63
+ . reason ( "App would like to access user information." )
64
+ . identifier ( identifier)
65
+ . send ( )
66
+ . await ;
67
+
68
+ if let Ok ( response) = request. and_then ( |r| r. response ( ) ) {
69
+ println ! ( "User name: {}" , response. name( ) ) ;
70
+ } else {
71
+ println ! ( "Could not access user information." )
72
+ }
73
+ }
74
+
75
+ #[ cfg( not( target_os = "linux" ) ) ]
76
+ async fn fetch_user_information ( _button : Button ) {
77
+ println ! ( "fetching user information not available outside target_os = \" linux\" " ) ;
78
+ }
0 commit comments