1- use  ashpd:: desktop:: account:: UserInformation ; 
2- use  ashpd:: WindowIdentifier ; 
31use  glib:: clone; 
42use  gtk:: prelude:: * ; 
53use  gtk:: { glib,  Application ,  ApplicationWindow ,  Button } ; 
@@ -35,21 +33,7 @@ fn build_ui(app: &Application) {
3533            #[ weak] 
3634            button, 
3735            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 
5337            } 
5438        ) ) ; 
5539    } ) ; 
@@ -65,3 +49,30 @@ fn build_ui(app: &Application) {
6549    // Present window 
6650    window. present ( ) ; 
6751} 
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