diff --git a/Wino.Core.Domain/Translations/WinoTranslationDictionary.cs b/Wino.Core.Domain/Translations/WinoTranslationDictionary.cs index 690171df..833c2206 100644 --- a/Wino.Core.Domain/Translations/WinoTranslationDictionary.cs +++ b/Wino.Core.Domain/Translations/WinoTranslationDictionary.cs @@ -1,6 +1,10 @@ -using System.Reflection; + +using System.Reflection; using Wino.Core.Domain.Enums; - +#if !NET8_0 +using System.IO; +using System.Collections.Generic; +#endif namespace Wino.Core.Domain.Translations { public class WinoTranslationDictionary : Dictionary diff --git a/Wino.Core.UWP/CoreUWPContainerSetup.cs b/Wino.Core.UWP/CoreUWPContainerSetup.cs index 295c907c..66e847c2 100644 --- a/Wino.Core.UWP/CoreUWPContainerSetup.cs +++ b/Wino.Core.UWP/CoreUWPContainerSetup.cs @@ -1,6 +1,7 @@ using Microsoft.Extensions.DependencyInjection; using Wino.Core.Domain.Interfaces; using Wino.Core.UWP.Services; +using Wino.Core.WinUI.Services; using Wino.Services; namespace Wino.Core.UWP @@ -13,6 +14,7 @@ namespace Wino.Core.UWP services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); + services.AddSingleton(); services.AddTransient(); services.AddTransient(); diff --git a/Wino.Core.UWP/Dispatcher.cs b/Wino.Core.UWP/Dispatcher.cs new file mode 100644 index 00000000..060607f8 --- /dev/null +++ b/Wino.Core.UWP/Dispatcher.cs @@ -0,0 +1,20 @@ +using System; +using System.Threading.Tasks; +using Windows.UI.Core; +using Wino.Core.Domain.Interfaces; + +namespace Wino.Core.UWP +{ + public class UWPDispatcher : IDispatcher + { + private readonly CoreDispatcher _coreDispatcher; + + public UWPDispatcher(CoreDispatcher coreDispatcher) + { + _coreDispatcher = coreDispatcher; + } + + public Task ExecuteOnUIThread(Action action) + => _coreDispatcher.RunAsync(CoreDispatcherPriority.Normal, () => action()).AsTask(); + } +} diff --git a/Wino.Core.UWP/Services/AppShellService.cs b/Wino.Core.UWP/Services/AppShellService.cs new file mode 100644 index 00000000..55d3cbfe --- /dev/null +++ b/Wino.Core.UWP/Services/AppShellService.cs @@ -0,0 +1,19 @@ +#if NET8_0 +using Microsoft.UI.Xaml; +using Microsoft.UI.Xaml.Controls; +#else +using Windows.UI.Xaml; +#endif + +namespace Wino.Core.WinUI.Services +{ + public interface IAppShellService + { + Window AppWindow { get; set; } + } + + public class AppShellService : IAppShellService + { + public Window AppWindow { get; set; } + } +} diff --git a/Wino.Core.UWP/Services/NativeAppService.cs b/Wino.Core.UWP/Services/NativeAppService.cs index 9e0d4c04..5759719e 100644 --- a/Wino.Core.UWP/Services/NativeAppService.cs +++ b/Wino.Core.UWP/Services/NativeAppService.cs @@ -2,7 +2,6 @@ using System.Threading.Tasks; using Windows.ApplicationModel; using Windows.Foundation.Metadata; -using Windows.Security.Authentication.Web; using Windows.Security.Cryptography; using Windows.Security.Cryptography.Core; using Windows.Storage; @@ -27,7 +26,16 @@ namespace Wino.Services private string _mimeMessagesFolder; private string _editorBundlePath; - public string GetWebAuthenticationBrokerUri() => WebAuthenticationBroker.GetCurrentApplicationCallbackUri().AbsoluteUri; + public string GetWebAuthenticationBrokerUri() + { +#if NET8_0 + // WinUI + return "wino://winomail.app"; +#else + return WebAuthenticationBroker.GetCurrentApplicationCallbackUri().AbsoluteUri; +#endif + + } public async Task GetMimeMessageStoragePath() { diff --git a/Wino.Core.UWP/Services/ThemeService.cs b/Wino.Core.UWP/Services/ThemeService.cs index 4af56200..54f1bbd8 100644 --- a/Wino.Core.UWP/Services/ThemeService.cs +++ b/Wino.Core.UWP/Services/ThemeService.cs @@ -165,8 +165,13 @@ namespace Wino.Services // Save reference as this might be null when the user is in another app + +#if NET8_0 // WinUI +#else mainApplicationFrame = Window.Current.Content as Frame; +#endif + if (mainApplicationFrame == null) return; diff --git a/Wino.Core.UWP/Wino.Core.UWP.csproj b/Wino.Core.UWP/Wino.Core.UWP.csproj index 993d9168..e9500653 100644 --- a/Wino.Core.UWP/Wino.Core.UWP.csproj +++ b/Wino.Core.UWP/Wino.Core.UWP.csproj @@ -128,6 +128,7 @@ + diff --git a/Wino.Mail.WinUI/App.xaml.cs b/Wino.Mail.WinUI/App.xaml.cs index 6cf65d8d..51503247 100644 --- a/Wino.Mail.WinUI/App.xaml.cs +++ b/Wino.Mail.WinUI/App.xaml.cs @@ -1,18 +1,25 @@ using System.Text; using Microsoft.Extensions.DependencyInjection; using Microsoft.UI.Xaml; +using Microsoft.UI.Xaml.Controls; +using Microsoft.UI.Xaml.Media; using Wino.Core; using Wino.Core.Domain.Interfaces; using Wino.Core.Services; - +using Wino.Core.WinUI.Services; +using Wino.Views; +using WinUIEx; namespace Wino { public partial class App : Application { - public static MainWindow MainWindow = new MainWindow(); + private WindowEx m_Window; + private Frame m_ShellFrame; public App() { + if (WebAuthenticator.CheckOAuthRedirectionActivation()) return; + InitializeComponent(); Services = ConfigureServices(); @@ -29,19 +36,38 @@ namespace Wino _appInitializerService = Services.GetService(); _synchronizerFactory = Services.GetService(); _translationService = Services.GetService(); + _appShellService = Services.GetService(); Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); } protected override async void OnLaunched(LaunchActivatedEventArgs args) { + ConfigureWindow(); + + _appShellService.AppWindow = m_Window; + foreach (var service in initializeServices) { await service.InitializeAsync(); } - MainWindow.Activate(); - MainWindow.StartWino(); + m_ShellFrame.Navigate(typeof(AppShell)); + m_Window.Activate(); + } + + private void ConfigureWindow() + { + m_Window = new WindowEx + { + SystemBackdrop = new MicaBackdrop(), + ExtendsContentIntoTitleBar = true, + MinWidth = 420 + }; + + m_ShellFrame = new Frame(); + + m_Window.Content = m_ShellFrame; } } } diff --git a/Wino.Mail.WinUI/MainWindow.xaml b/Wino.Mail.WinUI/MainWindow.xaml deleted file mode 100644 index 43f58f45..00000000 --- a/Wino.Mail.WinUI/MainWindow.xaml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - diff --git a/Wino.Mail.WinUI/MainWindow.xaml.cs b/Wino.Mail.WinUI/MainWindow.xaml.cs deleted file mode 100644 index ac587a87..00000000 --- a/Wino.Mail.WinUI/MainWindow.xaml.cs +++ /dev/null @@ -1,18 +0,0 @@ -using Microsoft.UI.Xaml; -using Wino.Views; - -namespace Wino -{ - public sealed partial class MainWindow : Window - { - public MainWindow() - { - InitializeComponent(); - } - - public void StartWino() - { - WindowFrame.Navigate(typeof(AppShell)); - } - } -} diff --git a/Wino.Mail.WinUI/Package.appxmanifest b/Wino.Mail.WinUI/Package.appxmanifest index 315f74eb..0c8a5e90 100644 --- a/Wino.Mail.WinUI/Package.appxmanifest +++ b/Wino.Mail.WinUI/Package.appxmanifest @@ -8,15 +8,15 @@ IgnorableNamespaces="uap rescap"> - + - Wino.Mail.WinUI - bkaan + WPCEx + Burak KÖSE Assets\StoreLogo.png @@ -42,6 +42,11 @@ + + + + + diff --git a/Wino.Mail.WinUI/Wino.Mail.WinUI.csproj b/Wino.Mail.WinUI/Wino.Mail.WinUI.csproj index 796a3809..eec8463a 100644 --- a/Wino.Mail.WinUI/Wino.Mail.WinUI.csproj +++ b/Wino.Mail.WinUI/Wino.Mail.WinUI.csproj @@ -12,6 +12,7 @@ true true 10.0.19041.35-preview + True @@ -99,7 +100,6 @@ - diff --git a/Wino.Mail/App.xaml.cs b/Wino.Mail/App.xaml.cs index 9a4a9f3b..53bcb5ef 100644 --- a/Wino.Mail/App.xaml.cs +++ b/Wino.Mail/App.xaml.cs @@ -55,6 +55,8 @@ namespace Wino { base.OnWindowCreated(args); + _appShellService.AppWindow = args.Window; + LogActivation("Window is created."); ConfigureTitleBar(); diff --git a/Wino.Mail/AppShell.xaml.cs b/Wino.Mail/AppShell.xaml.cs index cf23f12b..fe54c0cc 100644 --- a/Wino.Mail/AppShell.xaml.cs +++ b/Wino.Mail/AppShell.xaml.cs @@ -24,6 +24,7 @@ using Wino.MenuFlyouts.Context; using Wino.Views.Abstract; using Microsoft.UI.Xaml.Controls; + #if NET8_0 using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls.Primitives; @@ -295,7 +296,7 @@ namespace Wino.Views /// public async void Receive(InfoBarMessageRequested message) { - await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => + await ViewModel.ExecuteUIThread(() => { if (string.IsNullOrEmpty(message.ActionButtonTitle) || message.Action == null) { diff --git a/Wino.Mail/Controls/Advanced/WinoAppTitleBar.xaml.cs b/Wino.Mail/Controls/Advanced/WinoAppTitleBar.xaml.cs index 2fda2fa8..4c0232d8 100644 --- a/Wino.Mail/Controls/Advanced/WinoAppTitleBar.xaml.cs +++ b/Wino.Mail/Controls/Advanced/WinoAppTitleBar.xaml.cs @@ -1,4 +1,6 @@ using Windows.Foundation; +using Wino.Core.WinUI.Services; +using Microsoft.Extensions.DependencyInjection; #if NET8_0 using Microsoft.UI.Xaml; @@ -11,6 +13,8 @@ namespace Wino.Controls.Advanced { public sealed partial class WinoAppTitleBar : UserControl { + private IAppShellService _appShellService = App.Current.Services.GetService(); + public event TypedEventHandler BackButtonClicked; public string CoreWindowText @@ -152,11 +156,8 @@ namespace Wino.Controls.Advanced public WinoAppTitleBar() { InitializeComponent(); -#if NET8_0 - App.MainWindow.SetTitleBar(dragbar); -#else - Window.Current.SetTitleBar(dragbar); -#endif + + _appShellService.AppWindow.SetTitleBar(dragbar); } private void BackClicked(object sender, RoutedEventArgs e) diff --git a/Wino.Mail/PartialApp.cs b/Wino.Mail/PartialApp.cs index 4c09d346..bbceff4e 100644 --- a/Wino.Mail/PartialApp.cs +++ b/Wino.Mail/PartialApp.cs @@ -18,6 +18,8 @@ using Wino.Core.UWP; using Wino.Mail.ViewModels; using Wino.Services; using Wino.Core.Services; +using Wino.Core.WinUI.Services; + #if NET8_0 using Microsoft.UI.Xaml; @@ -40,6 +42,7 @@ namespace Wino private readonly IAppInitializerService _appInitializerService; private readonly IWinoSynchronizerFactory _synchronizerFactory; private readonly ITranslationService _translationService; + private readonly IAppShellService _appShellService; public new static App Current => (App)Application.Current; public IServiceProvider Services { get; } diff --git a/Wino.Mail/Services/WinoNavigationService.cs b/Wino.Mail/Services/WinoNavigationService.cs index f351ee3e..3c3d69f0 100644 --- a/Wino.Mail/Services/WinoNavigationService.cs +++ b/Wino.Mail/Services/WinoNavigationService.cs @@ -11,9 +11,10 @@ using Wino.Mail.ViewModels.Messages; using Wino.Views; using Wino.Views.Account; using Wino.Views.Settings; +using Wino.Core.WinUI.Services; + #if NET8_0 -using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; using Microsoft.UI.Xaml.Media.Animation; #else @@ -27,6 +28,7 @@ namespace Wino.Services public class WinoNavigationService : IWinoNavigationService { private readonly IStatePersistanceService _statePersistanceService; + private readonly IAppShellService _appShellService; private WinoPage[] _renderingPageTypes = new WinoPage[] { @@ -34,9 +36,10 @@ namespace Wino.Services WinoPage.ComposePage }; + private Frame GetCoreFrame(NavigationReferenceFrame frameType) { - if (Window.Current.Content is Frame appFrame && appFrame.Content is AppShell shellPage) + if (_appShellService.AppWindow.Content is Frame appFrame && appFrame.Content is AppShell shellPage) return WinoVisualTreeHelper.GetChildObject(shellPage, frameType.ToString()); return null; @@ -52,9 +55,10 @@ namespace Wino.Services } } - public WinoNavigationService(IStatePersistanceService statePersistanceService) + public WinoNavigationService(IStatePersistanceService statePersistanceService, IAppShellService appShellService) { _statePersistanceService = statePersistanceService; + _appShellService = appShellService; } private Type GetPageType(WinoPage winoPage)