11import Adw from "gi://Adw" ;
22import Gtk from "gi://Gtk" ;
3+ import Gio from "gi://Gio" ;
4+
5+ Gio . _promisify ( Adw . MessageDialog . prototype , "choose" , "choose_finish" ) ;
36
47const button_confirmation = workbench . builder . get_object ( "button_confirmation" ) ;
58const button_error = workbench . builder . get_object ( "button_error" ) ;
69const button_advanced = workbench . builder . get_object ( "button_advanced" ) ;
710const window = workbench . window ;
811
9- function createConfirmationDialog ( ) {
12+ async function createConfirmationDialog ( ) {
1013 const dialog = new Adw . MessageDialog ( {
1114 heading : "Replace File?" ,
1215 body : "A file named `example.png` already exists. Do you want to replace it?" ,
@@ -21,14 +24,11 @@ function createConfirmationDialog() {
2124 // Use DESTRUCTIVE appearance to draw attention to the potentially damaging consequences of this action
2225 dialog . set_response_appearance ( "replace" , Adw . ResponseAppearance . DESTRUCTIVE ) ;
2326
24- dialog . connect ( "response" , ( _self , response ) => {
25- console . log ( `Selected "${ response } " response.` ) ;
26- } ) ;
27-
28- dialog . present ( ) ;
27+ const response = await dialog . choose ( null ) ;
28+ console . log ( `Selected "${ response } " response.` ) ;
2929}
3030
31- function createErrorDialog ( ) {
31+ async function createErrorDialog ( ) {
3232 const dialog = new Adw . MessageDialog ( {
3333 heading : "Critical Error" ,
3434 body : "You did something you should not have" ,
@@ -39,15 +39,12 @@ function createErrorDialog() {
3939
4040 dialog . add_response ( "okay" , "Okay" ) ;
4141
42- dialog . connect ( "response" , ( _self , response ) => {
43- console . log ( `Selected "${ response } " response.` ) ;
44- } ) ;
45-
46- dialog . present ( ) ;
42+ const response = await dialog . choose ( null ) ;
43+ console . log ( `Selected "${ response } " response.` ) ;
4744}
4845
4946//Creates a message dialog with an extra child
50- function createAdvancedDialog ( ) {
47+ async function createAdvancedDialog ( ) {
5148 const dialog = new Adw . MessageDialog ( {
5249 heading : "Login" ,
5350 body : "A valid password is needed to continue" ,
@@ -68,19 +65,22 @@ function createAdvancedDialog() {
6865
6966 dialog . set_extra_child ( entry ) ;
7067
71- dialog . connect ( "response" , ( dialog , response ) => {
72- if ( dialog . get_response_label ( response ) === "Login" ) {
73- console . log (
74- `Selected "${ response } " response with password "${ entry . get_text ( ) } "` ,
75- ) ;
76- } else {
77- console . log ( `Selected "${ response } " response.` ) ;
78- }
79- } ) ;
80-
81- dialog . present ( ) ;
68+ const response = await dialog . choose ( null ) ;
69+ if ( response === "login" ) {
70+ console . log (
71+ `Selected "${ response } " response with password "${ entry . get_text ( ) } "` ,
72+ ) ;
73+ } else {
74+ console . log ( `Selected "${ response } " response.` ) ;
75+ }
8276}
8377
84- button_confirmation . connect ( "clicked" , createConfirmationDialog ) ;
85- button_error . connect ( "clicked" , createErrorDialog ) ;
86- button_advanced . connect ( "clicked" , createAdvancedDialog ) ;
78+ button_confirmation . connect ( "clicked" , ( ) => {
79+ createConfirmationDialog ( ) . catch ( logError ) ;
80+ } ) ;
81+ button_error . connect ( "clicked" , ( ) => {
82+ createErrorDialog ( ) . catch ( logError ) ;
83+ } ) ;
84+ button_advanced . connect ( "clicked" , ( ) => {
85+ createAdvancedDialog ( ) . catch ( logError ) ;
86+ } ) ;
0 commit comments