diff --git a/NAPS2.Lib.WinForms/WinForms/FAuthorize.cs b/NAPS2.Lib.WinForms/WinForms/FAuthorize.cs index 2109f9693..8a74623b2 100644 --- a/NAPS2.Lib.WinForms/WinForms/FAuthorize.cs +++ b/NAPS2.Lib.WinForms/WinForms/FAuthorize.cs @@ -31,6 +31,7 @@ public partial class FAuthorize : FormBase { try { + // TODO: This isn't actually working... OauthProvider.AcquireToken(_cancelTokenSource.Token); Invoke(() => { diff --git a/NAPS2.Lib/EtoForms/Ui/AuthorizeForm.cs b/NAPS2.Lib/EtoForms/Ui/AuthorizeForm.cs new file mode 100644 index 000000000..364e2f019 --- /dev/null +++ b/NAPS2.Lib/EtoForms/Ui/AuthorizeForm.cs @@ -0,0 +1,67 @@ +using System.Threading; +using Eto.Drawing; +using NAPS2.EtoForms.Layout; +using NAPS2.ImportExport.Email.Oauth; + +namespace NAPS2.EtoForms.Ui; + +public class AuthorizeForm : EtoDialogBase +{ + private readonly ErrorOutput _errorOutput; + private CancellationTokenSource? _cancelTokenSource; + + public AuthorizeForm(Naps2Config config, ErrorOutput errorOutput) : base(config) + { + _errorOutput = errorOutput; + Title = UiStrings.AuthorizeFormTitle; + Icon = new Icon(1f, Icons.key_small.ToEtoImage()); + + FormStateController.FixedHeightLayout = true; + FormStateController.RestoreFormState = false; + FormStateController.Resizable = false; + LayoutController.Content = L.Row( + C.Label(UiStrings.WaitingForAuthorization).Padding(right: 30), + C.CancelButton(this) + ); + } + + public OauthProvider? OauthProvider { get; set; } + + public bool Result { get; private set; } + + protected override void OnLoad(EventArgs e) + { + base.OnLoad(e); + + if (OauthProvider == null) throw new InvalidOperationException("OauthProvider must be specified"); + + _cancelTokenSource = new CancellationTokenSource(); + Task.Run(() => + { + try + { + OauthProvider.AcquireToken(_cancelTokenSource.Token); + Invoker.Current.SafeInvoke(() => + { + Result = true; + Close(); + }); + } + catch (OperationCanceledException) + { + } + catch (Exception ex) + { + _errorOutput.DisplayError(MiscResources.AuthError, ex); + Log.ErrorException("Error acquiring Oauth token", ex); + Invoker.Current.SafeInvoke(Close); + } + }); + } + + protected override void OnClosed(EventArgs e) + { + base.OnClosed(e); + _cancelTokenSource?.Cancel(); + } +} \ No newline at end of file diff --git a/NAPS2.Lib/EtoForms/Ui/EmailProviderForm.cs b/NAPS2.Lib/EtoForms/Ui/EmailProviderForm.cs index 4a839d457..6f11c2349 100644 --- a/NAPS2.Lib/EtoForms/Ui/EmailProviderForm.cs +++ b/NAPS2.Lib/EtoForms/Ui/EmailProviderForm.cs @@ -25,7 +25,7 @@ public class EmailProviderForm : EtoDialogBase _gmailOauthProvider = gmailOauthProvider; _outlookWebOauthProvider = outlookWebOauthProvider; Title = UiStrings.EmailProviderFormTitle; - Icon = new Icon(1f, Icons.picture_small.ToEtoImage()); + Icon = new Icon(1f, Icons.email_small.ToEtoImage()); _providerWidgets = new List(); #if NET6_0_OR_GREATER @@ -119,14 +119,14 @@ public class EmailProviderForm : EtoDialogBase private void ChooseOauth(OauthProvider provider) { - // var authForm = FormFactory.Create(); - // authForm.OauthProvider = provider; - // authForm.ShowModal(); - // if (authForm.Result) - // { - // Result = true; - // Close(); - // } + var authForm = FormFactory.Create(); + authForm.OauthProvider = provider; + authForm.ShowModal(); + if (authForm.Result) + { + Result = true; + Close(); + } } private EmailProviderWidget? GetDefaultWidget() diff --git a/NAPS2.Lib/EtoForms/Ui/EmailSettingsForm.cs b/NAPS2.Lib/EtoForms/Ui/EmailSettingsForm.cs index 89e6ffc79..22878112e 100644 --- a/NAPS2.Lib/EtoForms/Ui/EmailSettingsForm.cs +++ b/NAPS2.Lib/EtoForms/Ui/EmailSettingsForm.cs @@ -21,7 +21,7 @@ public class EmailSettingsForm : EtoDialogBase { _systemEmailClients = systemEmailClients; Title = UiStrings.EmailSettingsFormTitle; - Icon = new Icon(1f, Icons.picture_small.ToEtoImage()); + Icon = new Icon(1f, Icons.email_small.ToEtoImage()); UpdateValues(Config); UpdateProvider(Config); diff --git a/NAPS2.Lib/Icons.Designer.cs b/NAPS2.Lib/Icons.Designer.cs index 9c580186c..65ecc1636 100644 --- a/NAPS2.Lib/Icons.Designer.cs +++ b/NAPS2.Lib/Icons.Designer.cs @@ -449,6 +449,16 @@ namespace NAPS2 { } } + /// + /// Looks up a localized resource of type System.Byte[]. + /// + internal static byte[] email_small { + get { + object obj = ResourceManager.GetObject("email_small", resourceCulture); + return ((byte[])(obj)); + } + } + /// /// Looks up a localized resource of type System.Byte[]. /// @@ -549,6 +559,16 @@ namespace NAPS2 { } } + /// + /// Looks up a localized resource of type System.Byte[]. + /// + internal static byte[] key_small { + get { + object obj = ResourceManager.GetObject("key_small", resourceCulture); + return ((byte[])(obj)); + } + } + /// /// Looks up a localized resource of type System.Byte[]. /// diff --git a/NAPS2.Lib/Icons.resx b/NAPS2.Lib/Icons.resx index 3b1b2886f..89e3b1ba0 100644 --- a/NAPS2.Lib/Icons.resx +++ b/NAPS2.Lib/Icons.resx @@ -142,6 +142,12 @@ Icons\cross.png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + Icons\key-small.png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Icons\email-small.png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + Icons\email_attach.png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 diff --git a/NAPS2.Lib/Icons/email-small.png b/NAPS2.Lib/Icons/email-small.png new file mode 100644 index 000000000..832787392 Binary files /dev/null and b/NAPS2.Lib/Icons/email-small.png differ diff --git a/NAPS2.Lib/Icons/email.ico b/NAPS2.Lib/Icons/email.ico deleted file mode 100644 index 661a69836..000000000 Binary files a/NAPS2.Lib/Icons/email.ico and /dev/null differ diff --git a/NAPS2.Lib/Icons/key-small.png b/NAPS2.Lib/Icons/key-small.png new file mode 100644 index 000000000..b6ad1af40 Binary files /dev/null and b/NAPS2.Lib/Icons/key-small.png differ diff --git a/NAPS2.Lib/Icons/key.ico b/NAPS2.Lib/Icons/key.ico deleted file mode 100644 index 45e478fb7..000000000 Binary files a/NAPS2.Lib/Icons/key.ico and /dev/null differ diff --git a/NAPS2.Lib/Lang/Resources/UiStrings.Designer.cs b/NAPS2.Lib/Lang/Resources/UiStrings.Designer.cs index 02efb8489..d3b15a45b 100644 --- a/NAPS2.Lib/Lang/Resources/UiStrings.Designer.cs +++ b/NAPS2.Lib/Lang/Resources/UiStrings.Designer.cs @@ -203,6 +203,15 @@ namespace NAPS2.Lang.Resources { } } + /// + /// Looks up a localized string similar to Authorize. + /// + internal static string AuthorizeFormTitle { + get { + return ResourceManager.GetString("AuthorizeFormTitle", resourceCulture); + } + } + /// /// Looks up a localized string similar to Author:. /// @@ -1535,6 +1544,15 @@ namespace NAPS2.Lang.Resources { } } + /// + /// Looks up a localized string similar to Waiting for authorization.... + /// + internal static string WaitingForAuthorization { + get { + return ResourceManager.GetString("WaitingForAuthorization", resourceCulture); + } + } + /// /// Looks up a localized string similar to WIA Driver. /// diff --git a/NAPS2.Lib/Lang/Resources/UiStrings.resx b/NAPS2.Lib/Lang/Resources/UiStrings.resx index 5b4f1d8f1..512c61c54 100644 --- a/NAPS2.Lib/Lang/Resources/UiStrings.resx +++ b/NAPS2.Lib/Lang/Resources/UiStrings.resx @@ -630,4 +630,10 @@ Choose Email Provider + + Authorize + + + Waiting for authorization... + \ No newline at end of file