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