Viewing is open to everyone. Downloading and starring need a GitHub sign-in. Sign in with GitHub

CKeySafeActionPrompt.cs

v0.1.0-build.85 Latest Commit ede38f5

Size
1.4 KB
Lines
31
Language
csharp
SHA-256
eac9c823bf65…
View on GitHub

Sign in with GitHub to download. Each download is recorded with your GitHub username.

1using System;
2using System.Threading.Tasks;
3using System.Windows;
4
5namespace OpenCKey.Wpf
6{
7 /// <summary>
8 /// The SDK's WPF confirmation for a cross-device Safe Action
9 /// (spec/CKey-Safe-Actions.md, "What a reader must do", step 6).
10 /// </summary>
11 /// <remarks>
12 /// This is the only WPF way to approve a <see cref="CKeySafeActionRequest"/>: it names the
13 /// verified issuer and the issuer's account of who is asking, and the
14 /// registered handler runs only when the person chooses Yes. No, closing the
15 /// dialog and Escape decline. Call on the UI thread.
16 /// </remarks>
17 public static class CKeySafeActionPrompt
18 {
19 /// <summary>Shows the confirmation. Returns true when the person approved and the handler ran.</summary>
20 public static Task<bool> ShowAsync(Window? owner, CKeySafeActionRequest request)
21 {
22 if (request == null) throw new ArgumentNullException(nameof(request));
23 if (request.IsDecided) return Task.FromResult(false);
24 string text = request.Message + "\n\nContinue?";
25 MessageBoxResult answer = owner != null
26 ? MessageBox.Show(owner, text, request.Title, MessageBoxButton.YesNo, MessageBoxImage.Warning, MessageBoxResult.No)
27 : MessageBox.Show(text, request.Title, MessageBoxButton.YesNo, MessageBoxImage.Warning, MessageBoxResult.No);
28 return request.Decide(answer == MessageBoxResult.Yes);
29 }
30 }
31}