@@ -11,17 +11,22 @@ public static class ConfirmationDialog
1111
1212 public static Task < bool ? > Confirm ( string message , string trueLabel , string falseLabel )
1313 {
14+ ArgumentException . ThrowIfNullOrEmpty ( message ) ;
15+ ArgumentException . ThrowIfNullOrEmpty ( trueLabel ) ;
16+ ArgumentException . ThrowIfNullOrEmpty ( falseLabel ) ;
17+ ArgumentOutOfRangeException . ThrowIfEqual ( trueLabel , falseLabel ) ;
18+
1419 if ( OperatingSystem . IsWindows ( ) )
1520 {
16- return ConfirmWindows ( ) ;
21+ return ConfirmWindows ( message , trueLabel , falseLabel ) ;
1722 }
1823 else if ( OperatingSystem . IsMacOS ( ) )
1924 {
20- return ConfirmMacOS ( ) ;
25+ return ConfirmMacOS ( message , trueLabel , falseLabel ) ;
2126 }
2227 else if ( OperatingSystem . IsLinux ( ) )
2328 {
24- return ConfirmLinux ( ) ;
29+ return ConfirmLinux ( message , trueLabel , falseLabel ) ;
2530 }
2631 else
2732 {
@@ -30,19 +35,36 @@ public static class ConfirmationDialog
3035 }
3136
3237 [ SupportedOSPlatform ( "windows" ) ]
33- private unsafe static Task < bool ? > ConfirmWindows ( )
38+ private unsafe static Task < bool ? > ConfirmWindows ( string message , string trueLabel , string falseLabel )
3439 {
3540 return Task . FromResult < bool ? > ( null ) ;
3641 }
3742
3843 [ SupportedOSPlatform ( "macos" ) ]
39- private static Task < bool ? > ConfirmMacOS ( )
44+ private static async Task < bool ? > ConfirmMacOS ( string message , string trueLabel , string falseLabel )
4045 {
41- return Task . FromResult < bool ? > ( null ) ;
46+ string escapedMessage = ProcessExecutor . EscapeString ( message ) ;
47+ string escapedTrueLabel = ProcessExecutor . EscapeString ( trueLabel ) ;
48+ string escapedFalseLabel = ProcessExecutor . EscapeString ( falseLabel ) ;
49+ string ? result = await ProcessExecutor . TryRun ( "osascript" ,
50+ "-e" , $ "display dialog \" { escapedMessage } \" buttons {{\" { escapedTrueLabel } \" , \" { escapedFalseLabel } \" }} default button \" { escapedTrueLabel } \" ",
51+ "-e" , "button returned of result" ) ;
52+ if ( result == trueLabel )
53+ {
54+ return true ;
55+ }
56+ else if ( result == falseLabel )
57+ {
58+ return false ;
59+ }
60+ else
61+ {
62+ return null ; // An error occurred
63+ }
4264 }
4365
4466 [ SupportedOSPlatform ( "linux" ) ]
45- private static Task < bool ? > ConfirmLinux ( )
67+ private static Task < bool ? > ConfirmLinux ( string message , string trueLabel , string falseLabel )
4668 {
4769 if ( Gtk . Global . IsSupported )
4870 {
0 commit comments