mirror of
https://github.com/cyanfish/naps2.git
synced 2024-08-16 18:50:45 +03:00
Migrate AuthorizeForm to Eto
This commit is contained in:
parent
3c419ea58f
commit
9a3915547a
@ -31,6 +31,7 @@ public partial class FAuthorize : FormBase
|
||||
{
|
||||
try
|
||||
{
|
||||
// TODO: This isn't actually working...
|
||||
OauthProvider.AcquireToken(_cancelTokenSource.Token);
|
||||
Invoke(() =>
|
||||
{
|
||||
|
67
NAPS2.Lib/EtoForms/Ui/AuthorizeForm.cs
Normal file
67
NAPS2.Lib/EtoForms/Ui/AuthorizeForm.cs
Normal file
@ -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();
|
||||
}
|
||||
}
|
@ -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<EmailProviderWidget>();
|
||||
#if NET6_0_OR_GREATER
|
||||
@ -119,14 +119,14 @@ public class EmailProviderForm : EtoDialogBase
|
||||
|
||||
private void ChooseOauth(OauthProvider provider)
|
||||
{
|
||||
// var authForm = FormFactory.Create<AuthorizeForm>();
|
||||
// authForm.OauthProvider = provider;
|
||||
// authForm.ShowModal();
|
||||
// if (authForm.Result)
|
||||
// {
|
||||
// Result = true;
|
||||
// Close();
|
||||
// }
|
||||
var authForm = FormFactory.Create<AuthorizeForm>();
|
||||
authForm.OauthProvider = provider;
|
||||
authForm.ShowModal();
|
||||
if (authForm.Result)
|
||||
{
|
||||
Result = true;
|
||||
Close();
|
||||
}
|
||||
}
|
||||
|
||||
private EmailProviderWidget? GetDefaultWidget()
|
||||
|
@ -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);
|
||||
|
20
NAPS2.Lib/Icons.Designer.cs
generated
20
NAPS2.Lib/Icons.Designer.cs
generated
@ -449,6 +449,16 @@ namespace NAPS2 {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized resource of type System.Byte[].
|
||||
/// </summary>
|
||||
internal static byte[] email_small {
|
||||
get {
|
||||
object obj = ResourceManager.GetObject("email_small", resourceCulture);
|
||||
return ((byte[])(obj));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized resource of type System.Byte[].
|
||||
/// </summary>
|
||||
@ -549,6 +559,16 @@ namespace NAPS2 {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized resource of type System.Byte[].
|
||||
/// </summary>
|
||||
internal static byte[] key_small {
|
||||
get {
|
||||
object obj = ResourceManager.GetObject("key_small", resourceCulture);
|
||||
return ((byte[])(obj));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized resource of type System.Byte[].
|
||||
/// </summary>
|
||||
|
@ -142,6 +142,12 @@
|
||||
<data name="cross" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>Icons\cross.png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</data>
|
||||
<data name="key_small" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>Icons\key-small.png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</data>
|
||||
<data name="email_small" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>Icons\email-small.png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</data>
|
||||
<data name="email_attach" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>Icons\email_attach.png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</data>
|
||||
|
BIN
NAPS2.Lib/Icons/email-small.png
Normal file
BIN
NAPS2.Lib/Icons/email-small.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 530 B |
Binary file not shown.
Before Width: | Height: | Size: 1.1 KiB |
BIN
NAPS2.Lib/Icons/key-small.png
Normal file
BIN
NAPS2.Lib/Icons/key-small.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 664 B |
Binary file not shown.
Before Width: | Height: | Size: 18 KiB |
18
NAPS2.Lib/Lang/Resources/UiStrings.Designer.cs
generated
18
NAPS2.Lib/Lang/Resources/UiStrings.Designer.cs
generated
@ -203,6 +203,15 @@ namespace NAPS2.Lang.Resources {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Authorize.
|
||||
/// </summary>
|
||||
internal static string AuthorizeFormTitle {
|
||||
get {
|
||||
return ResourceManager.GetString("AuthorizeFormTitle", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Author:.
|
||||
/// </summary>
|
||||
@ -1535,6 +1544,15 @@ namespace NAPS2.Lang.Resources {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Waiting for authorization....
|
||||
/// </summary>
|
||||
internal static string WaitingForAuthorization {
|
||||
get {
|
||||
return ResourceManager.GetString("WaitingForAuthorization", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to WIA Driver.
|
||||
/// </summary>
|
||||
|
@ -630,4 +630,10 @@
|
||||
<data name="EmailProviderFormTitle" xml:space="preserve">
|
||||
<value>Choose Email Provider</value>
|
||||
</data>
|
||||
<data name="AuthorizeFormTitle" xml:space="preserve">
|
||||
<value>Authorize</value>
|
||||
</data>
|
||||
<data name="WaitingForAuthorization" xml:space="preserve">
|
||||
<value>Waiting for authorization...</value>
|
||||
</data>
|
||||
</root>
|
Loading…
Reference in New Issue
Block a user