diff --git a/Wino.Authentication/GmailAuthenticator.cs b/Wino.Authentication/GmailAuthenticator.cs index 54445e3f..901df797 100644 --- a/Wino.Authentication/GmailAuthenticator.cs +++ b/Wino.Authentication/GmailAuthenticator.cs @@ -11,8 +11,6 @@ namespace Wino.Authentication { public class GmailAuthenticator : BaseAuthenticator, IGmailAuthenticator { - private const string FileDataStoreFolder = "WinoGmailStore"; - public GmailAuthenticator(IAuthenticatorConfig authConfig) : base(authConfig) { } @@ -47,7 +45,7 @@ namespace Wino.Authentication return GoogleWebAuthorizationBroker.AuthorizeAsync(new ClientSecrets() { ClientId = ClientId - }, AuthenticatorConfig.GmailScope, account.Id.ToString(), CancellationToken.None, new FileDataStore(FileDataStoreFolder)); + }, AuthenticatorConfig.GmailScope, account.Id.ToString(), CancellationToken.None, new FileDataStore(AuthenticatorConfig.GmailTokenStoreIdentifier)); } } } diff --git a/Wino.Calendar.ViewModels/CalendarViewModelContainerSetup.cs b/Wino.Calendar.ViewModels/CalendarViewModelContainerSetup.cs new file mode 100644 index 00000000..4fb5a466 --- /dev/null +++ b/Wino.Calendar.ViewModels/CalendarViewModelContainerSetup.cs @@ -0,0 +1,13 @@ +using Microsoft.Extensions.DependencyInjection; +using Wino.Core; + +namespace Wino.Calendar.ViewModels +{ + public static class CalendarViewModelContainerSetup + { + public static void RegisterCalendarViewModelServices(this IServiceCollection services) + { + services.RegisterCoreServices(); + } + } +} diff --git a/Wino.Calendar.ViewModels/Wino.Calendar.ViewModels.csproj b/Wino.Calendar.ViewModels/Wino.Calendar.ViewModels.csproj index 613938db..53d3ba10 100644 --- a/Wino.Calendar.ViewModels/Wino.Calendar.ViewModels.csproj +++ b/Wino.Calendar.ViewModels/Wino.Calendar.ViewModels.csproj @@ -17,6 +17,7 @@ + diff --git a/Wino.Calendar.sln b/Wino.Calendar.sln index eac1571b..3b782a8a 100644 --- a/Wino.Calendar.sln +++ b/Wino.Calendar.sln @@ -23,6 +23,10 @@ Project("{C7167F0D-BC9F-4E6E-AFE1-012C56B48DB5}") = "Wino.Calendar.Packaging", " EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Wino.Calendar.ViewModels", "Wino.Calendar.ViewModels\Wino.Calendar.ViewModels.csproj", "{CF850F8C-5042-4376-9CBA-C8F2BB554083}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wino.Services", "Wino.Services\Wino.Services.csproj", "{BBA49030-7277-48CF-B2FE-3D01CB6B6C81}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wino.Authentication", "Wino.Authentication\Wino.Authentication.csproj", "{16A979C2-F308-464F-9B2A-0AF8ED5EDB43}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -257,6 +261,46 @@ Global {CF850F8C-5042-4376-9CBA-C8F2BB554083}.Release|x64.Build.0 = Release|x64 {CF850F8C-5042-4376-9CBA-C8F2BB554083}.Release|x86.ActiveCfg = Release|x86 {CF850F8C-5042-4376-9CBA-C8F2BB554083}.Release|x86.Build.0 = Release|x86 + {BBA49030-7277-48CF-B2FE-3D01CB6B6C81}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {BBA49030-7277-48CF-B2FE-3D01CB6B6C81}.Debug|Any CPU.Build.0 = Debug|Any CPU + {BBA49030-7277-48CF-B2FE-3D01CB6B6C81}.Debug|ARM.ActiveCfg = Debug|Any CPU + {BBA49030-7277-48CF-B2FE-3D01CB6B6C81}.Debug|ARM.Build.0 = Debug|Any CPU + {BBA49030-7277-48CF-B2FE-3D01CB6B6C81}.Debug|ARM64.ActiveCfg = Debug|Any CPU + {BBA49030-7277-48CF-B2FE-3D01CB6B6C81}.Debug|ARM64.Build.0 = Debug|Any CPU + {BBA49030-7277-48CF-B2FE-3D01CB6B6C81}.Debug|x64.ActiveCfg = Debug|Any CPU + {BBA49030-7277-48CF-B2FE-3D01CB6B6C81}.Debug|x64.Build.0 = Debug|Any CPU + {BBA49030-7277-48CF-B2FE-3D01CB6B6C81}.Debug|x86.ActiveCfg = Debug|Any CPU + {BBA49030-7277-48CF-B2FE-3D01CB6B6C81}.Debug|x86.Build.0 = Debug|Any CPU + {BBA49030-7277-48CF-B2FE-3D01CB6B6C81}.Release|Any CPU.ActiveCfg = Release|Any CPU + {BBA49030-7277-48CF-B2FE-3D01CB6B6C81}.Release|Any CPU.Build.0 = Release|Any CPU + {BBA49030-7277-48CF-B2FE-3D01CB6B6C81}.Release|ARM.ActiveCfg = Release|Any CPU + {BBA49030-7277-48CF-B2FE-3D01CB6B6C81}.Release|ARM.Build.0 = Release|Any CPU + {BBA49030-7277-48CF-B2FE-3D01CB6B6C81}.Release|ARM64.ActiveCfg = Release|Any CPU + {BBA49030-7277-48CF-B2FE-3D01CB6B6C81}.Release|ARM64.Build.0 = Release|Any CPU + {BBA49030-7277-48CF-B2FE-3D01CB6B6C81}.Release|x64.ActiveCfg = Release|Any CPU + {BBA49030-7277-48CF-B2FE-3D01CB6B6C81}.Release|x64.Build.0 = Release|Any CPU + {BBA49030-7277-48CF-B2FE-3D01CB6B6C81}.Release|x86.ActiveCfg = Release|Any CPU + {BBA49030-7277-48CF-B2FE-3D01CB6B6C81}.Release|x86.Build.0 = Release|Any CPU + {16A979C2-F308-464F-9B2A-0AF8ED5EDB43}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {16A979C2-F308-464F-9B2A-0AF8ED5EDB43}.Debug|Any CPU.Build.0 = Debug|Any CPU + {16A979C2-F308-464F-9B2A-0AF8ED5EDB43}.Debug|ARM.ActiveCfg = Debug|Any CPU + {16A979C2-F308-464F-9B2A-0AF8ED5EDB43}.Debug|ARM.Build.0 = Debug|Any CPU + {16A979C2-F308-464F-9B2A-0AF8ED5EDB43}.Debug|ARM64.ActiveCfg = Debug|Any CPU + {16A979C2-F308-464F-9B2A-0AF8ED5EDB43}.Debug|ARM64.Build.0 = Debug|Any CPU + {16A979C2-F308-464F-9B2A-0AF8ED5EDB43}.Debug|x64.ActiveCfg = Debug|x64 + {16A979C2-F308-464F-9B2A-0AF8ED5EDB43}.Debug|x64.Build.0 = Debug|x64 + {16A979C2-F308-464F-9B2A-0AF8ED5EDB43}.Debug|x86.ActiveCfg = Debug|x86 + {16A979C2-F308-464F-9B2A-0AF8ED5EDB43}.Debug|x86.Build.0 = Debug|x86 + {16A979C2-F308-464F-9B2A-0AF8ED5EDB43}.Release|Any CPU.ActiveCfg = Release|Any CPU + {16A979C2-F308-464F-9B2A-0AF8ED5EDB43}.Release|Any CPU.Build.0 = Release|Any CPU + {16A979C2-F308-464F-9B2A-0AF8ED5EDB43}.Release|ARM.ActiveCfg = Release|Any CPU + {16A979C2-F308-464F-9B2A-0AF8ED5EDB43}.Release|ARM.Build.0 = Release|Any CPU + {16A979C2-F308-464F-9B2A-0AF8ED5EDB43}.Release|ARM64.ActiveCfg = Release|Any CPU + {16A979C2-F308-464F-9B2A-0AF8ED5EDB43}.Release|ARM64.Build.0 = Release|Any CPU + {16A979C2-F308-464F-9B2A-0AF8ED5EDB43}.Release|x64.ActiveCfg = Release|x64 + {16A979C2-F308-464F-9B2A-0AF8ED5EDB43}.Release|x64.Build.0 = Release|x64 + {16A979C2-F308-464F-9B2A-0AF8ED5EDB43}.Release|x86.ActiveCfg = Release|x86 + {16A979C2-F308-464F-9B2A-0AF8ED5EDB43}.Release|x86.Build.0 = Release|x86 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Wino.Calendar/App.xaml.cs b/Wino.Calendar/App.xaml.cs index 418c0846..510fe951 100644 --- a/Wino.Calendar/App.xaml.cs +++ b/Wino.Calendar/App.xaml.cs @@ -12,11 +12,11 @@ using Wino.Activation; using Wino.Calendar.Activation; using Wino.Calendar.Services; using Wino.Calendar.ViewModels; -using Wino.Core; using Wino.Core.Domain.Interfaces; using Wino.Core.UWP; using Wino.Messaging.Client.Connection; using Wino.Messaging.Server; +using Wino.Services; namespace Wino.Calendar { @@ -38,7 +38,8 @@ namespace Wino.Calendar { var services = new ServiceCollection(); - services.RegisterCoreServices(); + services.RegisterSharedServices(); + services.RegisterCalendarViewModelServices(); services.RegisterCoreUWPServices(); services.RegisterCoreViewModels(); diff --git a/Wino.Calendar/Services/CalendarAuthenticatorConfig.cs b/Wino.Calendar/Services/CalendarAuthenticatorConfig.cs index 42e9da4b..f139ff59 100644 --- a/Wino.Calendar/Services/CalendarAuthenticatorConfig.cs +++ b/Wino.Calendar/Services/CalendarAuthenticatorConfig.cs @@ -21,10 +21,13 @@ namespace Wino.Calendar.Services public string[] GmailScope => new string[] { - "https://mail.google.com/", "https://www.googleapis.com/auth/calendar", "https://www.googleapis.com/auth/calendar.events", - "https://www.googleapis.com/auth/calendar.settings.readonly" + "https://www.googleapis.com/auth/calendar.settings.readonly", + "https://www.googleapis.com/auth/userinfo.profile", + "https://www.googleapis.com/auth/userinfo.email" }; + + public string GmailTokenStoreIdentifier => "WinoCalendarGmailTokenStore"; } } diff --git a/Wino.Calendar/Wino.Calendar.csproj b/Wino.Calendar/Wino.Calendar.csproj index 165faa7f..24c3a752 100644 --- a/Wino.Calendar/Wino.Calendar.csproj +++ b/Wino.Calendar/Wino.Calendar.csproj @@ -326,14 +326,14 @@ {53723ae8-7e7e-4d54-adab-0a6033255cc8} Wino.Core.ViewModels - - {e6b1632a-8901-41e8-9ddf-6793c7698b0b} - Wino.Core - {0c307d7e-256f-448c-8265-5622a812fbcc} Wino.Messaging + + {bba49030-7277-48cf-b2fe-3d01cb6b6c81} + Wino.Services + 14.0 diff --git a/Wino.Core.Domain/Interfaces/IAuthenticatorConfig.cs b/Wino.Core.Domain/Interfaces/IAuthenticatorConfig.cs index 435e4489..1f154727 100644 --- a/Wino.Core.Domain/Interfaces/IAuthenticatorConfig.cs +++ b/Wino.Core.Domain/Interfaces/IAuthenticatorConfig.cs @@ -6,5 +6,6 @@ string[] OutlookScope { get; } string GmailAuthenticatorClientId { get; } string[] GmailScope { get; } + string GmailTokenStoreIdentifier { get; } } } diff --git a/Wino.Core.UWP/Dialogs/AccountCreationDialog.xaml b/Wino.Core.UWP/Dialogs/AccountCreationDialog.xaml index 42e8cc3d..e5449e20 100644 --- a/Wino.Core.UWP/Dialogs/AccountCreationDialog.xaml +++ b/Wino.Core.UWP/Dialogs/AccountCreationDialog.xaml @@ -80,11 +80,11 @@ VerticalAlignment="Bottom" Click="CancelClicked" Content="{x:Bind domain:Translator.Buttons_Cancel}" /> - + - + - + - + diff --git a/Wino.Core.UWP/Dialogs/AccountCreationDialog.xaml.cs b/Wino.Core.UWP/Dialogs/AccountCreationDialog.xaml.cs index f8847e9e..49de0bb4 100644 --- a/Wino.Core.UWP/Dialogs/AccountCreationDialog.xaml.cs +++ b/Wino.Core.UWP/Dialogs/AccountCreationDialog.xaml.cs @@ -2,6 +2,8 @@ using System.Threading.Tasks; using CommunityToolkit.Mvvm.Messaging; using Microsoft.Extensions.DependencyInjection; +using Windows.UI.Xaml; +using Wino.Core.Domain.Enums; using Wino.Core.Domain.Interfaces; using Wino.Core.UWP; using Wino.Messaging.UI; @@ -18,6 +20,11 @@ namespace Wino.Dialogs WeakReferenceMessenger.Default.Register(this); } + public override void OnStateChanged(AccountCreationDialogState state) + { + var tt = VisualStateManager.GoToState(this, state.ToString(), true); + } + public async void Receive(CopyAuthURLRequested message) { copyClipboardURL = message.AuthURL; diff --git a/Wino.Core.UWP/Dialogs/BaseAccountCreationDialog.cs b/Wino.Core.UWP/Dialogs/BaseAccountCreationDialog.cs index bb56381c..f27abb2a 100644 --- a/Wino.Core.UWP/Dialogs/BaseAccountCreationDialog.cs +++ b/Wino.Core.UWP/Dialogs/BaseAccountCreationDialog.cs @@ -16,7 +16,15 @@ namespace Wino.Dialogs public CancellationTokenSource CancellationTokenSource { get; private set; } - public static readonly DependencyProperty StateProperty = DependencyProperty.Register(nameof(State), typeof(AccountCreationDialogState), typeof(BaseAccountCreationDialog), new PropertyMetadata(AccountCreationDialogState.Idle)); + public static readonly DependencyProperty StateProperty = DependencyProperty.Register(nameof(State), typeof(AccountCreationDialogState), typeof(BaseAccountCreationDialog), new PropertyMetadata(AccountCreationDialogState.Idle, OnStateChanged)); + + private static void OnStateChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) + { + var dialog = d as BaseAccountCreationDialog; + dialog.OnStateChanged((AccountCreationDialogState)e.NewValue); + } + + public abstract void OnStateChanged(AccountCreationDialogState state); // Prevent users from dismissing it by ESC key. public void DialogClosing(ContentDialog sender, ContentDialogClosingEventArgs args) diff --git a/Wino.Core.UWP/WinoApplication.cs b/Wino.Core.UWP/WinoApplication.cs index be35832e..ddeb52a0 100644 --- a/Wino.Core.UWP/WinoApplication.cs +++ b/Wino.Core.UWP/WinoApplication.cs @@ -39,7 +39,6 @@ namespace Wino.Core.UWP protected IThemeService ThemeService { get; } protected IDatabaseService DatabaseService { get; } protected ITranslationService TranslationService { get; } - protected IMailDialogService DialogService { get; } // Order matters. private List initializeServices => new List() @@ -69,7 +68,6 @@ namespace Wino.Core.UWP ThemeService = Services.GetService(); DatabaseService = Services.GetService(); TranslationService = Services.GetService(); - DialogService = Services.GetService(); // Make sure the paths are setup on app start. AppConfiguration.ApplicationDataFolderPath = ApplicationData.Current.LocalFolder.Path; diff --git a/Wino.Core/Synchronizers/GmailSynchronizer.cs b/Wino.Core/Synchronizers/GmailSynchronizer.cs index a2fca285..b46b9ea1 100644 --- a/Wino.Core/Synchronizers/GmailSynchronizer.cs +++ b/Wino.Core/Synchronizers/GmailSynchronizer.cs @@ -49,7 +49,6 @@ namespace Wino.Core.Synchronizers.Mail private readonly GmailService _gmailService; private readonly PeopleServiceService _peopleService; - private readonly IGmailAuthenticator _authenticator; private readonly IGmailChangeProcessor _gmailChangeProcessor; private readonly ILogger _logger = Log.ForContext(); @@ -68,9 +67,6 @@ namespace Wino.Core.Synchronizers.Mail _gmailService = new GmailService(initializer); _peopleService = new PeopleServiceService(initializer); - - - _authenticator = authenticator; _gmailChangeProcessor = gmailChangeProcessor; } @@ -79,14 +75,14 @@ namespace Wino.Core.Synchronizers.Mail public override async Task GetProfileInformationAsync() { var profileRequest = _peopleService.People.Get("people/me"); - profileRequest.PersonFields = "names,photos"; + profileRequest.PersonFields = "names,photos,emailAddresses"; string senderName = string.Empty, base64ProfilePicture = string.Empty, address = string.Empty; - var gmailUserData = _gmailService.Users.GetProfile("me"); - var gmailProfile = await gmailUserData.ExecuteAsync(); + //var gmailUserData = _gmailService.Users.GetProfile("me"); + //var gmailProfile = await gmailUserData.ExecuteAsync(); + - address = gmailProfile.EmailAddress; var userProfile = await profileRequest.ExecuteAsync(); senderName = userProfile.Names?.FirstOrDefault()?.DisplayName ?? Account.SenderName; @@ -98,6 +94,8 @@ namespace Wino.Core.Synchronizers.Mail base64ProfilePicture = await GetProfilePictureBase64EncodedAsync(profilePicture).ConfigureAwait(false); } + address = userProfile.EmailAddresses.FirstOrDefault().Value; + return new ProfileInformation(senderName, base64ProfilePicture, address); } diff --git a/Wino.Mail/App.xaml.cs b/Wino.Mail/App.xaml.cs index 806f6399..f5496c79 100644 --- a/Wino.Mail/App.xaml.cs +++ b/Wino.Mail/App.xaml.cs @@ -233,7 +233,9 @@ namespace Wino } catch (WinoServerException serverException) { - DialogService.InfoBarMessage(Translator.Info_SyncFailedTitle, serverException.Message, InfoBarMessageType.Error); + var dialogService = Services.GetService(); + + dialogService.InfoBarMessage(Translator.Info_SyncFailedTitle, serverException.Message, InfoBarMessageType.Error); } } @@ -260,7 +262,7 @@ namespace Wino // Starting the server is fine, but check if server termination behavior is set to terminate. // This state will kill the server once the app is terminated. - isGoToAppPreferencesRequested = await DialogService.ShowWinoCustomMessageDialogAsync(Translator.AppCloseBackgroundSynchronizationWarningTitle, + isGoToAppPreferencesRequested = await dialogService.ShowWinoCustomMessageDialogAsync(Translator.AppCloseBackgroundSynchronizationWarningTitle, $"{Translator.AppCloseTerminateBehaviorWarningMessageFirstLine}\n{Translator.AppCloseTerminateBehaviorWarningMessageSecondLine}\n\n{Translator.AppCloseTerminateBehaviorWarningMessageThirdLine}", Translator.Buttons_Yes, WinoCustomMessageDialogIcon.Warning, diff --git a/Wino.Mail/Services/MailAuthenticatorConfiguration.cs b/Wino.Mail/Services/MailAuthenticatorConfiguration.cs index 89708458..5c8c0388 100644 --- a/Wino.Mail/Services/MailAuthenticatorConfiguration.cs +++ b/Wino.Mail/Services/MailAuthenticatorConfiguration.cs @@ -25,5 +25,7 @@ namespace Wino.Services "https://www.googleapis.com/auth/userinfo.profile", "https://www.googleapis.com/auth/gmail.labels" }; + + public string GmailTokenStoreIdentifier => "WinoMailGmailTokenStore"; } }