diff --git a/.claude/instructions/winui3.instructions.md b/.claude/instructions/winui3.instructions.md new file mode 100644 index 00000000..811306c6 --- /dev/null +++ b/.claude/instructions/winui3.instructions.md @@ -0,0 +1,160 @@ +--- +description: 'WinUI 3 and Windows App SDK coding guidelines. Prevents common UWP API misuse, enforces correct XAML namespaces, threading, windowing, and MVVM patterns for desktop Windows apps.' +applyTo: '**/*.xaml, **/*.cs, **/*.csproj' +--- + +# WinUI 3 / Windows App SDK + +## Critical Rules — NEVER Use Legacy UWP APIs + +These UWP patterns are **wrong** for WinUI 3 desktop apps. Always use the Windows App SDK equivalent. + +- **NEVER** use `Windows.UI.Popups.MessageDialog`. Use `ContentDialog` with `XamlRoot` set. +- **NEVER** show a `ContentDialog` without setting `dialog.XamlRoot = this.Content.XamlRoot` first. +- **NEVER** use `CoreDispatcher.RunAsync` or `Dispatcher.RunAsync`. Use `DispatcherQueue.TryEnqueue`. +- **NEVER** use `Window.Current`. Track the main window via a static `App.MainWindow` property. +- **NEVER** use `Windows.UI.Xaml.*` namespaces. Use `Microsoft.UI.Xaml.*`. +- **NEVER** use `Windows.UI.Composition`. Use `Microsoft.UI.Composition`. +- **NEVER** use `Windows.UI.Colors`. Use `Microsoft.UI.Colors`. +- **NEVER** use `ApplicationView` or `CoreWindow` for window management. Use `Microsoft.UI.Windowing.AppWindow`. +- **NEVER** use `CoreApplicationViewTitleBar`. Use `AppWindowTitleBar`. +- **NEVER** use `GetForCurrentView()` patterns (e.g., `UIViewSettings.GetForCurrentView()`). These do not exist in desktop WinUI 3. Use `AppWindow` APIs instead. +- **NEVER** use UWP `PrintManager` directly. Use `IPrintManagerInterop` with a window handle. +- **NEVER** use `DataTransferManager` directly for sharing. Use `IDataTransferManagerInterop` with a window handle. +- **NEVER** use UWP `IBackgroundTask`. Use `Microsoft.Windows.AppLifecycle` activation. +- **NEVER** use `WebAuthenticationBroker`. Use `OAuth2Manager` (Windows App SDK 1.7+). + +## XAML Patterns + +- The default XAML namespace maps to `Microsoft.UI.Xaml`, not `Windows.UI.Xaml`. +- Prefer `{x:Bind}` over `{Binding}` for compiled, type-safe, higher-performance bindings. +- Set `x:DataType` on `DataTemplate` elements when using `{x:Bind}` — this is required for compiled bindings in templates. On Page/UserControl, `x:DataType` enables compile-time binding validation but is not strictly required if the DataContext does not change. +- Use `Mode=OneWay` for dynamic values, `Mode=OneTime` for static, `Mode=TwoWay` only for editable inputs. +- Do not bind static constants — set them directly in XAML. + +## Threading + +- Use `DispatcherQueue.TryEnqueue(() => { ... })` to update UI from background threads. +- `TryEnqueue` returns `bool`, not a `Task` — it is fire-and-forget. +- Check thread access with `DispatcherQueue.HasThreadAccess` before dispatching. +- WinUI 3 uses standard STA (not ASTA). No built-in reentrancy protection — be cautious with async code that pumps messages. + +## Windowing + +- Get the `AppWindow` from a WinUI 3 `Window` via `WindowNative.GetWindowHandle` → `Win32Interop.GetWindowIdFromWindow` → `AppWindow.GetFromWindowId`. +- Use `AppWindow` for resize, move, title, and presenter operations. +- Custom title bar: use `AppWindow.TitleBar` properties, not `CoreApplicationViewTitleBar`. +- Track the main window as `App.MainWindow` (a static property set in `OnLaunched`). + +## Dialogs and Pickers + +- **ContentDialog**: Always set `dialog.XamlRoot = this.Content.XamlRoot` before calling `ShowAsync()`. +- **File/Folder Pickers**: Initialize with `WinRT.Interop.InitializeWithWindow.Initialize(picker, hwnd)` where `hwnd` comes from `WindowNative.GetWindowHandle(App.MainWindow)`. +- **Share/Print**: Use COM interop interfaces (`IDataTransferManagerInterop`, `IPrintManagerInterop`) with window handles. + +## MVVM and Data Binding + +- Prefer `CommunityToolkit.Mvvm` (`[ObservableProperty]`, `[RelayCommand]`) for MVVM infrastructure. +- Use `Microsoft.Extensions.DependencyInjection` for service registration and injection. +- Keep UI (Views) focused on layout and bindings; keep logic in ViewModels and services. +- Use `async`/`await` for I/O and long-running work to keep the UI responsive. + +## Project Setup + +- Target `net10.0-windows10.0.22621.0` (or appropriate TFM for the project's target SDK). +- Set `true` in the project file. +- Reference the latest stable `Microsoft.WindowsAppSDK` NuGet package. +- Use `System.Text.Json` with source generators for JSON serialization. + +## C# Code Style + +- Use file-scoped namespaces. +- Enable nullable reference types. Use `is null` / `is not null` instead of `== null`. +- Prefer pattern matching over `as`/`is` with null checks. +- PascalCase for types, methods, properties. camelCase for private fields. +- Allman brace style (opening brace on its own line). +- Prefer explicit types for built-in types; use `var` only when the type is obvious. + +## Accessibility + +- Set `AutomationProperties.Name` on all interactive controls. +- Use `AutomationProperties.HeadingLevel` on section headers. +- Hide decorative elements with `AutomationProperties.AccessibilityView="Raw"`. +- Ensure full keyboard navigation (Tab, Enter, Space, arrow keys). +- Meet WCAG color contrast requirements. + +## Performance + +- Prefer `{x:Bind}` (compiled) over `{Binding}` (reflection-based). +- **NativeAOT:** Under Native AOT compilation, `{Binding}` (reflection-based) does not work at all. Only `{x:Bind}` (compiled bindings) is supported. If the project uses NativeAOT, use `{x:Bind}` exclusively. +- Use `x:Load` or `x:DeferLoadStrategy` for UI elements that are not immediately needed. +- Use `ItemsRepeater` with virtualization for large lists. +- Avoid deep layout nesting — prefer `Grid` over nested `StackPanel` chains. +- Use `async`/`await` for all I/O; never block the UI thread. + +## App Settings (Packaged vs Unpackaged) + +- **Packaged apps**: `ApplicationData.Current.LocalSettings` works as expected. +- **Unpackaged apps**: Use a custom settings file (e.g., JSON in `Environment.GetFolderPath(SpecialFolder.LocalApplicationData)`). +- Do not assume `ApplicationData` is always available — check packaging status first. + +## Typography + +- **Always** use built-in TextBlock styles (`CaptionTextBlockStyle`, `BodyTextBlockStyle`, `BodyStrongTextBlockStyle`, `SubtitleTextBlockStyle`, `TitleTextBlockStyle`, `TitleLargeTextBlockStyle`, `DisplayTextBlockStyle`). +- Prefer using the built-in TextBlock styles over hardcoding `FontSize`, `FontWeight`, or `FontFamily`. +- Font: Segoe UI Variable is the default — do not change it. +- Use sentence casing for all UI text. + + +## Theming & Colors + +- **Always** use `{ThemeResource}` for brushes and colors to support Light, Dark, and High Contrast themes automatically. +- **Never** hardcode color values (`#FFFFFF`, `Colors.White`, etc.) for UI elements. Use theme resources like `TextFillColorPrimaryBrush`, `CardBackgroundFillColorDefaultBrush`, `CardStrokeColorDefaultBrush`. +- Use `SystemAccentColor` (and `Light1`–`Light3`, `Dark1`–`Dark3` variants) for the user's accent color palette. +- For borders: use `CardStrokeColorDefaultBrush` or `ControlStrokeColorDefaultBrush`. + +## Spacing & Layout + +- Use a **4px grid system**: all margins, padding, and spacing values must be multiples of 4px. +- Standard spacing: 4 (compact), 8 (controls), 12 (small gutters), 16 (content padding), 24 (large gutters). +- Prefer `Grid` over deeply nested `StackPanel` chains for performance. +- Use `Auto` for content-sized rows/columns, `*` for proportional sizing. Avoid fixed pixel sizes. +- Use `VisualStateManager` with `AdaptiveTrigger` for responsive layouts at breakpoints (640px, 1008px). +- Use `ControlCornerRadius` (4px) for small controls and `OverlayCornerRadius` (8px) for cards, dialogs, flyouts. + +## Materials & Elevation + +- Use **Mica** (`MicaBackdrop`) for the app window backdrop. Requires transparent layers above to show through. +- Use **Acrylic** for transient surfaces only (flyouts, menus, navigation panes). +- Use `LayerFillColorDefaultBrush` for content layers above Mica. +- Use `ThemeShadow` with Z-axis `Translation` for elevation. Cards: 4–8 px, Flyouts: 32 px, Dialogs: 128 px. + +## Motion & Transitions + +- Use built-in theme transitions (`EntranceThemeTransition`, `RepositionThemeTransition`, `ContentThemeTransition`, `AddDeleteThemeTransition`). +- Avoid custom storyboard animations when a built-in transition exists. + +## Control Selection + +- Use `NavigationView` for primary app navigation (not custom sidebars). +- Use `InfoBar` for persistent in-app notifications (not custom banners). +- Use `TeachingTip` for contextual guidance (not custom popups). +- Use `NumberBox` for numeric input (not TextBox with manual validation). +- Use `ToggleSwitch` for on/off settings (not CheckBox). +- Use `ItemsView` as the modern collection control for displaying data with built-in selection, virtualization, and layout flexibility. +- Use `ListView`/`GridView` for standard virtualized lists and grids, especially when built-in selection support is needed. +- Use `ItemsRepeater` only for fully custom virtualizing layouts where you need complete control over rendering and do not need built-in selection or interaction handling. +- Use `Expander` for collapsible sections (not custom visibility toggling). + +## Error Handling + +- Always wrap `async void` event handlers in try/catch to prevent unhandled crashes. +- Use `InfoBar` (with `Severity = Error`) for user-facing error messages, not `ContentDialog` for routine errors. +- Handle `App.UnhandledException` for logging and graceful recovery. + +## Testing + +- **NEVER** use a plain MSTest or xUnit project for tests that instantiate WinUI 3 XAML types. Use a **Unit Test App (WinUI in Desktop)** project, which provides the Xaml runtime and UI thread. +- Use `[TestMethod]` for pure logic tests. Use `[UITestMethod]` for any test that creates or interacts with `Microsoft.UI.Xaml` types (controls, pages, user controls). +- Place testable business logic in a **Class Library (WinUI in Desktop)** project, separate from the main app. +- Build the solution before running tests to enable Visual Studio test discovery. diff --git a/Instructions/WelcomePageInstructions.md b/Instructions/WelcomePageInstructions.md new file mode 100644 index 00000000..3dc70d2e --- /dev/null +++ b/Instructions/WelcomePageInstructions.md @@ -0,0 +1,16 @@ +This is a design document for new welcome page for users who have no accounts defined in the database. + +Right now we welcome our users in WelcomePage if they have no accounts defined. Navigation is like ShellWindow -> MailAppShell -> WelcomePage. This allows users to access ManageAccountsPage from the side bar since mail app shell has this navigation option. +We don't want this anymore. Here are the instructions to define new welcome page (or initial startup wizard page): + +- ShellWindow should not be used to navigate this new welcome page. +- Create a new WelcomeWindow and navigate to WelcomePage. You can remove all the content inside the existing welcome page because we are doing a new welcome page. +- In App.xaml.cs, we must check if the user has accounts defined or not. If no accounts, create this new window and activate it. +- In this Window I want to highlight a few things. It should clearly say that this is a native Windows application that supports Mail and Calendar. +- Design is not important at the moment, but make sure to follow Windows fluent design guidelines. +- In this page users must be able to + ++ Go to manage accounts page ++ Show the latest version changelog. We have this new "What's new" dialog, but resolve the latest json for the update and show it on the page as well using the same FlipView. You can make this a UserControl maybe. It'll be exactly the same, except "Get started" button should not be visible when the control is loaded in WelcomePage. ++ Some details from the About page like version, github page, donation link etc. would be great. We can show it here in new WelcomePage too. + diff --git a/Wino.Calendar.ViewModels/CalendarAppShellViewModel.cs b/Wino.Calendar.ViewModels/CalendarAppShellViewModel.cs index 7ca56bba..42eaaaa1 100644 --- a/Wino.Calendar.ViewModels/CalendarAppShellViewModel.cs +++ b/Wino.Calendar.ViewModels/CalendarAppShellViewModel.cs @@ -72,10 +72,14 @@ public partial class CalendarAppShellViewModel : CalendarBaseViewModel, IAccountService accountService, ICalendarService calendarService, IAccountCalendarStateService accountCalendarStateService, - INavigationService navigationService) + INavigationService navigationService, + IDialogServiceBase dialogService, + IUpdateManager updateManager) { _accountService = accountService; _calendarService = calendarService; + _dialogService = dialogService; + _updateManager = updateManager; AccountCalendarStateService = accountCalendarStateService; AccountCalendarStateService.AccountCalendarSelectionStateChanged += UpdateAccountCalendarRequested; @@ -123,9 +127,24 @@ public partial class CalendarAppShellViewModel : CalendarBaseViewModel, await InitializeAccountCalendarsAsync(); + await ShowWhatIsNewIfNeededAsync(); + TodayClicked(); } + private async Task ShowWhatIsNewIfNeededAsync() + { + if (!_updateManager.ShouldShowUpdateNotes()) + return; + + var notes = await _updateManager.GetLatestUpdateNotesAsync(); + + if (notes.Sections.Count == 0) + return; + + await _dialogService.ShowWhatIsNewDialogAsync(notes); + } + private async void AccountCalendarStateCollectivelyChanged(object sender, GroupedAccountCalendarViewModel e) { // When using three-state checkbox, multiple accounts will be selected/unselected at the same time. @@ -271,6 +290,8 @@ public partial class CalendarAppShellViewModel : CalendarBaseViewModel, private DateTime? _navigationDate; private readonly IAccountService _accountService; private readonly ICalendarService _calendarService; + private readonly IDialogServiceBase _dialogService; + private readonly IUpdateManager _updateManager; #region Commands diff --git a/Wino.Core.Domain/BasicTypesJsonContext.cs b/Wino.Core.Domain/BasicTypesJsonContext.cs index b9dba02d..f6085c1c 100644 --- a/Wino.Core.Domain/BasicTypesJsonContext.cs +++ b/Wino.Core.Domain/BasicTypesJsonContext.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using System.Text.Json.Serialization; +using Wino.Core.Domain.Models.Updates; namespace Wino.Core.Domain; @@ -8,4 +9,6 @@ namespace Wino.Core.Domain; [JsonSerializable(typeof(int))] [JsonSerializable(typeof(List))] [JsonSerializable(typeof(bool))] +[JsonSerializable(typeof(UpdateNotes))] +[JsonSerializable(typeof(List))] public partial class BasicTypesJsonContext : JsonSerializerContext; diff --git a/Wino.Core.Domain/Constants.cs b/Wino.Core.Domain/Constants.cs index 6165b628..72d49850 100644 --- a/Wino.Core.Domain/Constants.cs +++ b/Wino.Core.Domain/Constants.cs @@ -21,7 +21,6 @@ public static class Constants public const string ToastModeKey = nameof(ToastModeKey); public const string ToastModeMail = nameof(ToastModeMail); public const string ToastModeCalendar = nameof(ToastModeCalendar); - public const string ClientLogFile = "Client_.log"; public const string ServerLogFile = "Server_.log"; public const string LogArchiveFileName = "WinoLogs.zip"; diff --git a/Wino.Core.Domain/Enums/AccountSetupStepStatus.cs b/Wino.Core.Domain/Enums/AccountSetupStepStatus.cs new file mode 100644 index 00000000..a0bb99a3 --- /dev/null +++ b/Wino.Core.Domain/Enums/AccountSetupStepStatus.cs @@ -0,0 +1,9 @@ +namespace Wino.Core.Domain.Enums; + +public enum AccountSetupStepStatus +{ + Pending, + InProgress, + Succeeded, + Failed +} diff --git a/Wino.Core.Domain/Enums/WinoPage.cs b/Wino.Core.Domain/Enums/WinoPage.cs index 2787ba3f..43637436 100644 --- a/Wino.Core.Domain/Enums/WinoPage.cs +++ b/Wino.Core.Domain/Enums/WinoPage.cs @@ -34,5 +34,10 @@ public enum WinoPage CalendarAccountSettingsPage, EventDetailsPage, SignatureAndEncryptionPage, - StoragePage + StoragePage, + WelcomePageV2, + WelcomeHostPage, + ProviderSelectionPage, + AccountSetupProgressPage, + SpecialImapCredentialsPage } diff --git a/Wino.Core.Domain/Interfaces/IDialogServiceBase.cs b/Wino.Core.Domain/Interfaces/IDialogServiceBase.cs index 10189f83..11a9f6f3 100644 --- a/Wino.Core.Domain/Interfaces/IDialogServiceBase.cs +++ b/Wino.Core.Domain/Interfaces/IDialogServiceBase.cs @@ -5,6 +5,7 @@ using Wino.Core.Domain.Enums; using Wino.Core.Domain.Models.Accounts; using Wino.Core.Domain.Models.Common; using Wino.Core.Domain.Models.Printing; +using Wino.Core.Domain.Models.Updates; namespace Wino.Core.Domain.Interfaces; @@ -30,4 +31,10 @@ public interface IDialogServiceBase Task> PickFilesAsync(params object[] typeFilters); Task PickFilePathAsync(string saveFileName); Task ShowPrintDialogAsync(WebView2PrintSettingsModel initialSettings = null); + + /// + /// Presents the "What's New" dialog for the current version. + /// This dialog is undismissable and runs any pending migrations when the user clicks "Get Started". + /// + Task ShowWhatIsNewDialogAsync(UpdateNotes notes); } diff --git a/Wino.Core.Domain/Interfaces/INewThemeService.cs b/Wino.Core.Domain/Interfaces/INewThemeService.cs index d571d7ac..037b4bee 100644 --- a/Wino.Core.Domain/Interfaces/INewThemeService.cs +++ b/Wino.Core.Domain/Interfaces/INewThemeService.cs @@ -37,4 +37,10 @@ public interface INewThemeService : IInitializeAsync // Backdrop management List GetAvailableBackdropTypes(); + + /// + /// Re-applies the current theme (backdrop, root theme, accent, caption colors) + /// to the currently active window. Use after a window transition. + /// + Task ApplyThemeToActiveWindowAsync(); } diff --git a/Wino.Core.Domain/Interfaces/IUpdateManager.cs b/Wino.Core.Domain/Interfaces/IUpdateManager.cs new file mode 100644 index 00000000..d0e4a900 --- /dev/null +++ b/Wino.Core.Domain/Interfaces/IUpdateManager.cs @@ -0,0 +1,21 @@ +using System.Threading.Tasks; +using Wino.Core.Domain.Models.Updates; +using System.Collections.Generic; + +namespace Wino.Core.Domain.Interfaces; + +public interface IUpdateManager +{ + /// Loads and parses the update notes for the current version from the bundled asset file. + Task GetLatestUpdateNotesAsync(); + + /// Loads and parses the app feature highlights from the bundled asset file. + Task> GetFeaturesAsync(); + + /// Returns true if the current version's update notes have not yet been shown to the user. + bool ShouldShowUpdateNotes(); + + /// Stores a flag in local settings indicating the update notes for the current version have been seen. + void MarkUpdateNotesAsSeen(); + +} diff --git a/Wino.Core.Domain/Models/Accounts/AccountSetupStepModel.cs b/Wino.Core.Domain/Models/Accounts/AccountSetupStepModel.cs new file mode 100644 index 00000000..65befde6 --- /dev/null +++ b/Wino.Core.Domain/Models/Accounts/AccountSetupStepModel.cs @@ -0,0 +1,24 @@ +using CommunityToolkit.Mvvm.ComponentModel; +using Wino.Core.Domain.Enums; + +namespace Wino.Core.Domain.Models.Accounts; + +public partial class AccountSetupStepModel : ObservableObject +{ + public string Title { get; init; } + + [ObservableProperty] + [NotifyPropertyChangedFor(nameof(IsPending))] + [NotifyPropertyChangedFor(nameof(IsInProgress))] + [NotifyPropertyChangedFor(nameof(IsSucceeded))] + [NotifyPropertyChangedFor(nameof(IsFailed))] + public partial AccountSetupStepStatus Status { get; set; } = AccountSetupStepStatus.Pending; + + [ObservableProperty] + public partial string ErrorMessage { get; set; } + + public bool IsPending => Status == AccountSetupStepStatus.Pending; + public bool IsInProgress => Status == AccountSetupStepStatus.InProgress; + public bool IsSucceeded => Status == AccountSetupStepStatus.Succeeded; + public bool IsFailed => Status == AccountSetupStepStatus.Failed; +} diff --git a/Wino.Core.Domain/Models/Updates/UpdateNoteSection.cs b/Wino.Core.Domain/Models/Updates/UpdateNoteSection.cs new file mode 100644 index 00000000..0bb8f7c8 --- /dev/null +++ b/Wino.Core.Domain/Models/Updates/UpdateNoteSection.cs @@ -0,0 +1,27 @@ +using System.Text.Json.Serialization; + +namespace Wino.Core.Domain.Models.Updates; + +public class UpdateNoteSection +{ + [JsonPropertyName("title")] + public string Title { get; set; } = string.Empty; + + [JsonPropertyName("description")] + public string Description { get; set; } = string.Empty; + + [JsonPropertyName("imageUrl")] + public string ImageUrl { get; set; } = string.Empty; + + [JsonPropertyName("imageWidth")] + public double? ImageWidth { get; set; } + + [JsonPropertyName("imageHeight")] + public double? ImageHeight { get; set; } + + /// Gets the image width for binding, returning NaN for auto-sizing when not specified. + public double ActualImageWidth => ImageWidth ?? double.NaN; + + /// Gets the image height for binding, returning NaN for auto-sizing when not specified. + public double ActualImageHeight => ImageHeight ?? double.NaN; +} diff --git a/Wino.Core.Domain/Models/Updates/UpdateNotes.cs b/Wino.Core.Domain/Models/Updates/UpdateNotes.cs new file mode 100644 index 00000000..354f6f6c --- /dev/null +++ b/Wino.Core.Domain/Models/Updates/UpdateNotes.cs @@ -0,0 +1,7 @@ +using System.Collections.Generic; +namespace Wino.Core.Domain.Models.Updates; + +public class UpdateNotes +{ + public List Sections { get; set; } = []; +} diff --git a/Wino.Core.Domain/Translations/en_US/resources.json b/Wino.Core.Domain/Translations/en_US/resources.json index 36074c3a..f0277a2a 100644 --- a/Wino.Core.Domain/Translations/en_US/resources.json +++ b/Wino.Core.Domain/Translations/en_US/resources.json @@ -993,5 +993,66 @@ "CalendarAccountSettings_DefaultShowAs": "Default Show As Status", "CalendarAccountSettings_DefaultShowAsDescription": "Default availability status for new events created with this account", "CalendarAccountSettings_PrimaryCalendar": "Primary Calendar", - "CalendarAccountSettings_PrimaryCalendarDescription": "Mark this calendar as the primary calendar for the account" + "CalendarAccountSettings_PrimaryCalendarDescription": "Mark this calendar as the primary calendar for the account", + "WhatIsNew_GetStartedButton": "Get Started", + "WhatIsNew_ContinueAnywayButton": "Continue anyway", + "WhatIsNew_PreparingForNewVersionButton": "Preparing for new version...", + "WhatIsNew_MigrationPreparing_Title": "Preparing your data", + "WhatIsNew_MigrationPreparing_Description": "Wino is applying update migrations. Please wait while we prepare your account data for this release.", + "WhatIsNew_MigrationFailedMessage": "Applying migrations failed with error code {0}. You may continue to use the application. However, if you encounter serious issues please re-install the application.", + "WhatIsNew_MigrationNotification_Title": "Wino Mail Updated", + "WhatIsNew_MigrationNotification_Message": "Open the app to complete the update and see what's new.", + "WelcomeWindow_Title": "Welcome to Wino Mail", + "WelcomeWindow_Subtitle": "A native Windows experience for Mail and Calendar.", + "WelcomeWindow_WhatsNewTitle": "Latest changes", + "WelcomeWindow_FeaturesTitle": "Features", + "WelcomeWindow_WhatsNewTab": "What's New", + "WelcomeWindow_FeaturesTab": "Features", + "WelcomeWindow_GetStartedButton": "Get started by adding an account", + "WelcomeWindow_GetStartedDescription": "Add your Outlook, Gmail, or IMAP account to get started with Wino Mail.", + "WelcomeWindow_SetupTitle": "Set up your account", + "WelcomeWindow_SetupSubtitle": "Choose your email provider to get started", + "WelcomeWindow_AddAccountButton": "Add account", + "WelcomeWindow_SkipForNow": "Skip for now — I'll set it up later", + "WelcomeWindow_AppDescription": "A fast, focused inbox — redesigned for Windows 11", + "WelcomeWizard_Step1Title": "Welcome", + "WelcomeWizard_Step2Title": "Add Account", + "WelcomeWizard_Step3Title": "Finish Setup", + "ProviderSelection_Title": "Choose your email provider", + "ProviderSelection_Subtitle": "Select a provider below to add your email account to Wino Mail.", + "ProviderSelection_AccountNameHeader": "Account Name", + "ProviderSelection_AccountNamePlaceholder": "e.g. Personal, Work", + "ProviderSelection_DisplayNameHeader": "Display Name", + "ProviderSelection_DisplayNamePlaceholder": "e.g. John Doe", + "ProviderSelection_EmailHeader": "E-mail Address", + "ProviderSelection_EmailPlaceholder": "e.g. johndoe@example.com", + "ProviderSelection_AppPasswordHeader": "App-Specific Password", + "ProviderSelection_AppPasswordHelp": "How do I get an app-specific password?", + "ProviderSelection_CalendarModeHeader": "Calendar Integration", + "ProviderSelection_CalendarMode_DisabledTitle": "Disabled", + "ProviderSelection_CalendarMode_DisabledDescription": "No calendar integration", + "ProviderSelection_CalendarMode_CalDavTitle": "CalDAV Synchronization", + "ProviderSelection_CalendarMode_CalDavDescription_Apple": "Your calendar events are synced to Apple servers between your devices.", + "ProviderSelection_CalendarMode_CalDavDescription_Yahoo": "Your calendar events are synced to Yahoo servers between your devices.", + "ProviderSelection_CalendarMode_LocalTitle": "Local calendar", + "ProviderSelection_CalendarMode_LocalDescription": "Your events are stored only on your computer. No server connectivity.", + "ProviderSelection_ClearColor": "Clear color", + "ProviderSelection_ContinueButton": "Continue", + "ProviderSelection_SpecialImap_Subtitle": "Enter your account credentials to connect.", + "AccountSetup_Title": "Setting up your account", + "AccountSetup_Step_Authenticating": "Authenticating with {0}", + "AccountSetup_Step_TestingMailAuth": "Testing mail authentication", + "AccountSetup_Step_SyncingFolders": "Synchronizing folder metadata", + "AccountSetup_Step_FetchingProfile": "Fetching profile information", + "AccountSetup_Step_DiscoveringCalDav": "Discovering CalDAV settings", + "AccountSetup_Step_TestingCalendarAuth": "Testing calendar authentication", + "AccountSetup_Step_SavingAccount": "Saving account information", + "AccountSetup_Step_FetchingCalendarMetadata": "Fetching calendar metadata", + "AccountSetup_Step_SyncingAliases": "Synchronizing aliases", + "AccountSetup_Step_Finalizing": "Finalizing setup", + "AccountSetup_FailureMessage": "Setup failed. Go back to fix your settings, or try again later.", + "AccountSetup_SuccessMessage": "Your account has been set up successfully!", + "AccountSetup_GoBackButton": "Go Back", + "AccountSetup_TryAgainButton": "Try Again", + "ImapCalDavSettings_AutoDiscoveryFailed": "Auto-discovery failed. Please enter settings manually in the Advanced tab." } diff --git a/Wino.Core.Domain/Translator.cs b/Wino.Core.Domain/Translator.cs index 1fc2fb4c..9ada00c6 100644 --- a/Wino.Core.Domain/Translator.cs +++ b/Wino.Core.Domain/Translator.cs @@ -7,4 +7,7 @@ namespace Wino.Core.Domain; /// All translations generated automatically by the source generator. /// [TranslatorGen] -public partial class Translator; +public partial class Translator +{ + public static string GetTranslatedString(string key) => Resources.GetTranslatedString(key); +} diff --git a/Wino.Core.ViewModels/Data/BreadcrumbNavigationItemViewModel.cs b/Wino.Core.ViewModels/Data/BreadcrumbNavigationItemViewModel.cs index 5d808e66..55941039 100644 --- a/Wino.Core.ViewModels/Data/BreadcrumbNavigationItemViewModel.cs +++ b/Wino.Core.ViewModels/Data/BreadcrumbNavigationItemViewModel.cs @@ -11,12 +11,15 @@ public partial class BreadcrumbNavigationItemViewModel : ObservableObject [ObservableProperty] private bool isActive; + public int StepNumber { get; set; } + public BreadcrumbNavigationRequested Request { get; set; } - public BreadcrumbNavigationItemViewModel(BreadcrumbNavigationRequested request, bool isActive) + public BreadcrumbNavigationItemViewModel(BreadcrumbNavigationRequested request, bool isActive, int stepNumber = 0) { Request = request; Title = request.PageTitle; IsActive = isActive; + StepNumber = stepNumber; } } diff --git a/Wino.Core.ViewModels/WelcomeHostPageViewModel.cs b/Wino.Core.ViewModels/WelcomeHostPageViewModel.cs new file mode 100644 index 00000000..5ee5dd40 --- /dev/null +++ b/Wino.Core.ViewModels/WelcomeHostPageViewModel.cs @@ -0,0 +1,13 @@ +using Wino.Core.Domain.Interfaces; + +namespace Wino.Core.ViewModels; + +public class WelcomeHostPageViewModel : CoreBaseViewModel +{ + public WelcomeHostPageViewModel(INavigationService navigationService) + { + NavigationService = navigationService; + } + + public INavigationService NavigationService { get; } +} diff --git a/Wino.Mail.ViewModels/AccountManagementViewModel.cs b/Wino.Mail.ViewModels/AccountManagementViewModel.cs index 63f1e875..50c2d46f 100644 --- a/Wino.Mail.ViewModels/AccountManagementViewModel.cs +++ b/Wino.Mail.ViewModels/AccountManagementViewModel.cs @@ -86,251 +86,11 @@ public partial class AccountManagementViewModel : AccountManagementPageViewModel return; } - MailAccount createdAccount = null; - IAccountCreationDialog creationDialog = null; - bool creationDialogClosed = false; - - try - { - var providers = ProviderService.GetAvailableProviders(); - - // Select provider. - var accountCreationDialogResult = await ExecuteUIThreadTaskAsync(() => MailDialogService.ShowAccountProviderSelectionDialogAsync(providers)); - - if (accountCreationDialogResult != null) - { - CustomServerInformation customServerInformation = null; - - createdAccount = new MailAccount() - { - ProviderType = accountCreationDialogResult.ProviderType, - Name = accountCreationDialogResult.AccountName, - SpecialImapProvider = accountCreationDialogResult.SpecialImapProviderDetails?.SpecialImapProvider ?? SpecialImapProvider.None, - Id = Guid.NewGuid(), - AccountColorHex = accountCreationDialogResult.AccountColorHex, - IsCalendarAccessGranted = true // New accounts have calendar scopes - }; - - if (accountCreationDialogResult.ProviderType == MailProviderType.IMAP4) - { - if (createdAccount.SpecialImapProvider == SpecialImapProvider.iCloud || createdAccount.SpecialImapProvider == SpecialImapProvider.Yahoo) - { - var accountCreationCancellationTokenSource = new CancellationTokenSource(); - creationDialog = MailDialogService.GetAccountCreationDialog(accountCreationDialogResult); - - await ExecuteUIThreadTaskAsync(() => creationDialog.ShowDialogAsync(accountCreationCancellationTokenSource)); - await Task.Delay(500); - - await ExecuteUIThread(() => creationDialog.State = AccountCreationDialogState.SigningIn); - - customServerInformation = _specialImapProviderConfigResolver.GetServerInformation(createdAccount, accountCreationDialogResult) - ?? throw new AccountSetupCanceledException(); - - customServerInformation.Id = Guid.NewGuid(); - customServerInformation.AccountId = createdAccount.Id; - - createdAccount.Address = accountCreationDialogResult.SpecialImapProviderDetails.Address; - createdAccount.SenderName = accountCreationDialogResult.SpecialImapProviderDetails.SenderName; - createdAccount.IsCalendarAccessGranted = customServerInformation.CalendarSupportMode != ImapCalendarSupportMode.Disabled; - createdAccount.ServerInformation = customServerInformation; - - await ValidateSpecialImapConnectivityAsync(customServerInformation).ConfigureAwait(false); - } - else - { - var completionSource = new TaskCompletionSource(); - var setupContext = ImapCalDavSettingsNavigationContext.CreateForCreateMode(accountCreationDialogResult, completionSource); - - await ExecuteUIThread(() => Messenger.Send(new BreadcrumbNavigationRequested( - Translator.ImapCalDavSettingsPage_TitleCreate, - WinoPage.ImapCalDavSettingsPage, - setupContext))); - - var setupResult = await completionSource.Task.ConfigureAwait(false) - ?? throw new AccountSetupCanceledException(); - - customServerInformation = setupResult.ServerInformation ?? throw new AccountSetupCanceledException(); - customServerInformation.Id = Guid.NewGuid(); - customServerInformation.AccountId = createdAccount.Id; - - createdAccount.Address = setupResult.EmailAddress; - createdAccount.SenderName = setupResult.DisplayName; - createdAccount.IsCalendarAccessGranted = setupResult.IsCalendarAccessGranted; - createdAccount.ServerInformation = customServerInformation; - } - } - else - { - var accountCreationCancellationTokenSource = new CancellationTokenSource(); - creationDialog = MailDialogService.GetAccountCreationDialog(accountCreationDialogResult); - - await ExecuteUIThreadTaskAsync(() => creationDialog.ShowDialogAsync(accountCreationCancellationTokenSource)); - await Task.Delay(500); - - await ExecuteUIThread(() => creationDialog.State = AccountCreationDialogState.SigningIn); - - // OAuth authentication is handled here. - // Use SynchronizationManager to handle OAuth authentication. - - var authTokenInfo = await SynchronizationManager.Instance.HandleAuthorizationAsync( - accountCreationDialogResult.ProviderType, - createdAccount, - createdAccount.ProviderType == MailProviderType.Gmail); - - bool creationCanceled = false; - await ExecuteUIThread(() => creationCanceled = creationDialog.State == AccountCreationDialogState.Canceled); - - if (creationCanceled) - throw new AccountSetupCanceledException(); - - // Update account address with authenticated user information - createdAccount.Address = authTokenInfo.AccountAddress; - } - - // Address is still doesn't have a value for API synchronizers. - // It'll be synchronized with profile information. - - await AccountService.CreateAccountAsync(createdAccount, customServerInformation); - - // Local account has been created. - - // Sync profile information if supported. - if (createdAccount.IsProfileInfoSyncSupported) - { - // Start profile information synchronization. - // It's only available for Outlook and Gmail synchronizers. - - var profileSynchronizationResult = await SynchronizationManager.Instance.SynchronizeProfileAsync(createdAccount.Id); - - if (profileSynchronizationResult.CompletedState != SynchronizationCompletedState.Success) - throw new Exception(Translator.Exception_FailedToSynchronizeProfileInformation); - - if (profileSynchronizationResult.ProfileInformation != null) - { - createdAccount.SenderName = profileSynchronizationResult.ProfileInformation.SenderName; - createdAccount.Base64ProfilePictureData = profileSynchronizationResult.ProfileInformation.Base64ProfilePictureData; - - if (!string.IsNullOrEmpty(profileSynchronizationResult.ProfileInformation.AccountAddress)) - { - createdAccount.Address = profileSynchronizationResult.ProfileInformation.AccountAddress; - } - - await AccountService.UpdateProfileInformationAsync(createdAccount.Id, profileSynchronizationResult.ProfileInformation); - } - } - - if (creationDialog != null) - await ExecuteUIThread(() => creationDialog.State = AccountCreationDialogState.PreparingFolders); - - var folderSynchronizationResult = await SynchronizationManager.Instance.SynchronizeFoldersAsync(createdAccount.Id); - - if (folderSynchronizationResult == null || folderSynchronizationResult.CompletedState != SynchronizationCompletedState.Success) - throw new Exception(Translator.Exception_FailedToSynchronizeFolders); - - if (createdAccount.IsCalendarAccessGranted) - { - if (creationDialog != null) - await ExecuteUIThread(() => creationDialog.State = AccountCreationDialogState.CalendarMetadataFetch); - - var calendarMetadataSynchronizationResult = await SynchronizationManager.Instance.SynchronizeCalendarAsync(new CalendarSynchronizationOptions - { - AccountId = createdAccount.Id, - Type = CalendarSynchronizationType.CalendarMetadata - }); - - if (calendarMetadataSynchronizationResult == null || calendarMetadataSynchronizationResult.CompletedState != SynchronizationCompletedState.Success) - throw new Exception(Translator.Exception_FailedToSynchronizeCalendarMetadata); - } - - // Sync aliases if supported. - if (createdAccount.IsAliasSyncSupported) - { - // Try to synchronize aliases for the account. - var aliasSynchronizationResult = await SynchronizationManager.Instance.SynchronizeAliasesAsync(createdAccount.Id); - - if (aliasSynchronizationResult.CompletedState != SynchronizationCompletedState.Success) - throw new Exception(Translator.Exception_FailedToSynchronizeAliases); - } - else - { - // Create root primary alias for the account. - // This is only available for accounts that do not support alias synchronization. - - await AccountService.CreateRootAliasAsync(createdAccount.Id, createdAccount.Address); - } - - if (creationDialog != null) - { - await ExecuteUIThread(() => creationDialog.Complete(false)); - creationDialogClosed = true; - } - - // Send changes to listeners. - await ExecuteUIThread(() => ReportUIChange(new AccountCreatedMessage(createdAccount))); - - // Notify success. - await ExecuteUIThread(() => DialogService.InfoBarMessage(Translator.Info_AccountCreatedTitle, string.Format(Translator.Info_AccountCreatedMessage, createdAccount.Address), InfoBarMessageType.Success)); - } - } - catch (Exception ex) when (ex.Message.Contains(nameof(GmailServiceDisabledException))) - { - // For Google Workspace accounts, Gmail API might be disabled by the admin. - // Wino can't continue synchronization in this case. - // We must notify the user about this and prevent account creation. - - await ExecuteUIThread(() => DialogService.InfoBarMessage(Translator.GmailServiceDisabled_Title, Translator.GmailServiceDisabled_Message, InfoBarMessageType.Error)); - - if (createdAccount != null) - { - await AccountService.DeleteAccountAsync(createdAccount); - } - } - catch (AccountSetupCanceledException) - { - // Ignore - } - catch (Exception ex) when (ex.Message.Contains(nameof(AccountSetupCanceledException))) - { - // Ignore - } - catch (ImapClientPoolException testClientPoolException) when (testClientPoolException.CustomServerInformation != null) - { - var properties = testClientPoolException.CustomServerInformation.GetConnectionProperties(); - - properties.Add("ProtocolLog", testClientPoolException.ProtocolLog); - properties.Add("DiagnosticId", PreferencesService.DiagnosticId); - - _winoLogger.TrackEvent("IMAP Test Failed", properties); - - await ExecuteUIThread(() => DialogService.InfoBarMessage(Translator.Info_AccountCreationFailedTitle, testClientPoolException.Message, InfoBarMessageType.Error)); - } - catch (ImapClientPoolException clientPoolException) when (clientPoolException.InnerException != null) - { - await ExecuteUIThread(() => DialogService.InfoBarMessage(Translator.Info_AccountCreationFailedTitle, clientPoolException.InnerException.Message, InfoBarMessageType.Error)); - } - catch (Exception ex) - { - Log.Error(ex, "Failed to create account."); - - await ExecuteUIThread(() => DialogService.InfoBarMessage(Translator.Info_AccountCreationFailedTitle, ex.Message, InfoBarMessageType.Error)); - - // Delete account in case of failure. - if (createdAccount != null) - { - await AccountService.DeleteAccountAsync(createdAccount); - } - } - finally - { - if (creationDialog != null && !creationDialogClosed) - { - bool isCanceled = false; - await ExecuteUIThread(() => isCanceled = creationDialog.State == AccountCreationDialogState.Canceled); - await ExecuteUIThread(() => creationDialog.Complete(isCanceled)); - } - } + Messenger.Send(new BreadcrumbNavigationRequested(Translator.WelcomeWizard_Step2Title, WinoPage.ProviderSelectionPage)); } + public Task StartAddNewAccountAsync() => AddNewAccountAsync(); + private async Task ValidateSpecialImapConnectivityAsync(CustomServerInformation serverInformation) { var connectivityResult = await SynchronizationManager.Instance diff --git a/Wino.Mail.ViewModels/AccountSetupProgressPageViewModel.cs b/Wino.Mail.ViewModels/AccountSetupProgressPageViewModel.cs new file mode 100644 index 00000000..85423bab --- /dev/null +++ b/Wino.Mail.ViewModels/AccountSetupProgressPageViewModel.cs @@ -0,0 +1,477 @@ +using System; +using System.Collections.ObjectModel; +using System.Threading.Tasks; +using CommunityToolkit.Mvvm.ComponentModel; +using CommunityToolkit.Mvvm.Input; +using CommunityToolkit.Mvvm.Messaging; +using Serilog; +using Wino.Core.Domain; +using Wino.Core.Domain.Entities.Shared; +using Wino.Core.Domain.Enums; +using Wino.Core.Domain.Interfaces; +using Wino.Core.Domain.Models.Accounts; +using Wino.Core.Domain.Models.Calendar; +using Wino.Core.Domain.Exceptions; +using Wino.Core.Domain.Models.Navigation; +using Wino.Core.Domain.Models.Synchronization; +using Wino.Core.Services; +using Wino.Mail.ViewModels.Data; +using Wino.Messaging.Client.Navigation; +using Wino.Messaging.UI; + +namespace Wino.Mail.ViewModels; + +public partial class AccountSetupProgressPageViewModel : MailBaseViewModel +{ + private readonly IAccountService _accountService; + private readonly ISpecialImapProviderConfigResolver _specialImapProviderConfigResolver; + private readonly ICalDavClient _calDavClient; + private readonly IMailDialogService _dialogService; + + public WelcomeWizardContext WizardContext { get; } + + public ObservableCollection Steps { get; } = []; + + [ObservableProperty] + public partial bool IsSetupComplete { get; set; } + + [ObservableProperty] + public partial bool IsSetupFailed { get; set; } + + [ObservableProperty] + public partial string FailureMessage { get; set; } + + private MailAccount _createdAccount; + private bool _dbWritten; + + public AccountSetupProgressPageViewModel( + IAccountService accountService, + ISpecialImapProviderConfigResolver specialImapProviderConfigResolver, + ICalDavClient calDavClient, + IMailDialogService dialogService, + WelcomeWizardContext wizardContext) + { + _accountService = accountService; + _specialImapProviderConfigResolver = specialImapProviderConfigResolver; + _calDavClient = calDavClient; + _dialogService = dialogService; + WizardContext = wizardContext; + } + + public override async void OnNavigatedTo(NavigationMode mode, object parameters) + { + base.OnNavigatedTo(mode, parameters); + + // Only run on fresh navigation, not on back-navigation + if (mode == NavigationMode.Back) return; + + await RunSetupAsync(); + } + + private void BuildSteps() + { + Steps.Clear(); + + if (WizardContext.IsOAuthProvider) + { + Steps.Add(new AccountSetupStepModel + { + Title = string.Format(Translator.AccountSetup_Step_Authenticating, WizardContext.SelectedProvider.Name) + }); + Steps.Add(new AccountSetupStepModel { Title = Translator.AccountSetup_Step_FetchingProfile }); + Steps.Add(new AccountSetupStepModel { Title = Translator.AccountSetup_Step_SavingAccount }); + Steps.Add(new AccountSetupStepModel { Title = Translator.AccountSetup_Step_SyncingFolders }); + Steps.Add(new AccountSetupStepModel { Title = Translator.AccountSetup_Step_FetchingCalendarMetadata }); + Steps.Add(new AccountSetupStepModel { Title = Translator.AccountSetup_Step_SyncingAliases }); + Steps.Add(new AccountSetupStepModel { Title = Translator.AccountSetup_Step_Finalizing }); + } + else if (WizardContext.IsSpecialImapProvider) + { + Steps.Add(new AccountSetupStepModel { Title = Translator.AccountSetup_Step_TestingMailAuth }); + + if (WizardContext.CalendarSupportMode == ImapCalendarSupportMode.CalDav) + { + Steps.Add(new AccountSetupStepModel { Title = Translator.AccountSetup_Step_DiscoveringCalDav }); + Steps.Add(new AccountSetupStepModel { Title = Translator.AccountSetup_Step_TestingCalendarAuth }); + } + + Steps.Add(new AccountSetupStepModel { Title = Translator.AccountSetup_Step_SavingAccount }); + Steps.Add(new AccountSetupStepModel { Title = Translator.AccountSetup_Step_SyncingFolders }); + + if (WizardContext.CalendarSupportMode != ImapCalendarSupportMode.Disabled) + { + Steps.Add(new AccountSetupStepModel { Title = Translator.AccountSetup_Step_FetchingCalendarMetadata }); + } + + Steps.Add(new AccountSetupStepModel { Title = Translator.AccountSetup_Step_Finalizing }); + } + else // Generic IMAP + { + Steps.Add(new AccountSetupStepModel { Title = Translator.AccountSetup_Step_SavingAccount }); + Steps.Add(new AccountSetupStepModel { Title = Translator.AccountSetup_Step_SyncingFolders }); + + var setupResult = WizardContext.ImapCalDavSetupResult; + if (setupResult?.IsCalendarAccessGranted == true && + setupResult.ServerInformation?.CalendarSupportMode == ImapCalendarSupportMode.CalDav) + { + Steps.Add(new AccountSetupStepModel { Title = Translator.AccountSetup_Step_DiscoveringCalDav }); + Steps.Add(new AccountSetupStepModel { Title = Translator.AccountSetup_Step_TestingCalendarAuth }); + } + + if (setupResult?.IsCalendarAccessGranted == true) + { + Steps.Add(new AccountSetupStepModel { Title = Translator.AccountSetup_Step_FetchingCalendarMetadata }); + } + + Steps.Add(new AccountSetupStepModel { Title = Translator.AccountSetup_Step_Finalizing }); + } + } + + private int _currentStepIndex; + + private void SetStepInProgress(string title) + { + for (int i = 0; i < Steps.Count; i++) + { + if (Steps[i].Title == title) + { + _currentStepIndex = i; + Steps[i].Status = AccountSetupStepStatus.InProgress; + return; + } + } + } + + private void SetCurrentStepSucceeded() + { + if (_currentStepIndex < Steps.Count) + Steps[_currentStepIndex].Status = AccountSetupStepStatus.Succeeded; + } + + private void SetCurrentStepFailed(string errorMessage) + { + if (_currentStepIndex < Steps.Count) + { + Steps[_currentStepIndex].Status = AccountSetupStepStatus.Failed; + Steps[_currentStepIndex].ErrorMessage = errorMessage; + } + } + + private async Task RunSetupAsync() + { + IsSetupComplete = false; + IsSetupFailed = false; + FailureMessage = null; + _dbWritten = false; + _createdAccount = null; + + BuildSteps(); + + try + { + CustomServerInformation customServerInformation = null; + + // Build account in memory + _createdAccount = new MailAccount + { + Id = Guid.NewGuid(), + ProviderType = WizardContext.SelectedProvider.Type, + Name = WizardContext.AccountName, + SpecialImapProvider = WizardContext.SelectedProvider.SpecialImapProvider, + AccountColorHex = WizardContext.AccountColorHex, + IsCalendarAccessGranted = true + }; + + if (WizardContext.IsOAuthProvider) + { + // Step: Authenticating + SetStepInProgress(string.Format(Translator.AccountSetup_Step_Authenticating, WizardContext.SelectedProvider.Name)); + + var authTokenInfo = await SynchronizationManager.Instance.HandleAuthorizationAsync( + WizardContext.SelectedProvider.Type, + _createdAccount, + _createdAccount.ProviderType == MailProviderType.Gmail); + + _createdAccount.Address = authTokenInfo.AccountAddress; + SetCurrentStepSucceeded(); + + // Step: Save to DB + SetStepInProgress(Translator.AccountSetup_Step_SavingAccount); + await _accountService.CreateAccountAsync(_createdAccount, null); + _dbWritten = true; + SetCurrentStepSucceeded(); + + // Step: Profile + SetStepInProgress(Translator.AccountSetup_Step_FetchingProfile); + var profileResult = await SynchronizationManager.Instance.SynchronizeProfileAsync(_createdAccount.Id); + if (profileResult.CompletedState != SynchronizationCompletedState.Success) + throw new Exception(Translator.Exception_FailedToSynchronizeProfileInformation); + + if (profileResult.ProfileInformation != null) + { + _createdAccount.SenderName = profileResult.ProfileInformation.SenderName; + _createdAccount.Base64ProfilePictureData = profileResult.ProfileInformation.Base64ProfilePictureData; + + if (!string.IsNullOrEmpty(profileResult.ProfileInformation.AccountAddress)) + _createdAccount.Address = profileResult.ProfileInformation.AccountAddress; + + await _accountService.UpdateProfileInformationAsync(_createdAccount.Id, profileResult.ProfileInformation); + } + SetCurrentStepSucceeded(); + + // Step: Folders + SetStepInProgress(Translator.AccountSetup_Step_SyncingFolders); + var folderResult = await SynchronizationManager.Instance.SynchronizeFoldersAsync(_createdAccount.Id); + if (folderResult == null || folderResult.CompletedState != SynchronizationCompletedState.Success) + throw new Exception(Translator.Exception_FailedToSynchronizeFolders); + SetCurrentStepSucceeded(); + + // Step: Calendar metadata + SetStepInProgress(Translator.AccountSetup_Step_FetchingCalendarMetadata); + if (_createdAccount.IsCalendarAccessGranted) + { + var calResult = await SynchronizationManager.Instance.SynchronizeCalendarAsync(new CalendarSynchronizationOptions + { + AccountId = _createdAccount.Id, + Type = CalendarSynchronizationType.CalendarMetadata + }); + if (calResult == null || calResult.CompletedState != SynchronizationCompletedState.Success) + throw new Exception(Translator.Exception_FailedToSynchronizeCalendarMetadata); + } + SetCurrentStepSucceeded(); + + // Step: Aliases + SetStepInProgress(Translator.AccountSetup_Step_SyncingAliases); + if (_createdAccount.IsAliasSyncSupported) + { + var aliasResult = await SynchronizationManager.Instance.SynchronizeAliasesAsync(_createdAccount.Id); + if (aliasResult.CompletedState != SynchronizationCompletedState.Success) + throw new Exception(Translator.Exception_FailedToSynchronizeAliases); + } + else + { + await _accountService.CreateRootAliasAsync(_createdAccount.Id, _createdAccount.Address); + } + SetCurrentStepSucceeded(); + } + else if (WizardContext.IsSpecialImapProvider) + { + var dialogResult = WizardContext.BuildAccountCreationDialogResult(); + + customServerInformation = _specialImapProviderConfigResolver.GetServerInformation(_createdAccount, dialogResult); + if (customServerInformation == null) throw new Exception("Failed to resolve server information."); + + customServerInformation.Id = Guid.NewGuid(); + customServerInformation.AccountId = _createdAccount.Id; + + _createdAccount.Address = WizardContext.EmailAddress; + _createdAccount.SenderName = WizardContext.DisplayName; + _createdAccount.IsCalendarAccessGranted = customServerInformation.CalendarSupportMode != ImapCalendarSupportMode.Disabled; + _createdAccount.ServerInformation = customServerInformation; + + // Step: Test IMAP + SetStepInProgress(Translator.AccountSetup_Step_TestingMailAuth); + await ValidateImapConnectivityAsync(customServerInformation); + SetCurrentStepSucceeded(); + + // Step: CalDAV discovery and testing (if applicable) + if (customServerInformation.CalendarSupportMode == ImapCalendarSupportMode.CalDav) + { + SetStepInProgress(Translator.AccountSetup_Step_DiscoveringCalDav); + SetCurrentStepSucceeded(); + + SetStepInProgress(Translator.AccountSetup_Step_TestingCalendarAuth); + await ValidateCalDavConnectivityAsync(customServerInformation); + SetCurrentStepSucceeded(); + } + + // Step: Save to DB + SetStepInProgress(Translator.AccountSetup_Step_SavingAccount); + await _accountService.CreateAccountAsync(_createdAccount, customServerInformation); + _dbWritten = true; + SetCurrentStepSucceeded(); + + // Step: Folders + SetStepInProgress(Translator.AccountSetup_Step_SyncingFolders); + var folderResult = await SynchronizationManager.Instance.SynchronizeFoldersAsync(_createdAccount.Id); + if (folderResult == null || folderResult.CompletedState != SynchronizationCompletedState.Success) + throw new Exception(Translator.Exception_FailedToSynchronizeFolders); + SetCurrentStepSucceeded(); + + // Step: Calendar metadata (if not disabled) + if (_createdAccount.IsCalendarAccessGranted) + { + SetStepInProgress(Translator.AccountSetup_Step_FetchingCalendarMetadata); + var calResult = await SynchronizationManager.Instance.SynchronizeCalendarAsync(new CalendarSynchronizationOptions + { + AccountId = _createdAccount.Id, + Type = CalendarSynchronizationType.CalendarMetadata + }); + if (calResult == null || calResult.CompletedState != SynchronizationCompletedState.Success) + throw new Exception(Translator.Exception_FailedToSynchronizeCalendarMetadata); + SetCurrentStepSucceeded(); + } + + // Aliases for IMAP + await _accountService.CreateRootAliasAsync(_createdAccount.Id, _createdAccount.Address); + } + else // Generic IMAP + { + var setupResult = WizardContext.ImapCalDavSetupResult + ?? throw new Exception("IMAP setup was not completed."); + + customServerInformation = setupResult.ServerInformation + ?? throw new Exception("Server information is missing."); + + customServerInformation.Id = Guid.NewGuid(); + customServerInformation.AccountId = _createdAccount.Id; + + _createdAccount.Address = setupResult.EmailAddress; + _createdAccount.SenderName = setupResult.DisplayName; + _createdAccount.IsCalendarAccessGranted = setupResult.IsCalendarAccessGranted; + _createdAccount.ServerInformation = customServerInformation; + + // Step: Save to DB + SetStepInProgress(Translator.AccountSetup_Step_SavingAccount); + await _accountService.CreateAccountAsync(_createdAccount, customServerInformation); + _dbWritten = true; + SetCurrentStepSucceeded(); + + // Step: Folders + SetStepInProgress(Translator.AccountSetup_Step_SyncingFolders); + var folderResult = await SynchronizationManager.Instance.SynchronizeFoldersAsync(_createdAccount.Id); + if (folderResult == null || folderResult.CompletedState != SynchronizationCompletedState.Success) + throw new Exception(Translator.Exception_FailedToSynchronizeFolders); + SetCurrentStepSucceeded(); + + // Step: CalDAV (if applicable) + if (setupResult.IsCalendarAccessGranted && + customServerInformation.CalendarSupportMode == ImapCalendarSupportMode.CalDav) + { + SetStepInProgress(Translator.AccountSetup_Step_DiscoveringCalDav); + SetCurrentStepSucceeded(); + + SetStepInProgress(Translator.AccountSetup_Step_TestingCalendarAuth); + await ValidateCalDavConnectivityAsync(customServerInformation); + SetCurrentStepSucceeded(); + } + + // Step: Calendar metadata + if (setupResult.IsCalendarAccessGranted) + { + SetStepInProgress(Translator.AccountSetup_Step_FetchingCalendarMetadata); + var calResult = await SynchronizationManager.Instance.SynchronizeCalendarAsync(new CalendarSynchronizationOptions + { + AccountId = _createdAccount.Id, + Type = CalendarSynchronizationType.CalendarMetadata + }); + if (calResult == null || calResult.CompletedState != SynchronizationCompletedState.Success) + throw new Exception(Translator.Exception_FailedToSynchronizeCalendarMetadata); + SetCurrentStepSucceeded(); + } + + // Aliases for IMAP + await _accountService.CreateRootAliasAsync(_createdAccount.Id, _createdAccount.Address); + } + + // Step: Finalizing + SetStepInProgress(Translator.AccountSetup_Step_Finalizing); + SetCurrentStepSucceeded(); + + IsSetupComplete = true; + + // Notify listeners — this triggers ShellWindow creation from App.xaml.cs + Messenger.Send(new AccountCreatedMessage(_createdAccount)); + } + catch (AccountSetupCanceledException) + { + // User canceled authentication — go back silently, no error UI + Messenger.Send(new BackBreadcrumNavigationRequested(NavigationTransitionEffect.FromLeft)); + } + catch (Exception ex) when (ex.Message.Contains(nameof(AccountSetupCanceledException))) + { + // Wrapped cancellation — same silent behavior + Messenger.Send(new BackBreadcrumNavigationRequested(NavigationTransitionEffect.FromLeft)); + } + catch (Exception ex) + { + Log.Error(ex, "Account setup failed."); + + SetCurrentStepFailed(ex.Message); + IsSetupFailed = true; + FailureMessage = Translator.AccountSetup_FailureMessage; + + // Rollback if DB write happened + if (_dbWritten && _createdAccount != null) + { + try + { + await _accountService.DeleteAccountAsync(_createdAccount); + } + catch (Exception deleteEx) + { + Log.Error(deleteEx, "Failed to rollback account creation."); + } + + _dbWritten = false; + } + } + } + + private async Task ValidateImapConnectivityAsync(CustomServerInformation serverInformation) + { + var connectivityResult = await SynchronizationManager.Instance + .TestImapConnectivityAsync(serverInformation, allowSSLHandshake: false); + + if (connectivityResult.IsCertificateUIRequired) + { + var certificateMessage = + $"{Translator.IMAPSetupDialog_CertificateAllowanceRequired_Row0}\n\n" + + $"{Translator.IMAPSetupDialog_CertificateIssuer}: {connectivityResult.CertificateIssuer}\n" + + $"{Translator.IMAPSetupDialog_CertificateValidFrom}: {connectivityResult.CertificateValidFromDateString}\n" + + $"{Translator.IMAPSetupDialog_CertificateValidTo}: {connectivityResult.CertificateExpirationDateString}\n\n" + + $"{Translator.IMAPSetupDialog_CertificateAllowanceRequired_Row1}"; + + var allowCertificate = await _dialogService.ShowConfirmationDialogAsync( + certificateMessage, + Translator.GeneralTitle_Warning, + Translator.Buttons_Allow); + + if (!allowCertificate) + throw new InvalidOperationException(Translator.IMAPSetupDialog_CertificateDenied); + + connectivityResult = await SynchronizationManager.Instance + .TestImapConnectivityAsync(serverInformation, allowSSLHandshake: true); + } + + if (!connectivityResult.IsSuccess) + throw new InvalidOperationException(connectivityResult.FailedReason ?? Translator.IMAPSetupDialog_ConnectionFailedMessage); + } + + private async Task ValidateCalDavConnectivityAsync(CustomServerInformation serverInformation) + { + if (string.IsNullOrWhiteSpace(serverInformation.CalDavServiceUrl)) + throw new InvalidOperationException(Translator.ImapCalDavSettingsPage_CalDavUrlRequired); + + var settings = new CalDavConnectionSettings + { + ServiceUri = new Uri(serverInformation.CalDavServiceUrl, UriKind.Absolute), + Username = serverInformation.CalDavUsername, + Password = serverInformation.CalDavPassword + }; + + await _calDavClient.DiscoverCalendarsAsync(settings); + } + + [RelayCommand] + private void GoBack() + { + Messenger.Send(new BackBreadcrumNavigationRequested(NavigationTransitionEffect.FromLeft)); + } + + [RelayCommand] + private async Task TryAgainAsync() + { + await RunSetupAsync(); + } +} diff --git a/Wino.Mail.ViewModels/Data/ImapCalDavSettingsNavigationContext.cs b/Wino.Mail.ViewModels/Data/ImapCalDavSettingsNavigationContext.cs index b5a1372d..8a1bce39 100644 --- a/Wino.Mail.ViewModels/Data/ImapCalDavSettingsNavigationContext.cs +++ b/Wino.Mail.ViewModels/Data/ImapCalDavSettingsNavigationContext.cs @@ -9,7 +9,8 @@ namespace Wino.Mail.ViewModels.Data; public enum ImapCalDavSettingsPageMode { Create, - Edit + Edit, + Wizard } public sealed class ImapCalDavSettingsNavigationContext @@ -35,6 +36,16 @@ public sealed class ImapCalDavSettingsNavigationContext Mode = ImapCalDavSettingsPageMode.Edit, AccountId = accountId }; + + public static ImapCalDavSettingsNavigationContext CreateForWizardMode( + AccountCreationDialogResult accountCreationDialogResult) + => new() + { + Mode = ImapCalDavSettingsPageMode.Wizard, + AccountCreationDialogResult = accountCreationDialogResult + }; + + public bool IsWizardMode => Mode == ImapCalDavSettingsPageMode.Wizard; } public sealed class ImapCalDavSetupResult diff --git a/Wino.Mail.ViewModels/Data/WelcomeWizardContext.cs b/Wino.Mail.ViewModels/Data/WelcomeWizardContext.cs new file mode 100644 index 00000000..fe38bd23 --- /dev/null +++ b/Wino.Mail.ViewModels/Data/WelcomeWizardContext.cs @@ -0,0 +1,79 @@ +using CommunityToolkit.Mvvm.ComponentModel; +using Wino.Core.Domain.Entities.Shared; +using Wino.Core.Domain.Enums; +using Wino.Core.Domain.Interfaces; +using Wino.Core.Domain.Models.Accounts; + +namespace Wino.Mail.ViewModels.Data; + +public partial class WelcomeWizardContext : ObservableObject +{ + // Step 2 — Provider selection + [ObservableProperty] + public partial IProviderDetail SelectedProvider { get; set; } + + [ObservableProperty] + public partial string AccountName { get; set; } + + [ObservableProperty] + public partial string AccountColorHex { get; set; } + + // Special IMAP fields (iCloud/Yahoo) + [ObservableProperty] + public partial string DisplayName { get; set; } + + [ObservableProperty] + public partial string EmailAddress { get; set; } + + [ObservableProperty] + public partial string AppSpecificPassword { get; set; } + + [ObservableProperty] + public partial ImapCalendarSupportMode CalendarSupportMode { get; set; } = ImapCalendarSupportMode.Disabled; + + // Generic IMAP — populated by ImapCalDavSettingsPage + public ImapCalDavSetupResult ImapCalDavSetupResult { get; set; } + + // Computed helpers + public bool IsOAuthProvider => SelectedProvider?.Type is MailProviderType.Outlook or MailProviderType.Gmail; + + public bool IsSpecialImapProvider => + SelectedProvider?.SpecialImapProvider is SpecialImapProvider.iCloud or SpecialImapProvider.Yahoo; + + public bool IsGenericImap => + SelectedProvider?.Type == MailProviderType.IMAP4 + && SelectedProvider?.SpecialImapProvider == SpecialImapProvider.None; + + public SpecialImapProviderDetails BuildSpecialImapProviderDetails() + { + if (!IsSpecialImapProvider) return null; + + return new SpecialImapProviderDetails( + EmailAddress, + AppSpecificPassword, + DisplayName, + SelectedProvider.SpecialImapProvider, + CalendarSupportMode); + } + + public AccountCreationDialogResult BuildAccountCreationDialogResult() + { + return new AccountCreationDialogResult( + SelectedProvider.Type, + AccountName, + BuildSpecialImapProviderDetails(), + AccountColorHex); + } + + public void Reset() + { + SelectedProvider = null; + AccountName = null; + AccountColorHex = null; + DisplayName = null; + EmailAddress = null; + AppSpecificPassword = null; + CalendarSupportMode = ImapCalendarSupportMode.Disabled; + ImapCalDavSetupResult = null; + } +} diff --git a/Wino.Mail.ViewModels/ImapCalDavSettingsPageViewModel.cs b/Wino.Mail.ViewModels/ImapCalDavSettingsPageViewModel.cs index 97d52026..f1409956 100644 --- a/Wino.Mail.ViewModels/ImapCalDavSettingsPageViewModel.cs +++ b/Wino.Mail.ViewModels/ImapCalDavSettingsPageViewModel.cs @@ -25,6 +25,7 @@ public partial class ImapCalDavSettingsPageViewModel : MailBaseViewModel private readonly ICalDavClient _calDavClient; private readonly IAccountService _accountService; private readonly IMailDialogService _mailDialogService; + private readonly WelcomeWizardContext _wizardContext; private ImapCalDavSettingsPageMode _pageMode; private Guid _editingAccountId; @@ -256,12 +257,14 @@ public partial class ImapCalDavSettingsPageViewModel : MailBaseViewModel public ImapCalDavSettingsPageViewModel(IAutoDiscoveryService autoDiscoveryService, ICalDavClient calDavClient, IAccountService accountService, - IMailDialogService mailDialogService) + IMailDialogService mailDialogService, + WelcomeWizardContext wizardContext) { _autoDiscoveryService = autoDiscoveryService; _calDavClient = calDavClient; _accountService = accountService; _mailDialogService = mailDialogService; + _wizardContext = wizardContext; } public override async void OnNavigatedTo(NavigationMode mode, object parameters) @@ -278,7 +281,7 @@ public partial class ImapCalDavSettingsPageViewModel : MailBaseViewModel _localOnlyInfoShown = false; SelectedSetupTabIndex = 0; - if (_pageMode == ImapCalDavSettingsPageMode.Create) + if (_pageMode == ImapCalDavSettingsPageMode.Create || _pageMode == ImapCalDavSettingsPageMode.Wizard) { PageTitle = Translator.ImapCalDavSettingsPage_TitleCreate; ApplyCreateContextDefaults(context.AccountCreationDialogResult); @@ -301,6 +304,8 @@ public partial class ImapCalDavSettingsPageViewModel : MailBaseViewModel base.OnNavigatedFrom(mode, parameters); } + public bool IsWizardMode => _pageMode == ImapCalDavSettingsPageMode.Wizard; + [RelayCommand] private async Task AutoDiscoverSettingsAsync() { @@ -407,6 +412,12 @@ public partial class ImapCalDavSettingsPageViewModel : MailBaseViewModel IsCalDavValidationSucceeded = false; } + if (_pageMode == ImapCalDavSettingsPageMode.Wizard) + { + CompleteWizardFlow(serverInformation); + return; + } + if (_pageMode == ImapCalDavSettingsPageMode.Create) { CompleteCreateFlow(serverInformation); @@ -436,6 +447,22 @@ public partial class ImapCalDavSettingsPageViewModel : MailBaseViewModel Messenger.Send(new BackBreadcrumNavigationRequested()); } + private void CompleteWizardFlow(CustomServerInformation serverInformation) + { + serverInformation.Id = Guid.NewGuid(); + serverInformation.AccountId = Guid.Empty; + + _wizardContext.ImapCalDavSetupResult = new ImapCalDavSetupResult + { + DisplayName = DisplayName.Trim(), + EmailAddress = EmailAddress.Trim(), + IsCalendarAccessGranted = serverInformation.CalendarSupportMode != ImapCalendarSupportMode.Disabled, + ServerInformation = serverInformation + }; + + Messenger.Send(new BreadcrumbNavigationRequested(Translator.WelcomeWizard_Step3Title, WinoPage.AccountSetupProgressPage)); + } + [RelayCommand] private Task ShowLocalCalendarExplanationAsync() => _mailDialogService.ShowMessageAsync( diff --git a/Wino.Mail.ViewModels/MailAppShellViewModel.cs b/Wino.Mail.ViewModels/MailAppShellViewModel.cs index 2aa65413..9848c150 100644 --- a/Wino.Mail.ViewModels/MailAppShellViewModel.cs +++ b/Wino.Mail.ViewModels/MailAppShellViewModel.cs @@ -78,6 +78,7 @@ public partial class MailAppShellViewModel : MailBaseViewModel, private readonly IMailDialogService _dialogService; private readonly IMimeFileService _mimeFileService; private readonly IWebView2RuntimeValidatorService _webView2RuntimeValidatorService; + private readonly IUpdateManager _updateManager; private readonly INativeAppService _nativeAppService; private readonly IMailService _mailService; @@ -100,7 +101,8 @@ public partial class MailAppShellViewModel : MailBaseViewModel, IStatePersistanceService statePersistanceService, IConfigurationService configurationService, IStartupBehaviorService startupBehaviorService, - IWebView2RuntimeValidatorService webView2RuntimeValidatorService) + IWebView2RuntimeValidatorService webView2RuntimeValidatorService, + IUpdateManager updateManager) { StatePersistenceService = statePersistanceService; @@ -121,6 +123,7 @@ public partial class MailAppShellViewModel : MailBaseViewModel, _notificationBuilder = notificationBuilder; _winoRequestDelegator = winoRequestDelegator; _webView2RuntimeValidatorService = webView2RuntimeValidatorService; + _updateManager = updateManager; } protected override void OnDispatcherAssigned() @@ -251,6 +254,7 @@ public partial class MailAppShellViewModel : MailBaseViewModel, await ForceAllAccountSynchronizationsAsync(); } + await ShowWhatIsNewIfNeededAsync(); await MakeSureEnableStartupLaunchAsync(); } @@ -264,6 +268,19 @@ public partial class MailAppShellViewModel : MailBaseViewModel, } } + private async Task ShowWhatIsNewIfNeededAsync() + { + if (!_updateManager.ShouldShowUpdateNotes()) + return; + + var notes = await _updateManager.GetLatestUpdateNotesAsync(); + + if (notes.Sections.Count == 0) + return; + + await _dialogService.ShowWhatIsNewDialogAsync(notes); + } + private async Task MakeSureEnableStartupLaunchAsync() { if (!_configurationService.Get(IsActivateStartupLaunchAskedKey, false)) diff --git a/Wino.Mail.ViewModels/ProviderSelectionPageViewModel.cs b/Wino.Mail.ViewModels/ProviderSelectionPageViewModel.cs new file mode 100644 index 00000000..c5480a68 --- /dev/null +++ b/Wino.Mail.ViewModels/ProviderSelectionPageViewModel.cs @@ -0,0 +1,122 @@ +using System.Collections.Generic; +using System.Linq; +using CommunityToolkit.Mvvm.ComponentModel; +using CommunityToolkit.Mvvm.Input; +using CommunityToolkit.Mvvm.Messaging; +using Wino.Core.Domain; +using Wino.Core.Domain.Enums; +using Wino.Core.Domain.Interfaces; +using Wino.Core.Domain.Models.Navigation; +using Wino.Core.ViewModels.Data; +using Wino.Mail.ViewModels.Data; +using Wino.Messaging.Client.Navigation; + +namespace Wino.Mail.ViewModels; + +public partial class ProviderSelectionPageViewModel : MailBaseViewModel +{ + private readonly IProviderService _providerService; + private readonly INewThemeService _themeService; + + public WelcomeWizardContext WizardContext { get; } + + public List Providers { get; private set; } = []; + public List AvailableColors { get; private set; } = []; + + [ObservableProperty] + public partial IProviderDetail SelectedProvider { get; set; } + + [ObservableProperty] + public partial AppColorViewModel SelectedColor { get; set; } + + [ObservableProperty] + public partial string AccountName { get; set; } + + [ObservableProperty] + public partial bool CanProceed { get; set; } + + public bool IsColorSelected => SelectedColor != null; + + public ProviderSelectionPageViewModel( + IProviderService providerService, + INewThemeService themeService, + WelcomeWizardContext wizardContext) + { + _providerService = providerService; + _themeService = themeService; + WizardContext = wizardContext; + } + + public override void OnNavigatedTo(NavigationMode mode, object parameters) + { + base.OnNavigatedTo(mode, parameters); + + Providers = _providerService.GetAvailableProviders(); + AvailableColors = _themeService.GetAvailableAccountColors() + .Select(hex => new AppColorViewModel(hex)) + .ToList(); + + // Restore from wizard context if navigating back + if (WizardContext.SelectedProvider != null) + { + SelectedProvider = Providers.FirstOrDefault(p => + p.Type == WizardContext.SelectedProvider.Type && + p.SpecialImapProvider == WizardContext.SelectedProvider.SpecialImapProvider); + AccountName = WizardContext.AccountName; + + if (WizardContext.AccountColorHex != null) + SelectedColor = AvailableColors.FirstOrDefault(c => c.Hex == WizardContext.AccountColorHex); + } + + Validate(); + } + + partial void OnSelectedProviderChanged(IProviderDetail value) => Validate(); + partial void OnAccountNameChanged(string value) => Validate(); + partial void OnSelectedColorChanged(AppColorViewModel value) => OnPropertyChanged(nameof(IsColorSelected)); + + [RelayCommand] + private void ClearColor() => SelectedColor = null; + + private void Validate() + { + CanProceed = SelectedProvider != null && !string.IsNullOrWhiteSpace(AccountName); + } + + [RelayCommand] + private void Proceed() + { + if (!CanProceed) return; + + // Persist to wizard context + WizardContext.SelectedProvider = SelectedProvider; + WizardContext.AccountName = AccountName?.Trim(); + WizardContext.AccountColorHex = SelectedColor?.Hex ?? string.Empty; + + if (WizardContext.IsGenericImap) + { + // Navigate to ImapCalDavSettingsPage in wizard mode + var context = ImapCalDavSettingsNavigationContext.CreateForWizardMode( + WizardContext.BuildAccountCreationDialogResult()); + + Messenger.Send(new BreadcrumbNavigationRequested( + Translator.ImapCalDavSettingsPage_TitleCreate, + WinoPage.ImapCalDavSettingsPage, + context)); + } + else if (SelectedProvider.SpecialImapProvider is SpecialImapProvider.iCloud or SpecialImapProvider.Yahoo) + { + // Navigate to credentials page for special IMAP providers + Messenger.Send(new BreadcrumbNavigationRequested( + SelectedProvider.Name, + WinoPage.SpecialImapCredentialsPage)); + } + else + { + // OAuth — go directly to progress page + Messenger.Send(new BreadcrumbNavigationRequested( + Translator.WelcomeWizard_Step3Title, + WinoPage.AccountSetupProgressPage)); + } + } +} diff --git a/Wino.Mail.ViewModels/SpecialImapCredentialsPageViewModel.cs b/Wino.Mail.ViewModels/SpecialImapCredentialsPageViewModel.cs new file mode 100644 index 00000000..9ba42445 --- /dev/null +++ b/Wino.Mail.ViewModels/SpecialImapCredentialsPageViewModel.cs @@ -0,0 +1,127 @@ +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using CommunityToolkit.Mvvm.ComponentModel; +using CommunityToolkit.Mvvm.Input; +using CommunityToolkit.Mvvm.Messaging; +using Wino.Core.Domain; +using Wino.Core.Domain.Enums; +using Wino.Core.Domain.Interfaces; +using Wino.Core.Domain.Models.Navigation; +using Wino.Mail.ViewModels.Data; +using Wino.Messaging.Client.Navigation; + +namespace Wino.Mail.ViewModels; + +public partial class SpecialImapCredentialsPageViewModel : MailBaseViewModel +{ + private static readonly Dictionary AppPasswordHelpLinks = new() + { + { SpecialImapProvider.iCloud, "https://support.apple.com/en-us/102654" }, + { SpecialImapProvider.Yahoo, "http://help.yahoo.com/kb/SLN15241.html" }, + }; + + private readonly INativeAppService _nativeAppService; + + public WelcomeWizardContext WizardContext { get; } + + [ObservableProperty] + public partial string DisplayName { get; set; } + + [ObservableProperty] + public partial string EmailAddress { get; set; } + + [ObservableProperty] + public partial string AppSpecificPassword { get; set; } + + [ObservableProperty] + public partial int SelectedCalendarModeIndex { get; set; } + + [ObservableProperty] + public partial bool CanProceed { get; set; } + + public string AppPasswordHelpUrl + { + get + { + if (WizardContext.SelectedProvider == null) return null; + AppPasswordHelpLinks.TryGetValue(WizardContext.SelectedProvider.SpecialImapProvider, out var url); + return url; + } + } + + public string CalendarModeCalDavDescription + => WizardContext.SelectedProvider?.SpecialImapProvider == SpecialImapProvider.iCloud + ? Translator.ProviderSelection_CalendarMode_CalDavDescription_Apple + : Translator.ProviderSelection_CalendarMode_CalDavDescription_Yahoo; + + public SpecialImapCredentialsPageViewModel( + INativeAppService nativeAppService, + WelcomeWizardContext wizardContext) + { + _nativeAppService = nativeAppService; + WizardContext = wizardContext; + } + + public override void OnNavigatedTo(NavigationMode mode, object parameters) + { + base.OnNavigatedTo(mode, parameters); + + // Restore from context when navigating back + DisplayName = WizardContext.DisplayName; + EmailAddress = WizardContext.EmailAddress; + AppSpecificPassword = WizardContext.AppSpecificPassword; + + SelectedCalendarModeIndex = WizardContext.CalendarSupportMode switch + { + ImapCalendarSupportMode.CalDav => 1, + ImapCalendarSupportMode.LocalOnly => 2, + _ => 0 + }; + + OnPropertyChanged(nameof(AppPasswordHelpUrl)); + OnPropertyChanged(nameof(CalendarModeCalDavDescription)); + + Validate(); + } + + partial void OnDisplayNameChanged(string value) => Validate(); + partial void OnEmailAddressChanged(string value) => Validate(); + partial void OnAppSpecificPasswordChanged(string value) => Validate(); + + private void Validate() + { + CanProceed = !string.IsNullOrWhiteSpace(DisplayName) + && !string.IsNullOrWhiteSpace(EmailAddress) + && EmailValidation.EmailValidator.Validate(EmailAddress ?? string.Empty) + && !string.IsNullOrWhiteSpace(AppSpecificPassword); + } + + [RelayCommand] + private void Proceed() + { + if (!CanProceed) return; + + WizardContext.DisplayName = DisplayName?.Trim(); + WizardContext.EmailAddress = EmailAddress?.Trim(); + WizardContext.AppSpecificPassword = AppSpecificPassword?.Trim(); + WizardContext.CalendarSupportMode = SelectedCalendarModeIndex switch + { + 1 => ImapCalendarSupportMode.CalDav, + 2 => ImapCalendarSupportMode.LocalOnly, + _ => ImapCalendarSupportMode.Disabled + }; + + Messenger.Send(new BreadcrumbNavigationRequested( + Translator.WelcomeWizard_Step3Title, + WinoPage.AccountSetupProgressPage)); + } + + [RelayCommand] + private async Task OpenAppPasswordHelp() + { + var url = AppPasswordHelpUrl; + if (url != null) + await _nativeAppService.LaunchUriAsync(new Uri(url)); + } +} diff --git a/Wino.Mail.ViewModels/WelcomePageV2ViewModel.cs b/Wino.Mail.ViewModels/WelcomePageV2ViewModel.cs new file mode 100644 index 00000000..cb190e8b --- /dev/null +++ b/Wino.Mail.ViewModels/WelcomePageV2ViewModel.cs @@ -0,0 +1,49 @@ +using System; +using System.Collections.Generic; +using CommunityToolkit.Mvvm.ComponentModel; +using CommunityToolkit.Mvvm.Input; +using CommunityToolkit.Mvvm.Messaging; +using Wino.Core.Domain; +using Wino.Core.Domain.Enums; +using Wino.Core.Domain.Interfaces; +using Wino.Core.Domain.Models.Navigation; +using Wino.Core.Domain.Models.Updates; +using Wino.Messaging.Client.Navigation; + +namespace Wino.Mail.ViewModels; + +public partial class WelcomePageV2ViewModel : MailBaseViewModel +{ + private readonly IUpdateManager _updateManager; + + [ObservableProperty] + public partial List UpdateSections { get; set; } = []; + + public WelcomePageV2ViewModel(IUpdateManager updateManager) + { + _updateManager = updateManager; + } + + public override async void OnNavigatedTo(NavigationMode mode, object parameters) + { + base.OnNavigatedTo(mode, parameters); + + try + { + var updateNotes = await _updateManager.GetLatestUpdateNotesAsync(); + UpdateSections = updateNotes.Sections; + } + catch (Exception) + { + UpdateSections = []; + } + } + + [RelayCommand] + private void GetStarted() + { + Messenger.Send(new BreadcrumbNavigationRequested( + Translator.WelcomeWizard_Step2Title, + WinoPage.ProviderSelectionPage)); + } +} diff --git a/Wino.Mail.ViewModels/WelcomePageViewModel.cs b/Wino.Mail.ViewModels/WelcomePageViewModel.cs index 4893d0e1..9a38fb66 100644 --- a/Wino.Mail.ViewModels/WelcomePageViewModel.cs +++ b/Wino.Mail.ViewModels/WelcomePageViewModel.cs @@ -1,37 +1,69 @@ -using System; +using System; +using System.Collections.Generic; using CommunityToolkit.Mvvm.ComponentModel; +using CommunityToolkit.Mvvm.Input; using Wino.Core.Domain; using Wino.Core.Domain.Interfaces; +using Wino.Core.Domain.Enums; using Wino.Core.Domain.Models.Navigation; +using Wino.Core.Domain.Models.Updates; namespace Wino.Mail.ViewModels; public partial class WelcomePageViewModel : MailBaseViewModel { - public const string VersionFile = "vnext.md"; - private readonly IMailDialogService _dialogService; - private readonly IFileService _fileService; + private readonly IUpdateManager _updateManager; + private readonly INativeAppService _nativeAppService; + private readonly INavigationService _navigationService; [ObservableProperty] - public partial string CurrentVersionNotes { get; set; } = string.Empty; + public partial string VersionDisplay { get; set; } = string.Empty; - public WelcomePageViewModel(IMailDialogService dialogService, IFileService fileService) + [ObservableProperty] + public partial List UpdateSections { get; set; } = []; + + [ObservableProperty] + public partial List FeatureSections { get; set; } = []; + + public string GitHubUrl => "https://github.com/bkaankose/Wino-Mail/"; + public string PaypalUrl => "https://paypal.me/bkaankose?country.x=PL&locale.x=en_US"; + + public WelcomePageViewModel(IUpdateManager updateManager, + INativeAppService nativeAppService, + INavigationService navigationService) { - _dialogService = dialogService; - _fileService = fileService; + _updateManager = updateManager; + _nativeAppService = nativeAppService; + _navigationService = navigationService; } public override async void OnNavigatedTo(NavigationMode mode, object parameters) { base.OnNavigatedTo(mode, parameters); + VersionDisplay = $"{Translator.SettingsAboutVersion}{_nativeAppService.GetFullAppVersion()}"; + try { - CurrentVersionNotes = await _fileService.GetFileContentByApplicationUriAsync($"ms-appx:///Assets/ReleaseNotes/{VersionFile}"); + var updateNotes = await _updateManager.GetLatestUpdateNotesAsync(); + UpdateSections = updateNotes.Sections; } catch (Exception) { - _dialogService.InfoBarMessage(Translator.GeneralTitle_Error, "Can't find the patch notes.", Core.Domain.Enums.InfoBarMessageType.Information); + UpdateSections = []; + } + + try + { + FeatureSections = await _updateManager.GetFeaturesAsync(); + } + catch (Exception) + { + FeatureSections = []; } } + + [RelayCommand] + private void NavigateManageAccounts() + => _navigationService.Navigate(WinoPage.ManageAccountsPage, null, NavigationReferenceFrame.ShellFrame, NavigationTransitionType.DrillIn); } diff --git a/Wino.Mail.WinUI/App.xaml.cs b/Wino.Mail.WinUI/App.xaml.cs index 10a42c14..e013840f 100644 --- a/Wino.Mail.WinUI/App.xaml.cs +++ b/Wino.Mail.WinUI/App.xaml.cs @@ -21,13 +21,17 @@ using Wino.Core.Domain.Enums; using Wino.Core.Domain.Interfaces; using Wino.Core.Domain.Models.Calendar; using Wino.Core.Domain.Models.MailItem; +using Wino.Core.Domain.Models.Navigation; using Wino.Core.Domain.Models.Synchronization; using Wino.Mail.Services; using Wino.Mail.ViewModels; +using Wino.Mail.ViewModels.Data; using Wino.Mail.WinUI.Activation; using Wino.Mail.WinUI.Interfaces; +using Wino.Mail.WinUI.Models; using Wino.Mail.WinUI.Services; using Wino.Messaging.Client.Accounts; +using Wino.Messaging.Client.Navigation; using Wino.Messaging.Server; using Wino.Messaging.UI; using Wino.Services; @@ -36,13 +40,17 @@ namespace Wino.Mail.WinUI; public partial class App : WinoApplication, IRecipient, - IRecipient + IRecipient, + IRecipient, + IRecipient, + IRecipient { private const int InboxSyncsPerFullSync = 20; private const string ToggleDefaultModeLaunchArgument = "--mode=toggle-default"; private ISynchronizationManager? _synchronizationManager; private IPreferencesService? _preferencesService; private IAccountService? _accountService; + private bool _windowManagerConfigured; private CancellationTokenSource? _autoSynchronizationLoopCts; private readonly SemaphoreSlim _autoSynchronizationSemaphore = new(1, 1); private readonly Dictionary _inboxSyncCounters = []; @@ -57,6 +65,52 @@ public partial class App : WinoApplication, RegisterRecipients(); } + private void EnsureWindowManagerConfigured() + { + if (_windowManagerConfigured) + return; + + var windowManager = Services.GetRequiredService(); + windowManager.ActiveWindowChanged -= OnActiveWindowChanged; + windowManager.ActiveWindowChanged += OnActiveWindowChanged; + windowManager.WindowRemoved -= OnManagedWindowRemoved; + windowManager.WindowRemoved += OnManagedWindowRemoved; + + var nativeAppService = Services.GetRequiredService(); + nativeAppService.GetCoreWindowHwnd = () => + { + var window = windowManager.ActiveWindow + ?? windowManager.GetWindow(WinoWindowKind.Shell) + ?? windowManager.GetWindow(WinoWindowKind.Welcome) + ?? MainWindow; + + return window == null + ? IntPtr.Zero + : WinRT.Interop.WindowNative.GetWindowHandle(window); + }; + + _windowManagerConfigured = true; + } + + private void OnActiveWindowChanged(object? sender, WindowEx? window) + { + if (window == null) + return; + + MainWindow = window; + InitializeNavigationDispatcher(); + } + + private void OnManagedWindowRemoved(object? sender, WindowEx window) + { + var windowManager = Services.GetRequiredService(); + MainWindow = windowManager.ActiveWindow + ?? windowManager.GetWindow(WinoWindowKind.Shell) + ?? windowManager.GetWindow(WinoWindowKind.Welcome); + + InitializeNavigationDispatcher(); + } + public bool IsNotificationActivation(out AppNotificationActivatedEventArgs args) { var activationArgs = AppInstance.GetCurrent().GetActivatedEventArgs(); @@ -92,6 +146,11 @@ public partial class App : WinoApplication, services.AddTransient(typeof(MailRenderingPageViewModel)); services.AddTransient(typeof(AccountManagementViewModel)); services.AddTransient(typeof(WelcomePageViewModel)); + services.AddTransient(typeof(WelcomePageV2ViewModel)); + services.AddTransient(typeof(ProviderSelectionPageViewModel)); + services.AddTransient(typeof(AccountSetupProgressPageViewModel)); + services.AddTransient(typeof(SpecialImapCredentialsPageViewModel)); + services.AddSingleton(typeof(WelcomeWizardContext)); services.AddTransient(typeof(ComposePageViewModel)); services.AddTransient(typeof(IdlePageViewModel)); @@ -152,9 +211,21 @@ public partial class App : WinoApplication, _synchronizationManager = Services.GetRequiredService(); _preferencesService = Services.GetRequiredService(); _accountService = Services.GetRequiredService(); + EnsureWindowManagerConfigured(); + + var hasAnyAccount = (await _accountService.GetAccountsAsync()).Any(); + if (!IsStartupTaskLaunch() && !hasAnyAccount) + { + CreateWelcomeWindow(); + await NewThemeService.InitializeAsync(); + MainWindow?.Activate(); + LogActivation("Welcome window created and activated."); + return; + } _preferencesService.PreferenceChanged -= PreferencesServiceChanged; _preferencesService.PreferenceChanged += PreferencesServiceChanged; + RestartAutoSynchronizationLoop(); // Check if launched from toast notification. @@ -180,11 +251,11 @@ public partial class App : WinoApplication, if (isStartupTaskLaunch) { LogActivation("Launched by startup task. Window created but hidden (system tray only)."); - // Window is created but not activated. User can show it from system tray. } else { // Normal launch - show and activate the window. + // The What's New dialog is shown from MailAppShellViewModel.OnNavigatedTo once XamlRoot is ready. MainWindow?.Activate(); LogActivation("Window created and activated."); } @@ -450,10 +521,19 @@ public partial class App : WinoApplication, // Initialize theme service after window is created. await NewThemeService.InitializeAsync(); - MainWindow?.Activate(); + if (MainWindow != null) + Services.GetRequiredService().ActivateWindow(MainWindow); + LogActivation("Window created and activated."); } + public Task OpenManageAccountsFromWelcomeAsync() + { + Services.GetRequiredService() + .Navigate(WinoPage.ManageAccountsPage, null, NavigationReferenceFrame.ShellFrame, NavigationTransitionType.DrillIn); + return Task.CompletedTask; + } + /// /// Creates the main window without activating it. /// Used for both normal launch and startup task launch (tray only). @@ -462,15 +542,15 @@ public partial class App : WinoApplication, { LogActivation("Creating main window."); - MainWindow = new ShellWindow(); + var windowManager = Services.GetRequiredService(); + MainWindow = windowManager.CreateWindow(WinoWindowKind.Shell, () => new ShellWindow()); InitializeNavigationDispatcher(); - var nativeAppService = Services.GetRequiredService(); - nativeAppService.GetCoreWindowHwnd = () => WinRT.Interop.WindowNative.GetWindowHandle(MainWindow); - if (MainWindow is not IWinoShellWindow shellWindow) throw new ArgumentException("MainWindow must implement IWinoShellWindow"); + windowManager.SetPrimaryNavigationFrame(WinoWindowKind.Shell, shellWindow.GetMainFrame()); + var activationArgs = AppInstance.GetCurrent().GetActivatedEventArgs(); if (activationArgs.Kind == ExtendedActivationKind.Launch && @@ -496,6 +576,21 @@ public partial class App : WinoApplication, shellWindow.HandleAppActivation(args?.Arguments, GetCurrentLaunchTileId(), Environment.CommandLine); } + private void CreateWelcomeWindow() + { + LogActivation("Creating welcome window."); + + var windowManager = Services.GetRequiredService(); + MainWindow = windowManager.CreateWindow(WinoWindowKind.Welcome, () => new WelcomeWindow()); + if (MainWindow is WelcomeWindow welcomeWindow) + windowManager.SetPrimaryNavigationFrame(WinoWindowKind.Welcome, welcomeWindow.GetRootFrame()); + + InitializeNavigationDispatcher(); + + Services.GetRequiredService() + .Navigate(WinoPage.WelcomeHostPage, null, NavigationReferenceFrame.ShellFrame, NavigationTransitionType.None); + } + private void InitializeNavigationDispatcher() { if (MainWindow == null) @@ -509,18 +604,26 @@ public partial class App : WinoApplication, private void EnsureMainWindowVisibleAndForeground() { - if (MainWindow == null) + var windowManager = Services.GetRequiredService(); + var currentWindow = windowManager.ActiveWindow + ?? windowManager.GetWindow(WinoWindowKind.Shell) + ?? windowManager.GetWindow(WinoWindowKind.Welcome) + ?? MainWindow; + + if (currentWindow == null) return; - MainWindow.Show(); - MainWindow.BringToFront(); - MainWindow.Activate(); + MainWindow = currentWindow; + windowManager.ActivateWindow(currentWindow); } private void RegisterRecipients() { WeakReferenceMessenger.Default.Register(this); WeakReferenceMessenger.Default.Register(this); + WeakReferenceMessenger.Default.Register(this); + WeakReferenceMessenger.Default.Register(this); + WeakReferenceMessenger.Default.Register(this); } public async void Receive(NewMailSynchronizationRequested message) @@ -573,6 +676,64 @@ public partial class App : WinoApplication, } } + public void Receive(AccountCreatedMessage message) + { + var windowManager = Services.GetRequiredService(); + + // Only transition when the account was created from the WelcomeWindow. + if (windowManager.GetWindow(WinoWindowKind.Welcome) == null) + return; + + MainWindow?.DispatcherQueue?.TryEnqueue(async () => + { + // Create and activate ShellWindow — ActiveWindowChanged fires and rebinds the dispatcher. + CreateWindow(null); + windowManager.HideWindow(WinoWindowKind.Welcome); + await NewThemeService.ApplyThemeToActiveWindowAsync(); + MainWindow?.Activate(); + RestartAutoSynchronizationLoop(); + }); + } + + public void Receive(AccountRemovedMessage message) + { + var windowManager = Services.GetRequiredService(); + + // Only handle when ShellWindow is active (not during wizard rollback) + if (windowManager.GetWindow(WinoWindowKind.Shell) == null) + return; + + MainWindow?.DispatcherQueue?.TryEnqueue(async () => + { + var accounts = await _accountService!.GetAccountsAsync(); + if (accounts.Any()) return; + + // All accounts removed — go back to welcome wizard from step 1 + Services.GetRequiredService().Reset(); + StopAutoSynchronizationLoop(); + CreateWelcomeWindow(); + windowManager.HideWindow(WinoWindowKind.Shell); + await NewThemeService.ApplyThemeToActiveWindowAsync(); + MainWindow?.Activate(); + }); + } + + public void Receive(GetStartedFromWelcomeRequested message) + { + var windowManager = Services.GetRequiredService(); + + if (windowManager.GetWindow(WinoWindowKind.Welcome) == null) + return; + + MainWindow?.DispatcherQueue?.TryEnqueue(async () => + { + CreateWindow(null); + windowManager.HideWindow(WinoWindowKind.Welcome); + await NewThemeService.ApplyThemeToActiveWindowAsync(); + MainWindow?.Activate(); + }); + } + private static string GetSynchronizationFailureMessage(MailSynchronizationType synchronizationType, string? exceptionMessage) { if (!string.IsNullOrWhiteSpace(exceptionMessage)) diff --git a/Wino.Mail.WinUI/AppThemes/Clouds.xaml b/Wino.Mail.WinUI/AppThemes/Clouds.xaml index d0af4a96..ee46664a 100644 --- a/Wino.Mail.WinUI/AppThemes/Clouds.xaml +++ b/Wino.Mail.WinUI/AppThemes/Clouds.xaml @@ -4,7 +4,7 @@ xmlns:xaml="using:Microsoft.UI.Xaml"> Clouds - ms-appx:///Wino.Mail.WinUI/BackgroundImages/Clouds.jpg + ms-appx:///BackgroundImages/Clouds.jpg Transparent diff --git a/Wino.Mail.WinUI/AppThemes/Forest.xaml b/Wino.Mail.WinUI/AppThemes/Forest.xaml index 265a0843..8c8a26ba 100644 --- a/Wino.Mail.WinUI/AppThemes/Forest.xaml +++ b/Wino.Mail.WinUI/AppThemes/Forest.xaml @@ -4,7 +4,7 @@ xmlns:xaml="using:Microsoft.UI.Xaml"> Forest - ms-appx:///Wino.Mail.WinUI/BackgroundImages/Forest.jpg + ms-appx:///BackgroundImages/Forest.jpg Transparent diff --git a/Wino.Mail.WinUI/AppThemes/Garden.xaml b/Wino.Mail.WinUI/AppThemes/Garden.xaml index 830f43de..3dbe1256 100644 --- a/Wino.Mail.WinUI/AppThemes/Garden.xaml +++ b/Wino.Mail.WinUI/AppThemes/Garden.xaml @@ -4,7 +4,7 @@ xmlns:xaml="using:Microsoft.UI.Xaml"> Garden - ms-appx:///Wino.Mail.WinUI/BackgroundImages/Garden.jpg + ms-appx:///BackgroundImages/Garden.jpg Transparent diff --git a/Wino.Mail.WinUI/AppThemes/Nighty.xaml b/Wino.Mail.WinUI/AppThemes/Nighty.xaml index 382f0b04..b611d0c6 100644 --- a/Wino.Mail.WinUI/AppThemes/Nighty.xaml +++ b/Wino.Mail.WinUI/AppThemes/Nighty.xaml @@ -4,7 +4,7 @@ xmlns:xaml="using:Microsoft.UI.Xaml"> Nighty - ms-appx:///Wino.Mail.WinUI/BackgroundImages/Nighty.jpg + ms-appx:///BackgroundImages/Nighty.jpg Transparent diff --git a/Wino.Mail.WinUI/AppThemes/Snowflake.xaml b/Wino.Mail.WinUI/AppThemes/Snowflake.xaml index 9e857f3e..34137686 100644 --- a/Wino.Mail.WinUI/AppThemes/Snowflake.xaml +++ b/Wino.Mail.WinUI/AppThemes/Snowflake.xaml @@ -4,7 +4,7 @@ xmlns:xaml="using:Microsoft.UI.Xaml"> Snowflake - ms-appx:///Wino.Mail.WinUI/BackgroundImages/Snowflake.jpg + ms-appx:///BackgroundImages/Snowflake.jpg Transparent diff --git a/Wino.Mail.WinUI/Assets/UpdateNotes/Images/Calendar.svg b/Wino.Mail.WinUI/Assets/UpdateNotes/Images/Calendar.svg new file mode 100644 index 00000000..40bd60e7 --- /dev/null +++ b/Wino.Mail.WinUI/Assets/UpdateNotes/Images/Calendar.svg @@ -0,0 +1,54 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + MARCH + + + + + + + + + + + + + + + + + + + + diff --git a/Wino.Mail.WinUI/Assets/UpdateNotes/Images/Customize.svg b/Wino.Mail.WinUI/Assets/UpdateNotes/Images/Customize.svg new file mode 100644 index 00000000..5667a4f3 --- /dev/null +++ b/Wino.Mail.WinUI/Assets/UpdateNotes/Images/Customize.svg @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Wino.Mail.WinUI/Assets/UpdateNotes/Images/Mail.svg b/Wino.Mail.WinUI/Assets/UpdateNotes/Images/Mail.svg new file mode 100644 index 00000000..7a551879 --- /dev/null +++ b/Wino.Mail.WinUI/Assets/UpdateNotes/Images/Mail.svg @@ -0,0 +1,51 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + G + + + O + + + @ + diff --git a/Wino.Mail.WinUI/Assets/UpdateNotes/Images/More.svg b/Wino.Mail.WinUI/Assets/UpdateNotes/Images/More.svg new file mode 100644 index 00000000..e62b98fe --- /dev/null +++ b/Wino.Mail.WinUI/Assets/UpdateNotes/Images/More.svg @@ -0,0 +1,48 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Wino.Mail.WinUI/Assets/UpdateNotes/Images/Notification.svg b/Wino.Mail.WinUI/Assets/UpdateNotes/Images/Notification.svg new file mode 100644 index 00000000..1a298e70 --- /dev/null +++ b/Wino.Mail.WinUI/Assets/UpdateNotes/Images/Notification.svg @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 3 + + + + Archive + + + Delete + diff --git a/Wino.Mail.WinUI/Assets/UpdateNotes/Images/Security.svg b/Wino.Mail.WinUI/Assets/UpdateNotes/Images/Security.svg new file mode 100644 index 00000000..8ec6fbfa --- /dev/null +++ b/Wino.Mail.WinUI/Assets/UpdateNotes/Images/Security.svg @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Wino.Mail.WinUI/Assets/UpdateNotes/Images/Thread.svg b/Wino.Mail.WinUI/Assets/UpdateNotes/Images/Thread.svg new file mode 100644 index 00000000..48723e7b --- /dev/null +++ b/Wino.Mail.WinUI/Assets/UpdateNotes/Images/Thread.svg @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Wino.Mail.WinUI/Assets/UpdateNotes/features.json b/Wino.Mail.WinUI/Assets/UpdateNotes/features.json new file mode 100644 index 00000000..07eb1dad --- /dev/null +++ b/Wino.Mail.WinUI/Assets/UpdateNotes/features.json @@ -0,0 +1,44 @@ +[ + { + "title": "# Outlook, Gmail & IMAP/SMTP", + "description": "Connect all your email accounts in one place. Wino supports Microsoft Outlook (Office 365), Gmail, and any standard IMAP/SMTP server — giving you a unified inbox experience.", + "imageUrl": "ms-appx:///Assets/UpdateNotes/Images/Mail.svg", + "imageWidth": 128, + "imageHeight": 128 + }, + { + "title": "# Calendar with CalDAV Support", + "description": "Manage your schedule alongside your emails. Create local calendars or connect to remote CalDAV-compatible servers. View, create, and respond to events and invitations.", + "imageUrl": "ms-appx:///Assets/UpdateNotes/Images/Calendar.svg", + "imageWidth": 128, + "imageHeight": 128 + }, + { + "title": "# S/MIME Signing & Encryption", + "description": "Keep your communications secure. Sign and encrypt emails with personal certificates to ensure your messages are authentic and private.", + "imageUrl": "ms-appx:///Assets/UpdateNotes/Images/Security.svg", + "imageWidth": 128, + "imageHeight": 128 + }, + { + "title": "# Conversation Threading", + "description": "Follow discussions with ease. Emails are grouped by conversation thread so you never lose context in long email chains.", + "imageUrl": "ms-appx:///Assets/UpdateNotes/Images/Thread.svg", + "imageWidth": 128, + "imageHeight": 128 + }, + { + "title": "# Actionable Notifications", + "description": "Stay productive without switching apps. Mark as read, delete, or archive emails directly from Windows toast notifications.", + "imageUrl": "ms-appx:///Assets/UpdateNotes/Images/Notification.svg", + "imageWidth": 128, + "imageHeight": 128 + }, + { + "title": "# Rich Customization", + "description": "Make Wino yours. Choose from built-in themes, create custom themes with your own wallpapers and accent colors, configure swipe actions, and set keyboard shortcuts.", + "imageUrl": "ms-appx:///Assets/UpdateNotes/Images/Customize.svg", + "imageWidth": 128, + "imageHeight": 128 + } +] diff --git a/Wino.Mail.WinUI/Assets/UpdateNotes/vnext.json b/Wino.Mail.WinUI/Assets/UpdateNotes/vnext.json new file mode 100644 index 00000000..f0c08b09 --- /dev/null +++ b/Wino.Mail.WinUI/Assets/UpdateNotes/vnext.json @@ -0,0 +1,39 @@ +{ + "sections": [ + { + "title": "# Wino Calendar is here!", + "description": "You can now create local or remote CalDAV-compatible calendars, manage recurring events, and respond to invitations — all from within Wino.", + "imageUrl": "ms-appx:///Assets/UpdateNotes/Images/Calendar.svg", + "imageWidth": 128, + "imageHeight": 128 + }, + { + "title": "# S/MIME Signing & Encryption", + "description": "Wino now supports signing and encrypting your emails with personal certificates. Keep your communications secure and verifiable.", + "imageUrl": "ms-appx:///Assets/UpdateNotes/Images/Security.svg", + "imageWidth": 128, + "imageHeight": 128 + }, + { + "title": "# Threaded Mail View", + "description": "Emails are now grouped by conversation, making it easier to follow long discussions without losing context.", + "imageUrl": "ms-appx:///Assets/UpdateNotes/Images/Thread.svg", + "imageWidth": 128, + "imageHeight": 128 + }, + { + "title": "# Smarter Notifications", + "description": "Act on your emails directly from toast notifications — mark as read, delete, or archive without opening the app.", + "imageUrl": "ms-appx:///Assets/UpdateNotes/Images/Notification.svg", + "imageWidth": 128, + "imageHeight": 128 + }, + { + "title": "# And much more...", + "description": "Folder management, swipe actions, keyboard shortcuts, a custom print dialog, and significant performance improvements are all included in this release.\n\nThank you for using Wino Mail!", + "imageUrl": "ms-appx:///Assets/UpdateNotes/Images/More.svg", + "imageWidth": 128, + "imageHeight": 128 + } + ] +} diff --git a/Wino.Mail.WinUI/Controls/UpdateNotesFlipViewControl.xaml b/Wino.Mail.WinUI/Controls/UpdateNotesFlipViewControl.xaml new file mode 100644 index 00000000..6e8f1203 --- /dev/null +++ b/Wino.Mail.WinUI/Controls/UpdateNotesFlipViewControl.xaml @@ -0,0 +1,50 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Wino.Mail.WinUI/Controls/UpdateNotesFlipViewControl.xaml.cs b/Wino.Mail.WinUI/Controls/UpdateNotesFlipViewControl.xaml.cs new file mode 100644 index 00000000..75f236ff --- /dev/null +++ b/Wino.Mail.WinUI/Controls/UpdateNotesFlipViewControl.xaml.cs @@ -0,0 +1,54 @@ +using System; +using System.Collections.Generic; +using Microsoft.UI.Xaml; +using Microsoft.UI.Xaml.Controls; +using Wino.Core.Domain.Models.Updates; + +namespace Wino.Mail.WinUI.Controls; + +public sealed partial class UpdateNotesFlipViewControl : UserControl +{ + public event EventHandler? SelectedIndexChanged; + + public int SelectedIndex => UpdateFlipView.SelectedIndex; + + public IList? Sections + { + get { return (IList?)GetValue(SectionsProperty); } + set { SetValue(SectionsProperty, value); } + } + + public static readonly DependencyProperty SectionsProperty = + DependencyProperty.Register(nameof(Sections), + typeof(IList), + typeof(UpdateNotesFlipViewControl), + new PropertyMetadata(null, OnSectionsChanged)); + + public UpdateNotesFlipViewControl() + { + InitializeComponent(); + } + + private static void OnSectionsChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) + { + if (d is UpdateNotesFlipViewControl control) + control.UpdatePager(); + } + + private void OnFlipViewSelectionChanged(object sender, SelectionChangedEventArgs e) + { + FlipViewPager.SelectedPageIndex = UpdateFlipView.SelectedIndex; + SelectedIndexChanged?.Invoke(this, UpdateFlipView.SelectedIndex); + UpdatePager(); + } + + private void OnPipsPagerSelectedIndexChanged(PipsPager sender, PipsPagerSelectedIndexChangedEventArgs args) + { + UpdateFlipView.SelectedIndex = sender.SelectedPageIndex; + } + + private void UpdatePager() + { + FlipViewPager.NumberOfPages = Sections?.Count ?? 0; + } +} diff --git a/Wino.Mail.WinUI/CoreUWPContainerSetup.cs b/Wino.Mail.WinUI/CoreUWPContainerSetup.cs index 6cbae79b..bf729cab 100644 --- a/Wino.Mail.WinUI/CoreUWPContainerSetup.cs +++ b/Wino.Mail.WinUI/CoreUWPContainerSetup.cs @@ -18,6 +18,7 @@ public static class CoreUWPContainerSetup services.AddSingleton(provider => provider.GetRequiredService()); services.AddSingleton(); + services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); @@ -48,6 +49,7 @@ public static class CoreUWPContainerSetup services.AddTransient(typeof(AboutPageViewModel)); services.AddTransient(typeof(SettingsPageViewModel)); services.AddTransient(typeof(ManageAccountsPagePageViewModel)); + services.AddTransient(typeof(WelcomeHostPageViewModel)); services.AddTransient(typeof(KeyboardShortcutsPageViewModel)); } } diff --git a/Wino.Mail.WinUI/Dialogs/WhatIsNewDialog.xaml b/Wino.Mail.WinUI/Dialogs/WhatIsNewDialog.xaml new file mode 100644 index 00000000..56e857dd --- /dev/null +++ b/Wino.Mail.WinUI/Dialogs/WhatIsNewDialog.xaml @@ -0,0 +1,42 @@ + + + + 480 + 560 + 480 + 700 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + + + + + + + + + + + + + + + diff --git a/Wino.Mail.WinUI/Views/WelcomePage.xaml.cs b/Wino.Mail.WinUI/Views/WelcomePage.xaml.cs index 0e7c14e7..93440684 100644 --- a/Wino.Mail.WinUI/Views/WelcomePage.xaml.cs +++ b/Wino.Mail.WinUI/Views/WelcomePage.xaml.cs @@ -1,3 +1,5 @@ +using Microsoft.UI.Xaml; +using Microsoft.UI.Xaml.Controls; using CommunityToolkit.WinUI.Controls; using Wino.Views.Abstract; @@ -5,12 +7,19 @@ namespace Wino.Views; public sealed partial class WelcomePage : WelcomePageAbstract { - private readonly MarkdownConfig _config; - public WelcomePage() { InitializeComponent(); + } - _config = new MarkdownConfig(); + private void OnTabSelectionChanged(object sender, SelectionChangedEventArgs e) + { + if (sender is not Segmented segmented) + return; + + bool isFeaturesTab = segmented.SelectedIndex == 0; + + FeaturesFlipView.Visibility = isFeaturesTab ? Visibility.Visible : Visibility.Collapsed; + WhatsNewFlipView.Visibility = isFeaturesTab ? Visibility.Collapsed : Visibility.Visible; } } diff --git a/Wino.Mail.WinUI/Views/WelcomePageV2.xaml b/Wino.Mail.WinUI/Views/WelcomePageV2.xaml new file mode 100644 index 00000000..989513e2 --- /dev/null +++ b/Wino.Mail.WinUI/Views/WelcomePageV2.xaml @@ -0,0 +1,152 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Wino.Mail.WinUI/Views/WelcomePageV2.xaml.cs b/Wino.Mail.WinUI/Views/WelcomePageV2.xaml.cs new file mode 100644 index 00000000..908f3e01 --- /dev/null +++ b/Wino.Mail.WinUI/Views/WelcomePageV2.xaml.cs @@ -0,0 +1,22 @@ +using Microsoft.UI.Xaml.Controls; +using Wino.Views.Abstract; + +namespace Wino.Views; + +public sealed partial class WelcomePageV2 : WelcomePageV2Abstract +{ + public WelcomePageV2() + { + InitializeComponent(); + } + + private void OnFlipViewSelectionChanged(object sender, SelectionChangedEventArgs e) + { + FlipViewPager.SelectedPageIndex = UpdateFlipView.SelectedIndex; + } + + private void OnPipsPagerSelectedIndexChanged(PipsPager sender, PipsPagerSelectedIndexChangedEventArgs args) + { + UpdateFlipView.SelectedIndex = sender.SelectedPageIndex; + } +} diff --git a/Wino.Mail.WinUI/WelcomeWindow.xaml b/Wino.Mail.WinUI/WelcomeWindow.xaml new file mode 100644 index 00000000..f4b46e4e --- /dev/null +++ b/Wino.Mail.WinUI/WelcomeWindow.xaml @@ -0,0 +1,14 @@ + + + + + + + diff --git a/Wino.Mail.WinUI/WelcomeWindow.xaml.cs b/Wino.Mail.WinUI/WelcomeWindow.xaml.cs new file mode 100644 index 00000000..63c16556 --- /dev/null +++ b/Wino.Mail.WinUI/WelcomeWindow.xaml.cs @@ -0,0 +1,37 @@ +using Microsoft.Extensions.DependencyInjection; +using Microsoft.UI.Windowing; +using Microsoft.UI.Xaml.Controls; +using Wino.Core.Domain.Interfaces; +using WinUIEx; + +namespace Wino.Mail.WinUI; + +public sealed partial class WelcomeWindow : WindowEx +{ + public Frame GetRootFrame() => RootFrame; + + public WelcomeWindow() + { + InitializeComponent(); + + MinWidth = 980; + MinHeight = 900; + Title = "Wino Mail"; + this.SetIcon("Assets/Wino_Icon.ico"); + + ConfigureWindowChrome(); + } + + private void ConfigureWindowChrome() + { + AppWindow.TitleBar.ExtendsContentIntoTitleBar = true; + + Width = 980; + Height = 720; + + this.CenterOnScreen(); + + var themeService = WinoApplication.Current.Services.GetService(); + themeService?.UpdateSystemCaptionButtonColors(); + } +} diff --git a/Wino.Mail.WinUI/Wino.Mail.WinUI.csproj b/Wino.Mail.WinUI/Wino.Mail.WinUI.csproj index 19e614c1..9e924576 100644 --- a/Wino.Mail.WinUI/Wino.Mail.WinUI.csproj +++ b/Wino.Mail.WinUI/Wino.Mail.WinUI.csproj @@ -158,6 +158,13 @@ + + + + + + + @@ -202,6 +209,15 @@ + + + + + + + + + diff --git a/Wino.Messages/Client/Navigation/GetStartedFromWelcomeRequested.cs b/Wino.Messages/Client/Navigation/GetStartedFromWelcomeRequested.cs new file mode 100644 index 00000000..58b11c00 --- /dev/null +++ b/Wino.Messages/Client/Navigation/GetStartedFromWelcomeRequested.cs @@ -0,0 +1,7 @@ +namespace Wino.Messaging.Client.Navigation; + +/// +/// User clicked "Get Started" on the welcome page. +/// App should close the welcome window and open the shell window. +/// +public record GetStartedFromWelcomeRequested; diff --git a/Wino.Services/ServicesContainerSetup.cs b/Wino.Services/ServicesContainerSetup.cs index 054a0e5f..955380be 100644 --- a/Wino.Services/ServicesContainerSetup.cs +++ b/Wino.Services/ServicesContainerSetup.cs @@ -29,5 +29,6 @@ public static class ServicesContainerSetup services.AddSingleton(); services.AddTransient(); + services.AddSingleton(); } } diff --git a/Wino.Services/UpdateManager.cs b/Wino.Services/UpdateManager.cs new file mode 100644 index 00000000..a195068f --- /dev/null +++ b/Wino.Services/UpdateManager.cs @@ -0,0 +1,89 @@ +using System; +using System.Collections.Generic; +using System.Text.Json; +using System.Threading.Tasks; +using Wino.Core.Domain; +using Wino.Core.Domain.Interfaces; +using Wino.Core.Domain.Models.Updates; + +namespace Wino.Services; + +public class UpdateManager : IUpdateManager +{ + private const string UpdateNotesResourcePath = "ms-appx:///Assets/UpdateNotes/vnext.json"; + private const string FeaturesResourcePath = "ms-appx:///Assets/UpdateNotes/features.json"; + private const string UpdateNotesSeenKeyFormat = "UpdateNotes_{0}_Shown"; + + private readonly IFileService _fileService; + private readonly IConfigurationService _configurationService; + private readonly INativeAppService _nativeAppService; + + private string _versionSeenKey = string.Empty; + private UpdateNotes _latestUpdateNotes = new(); + + public UpdateManager(IFileService fileService, + IConfigurationService configurationService, + INativeAppService nativeAppService) + { + _fileService = fileService; + _configurationService = configurationService; + _nativeAppService = nativeAppService; + } + + private string GetVersionSeenKey() + { + if (string.IsNullOrEmpty(_versionSeenKey)) + { + var version = _nativeAppService.GetFullAppVersion(); + var sanitized = version.Replace(".", "_"); + _versionSeenKey = string.Format(UpdateNotesSeenKeyFormat, sanitized); + } + + return _versionSeenKey; + } + + public async Task GetLatestUpdateNotesAsync() + { + try + { + var json = await _fileService.GetFileContentByApplicationUriAsync(UpdateNotesResourcePath); + + if (string.IsNullOrEmpty(json)) + { + _latestUpdateNotes = new UpdateNotes(); + return _latestUpdateNotes; + } + + _latestUpdateNotes = JsonSerializer.Deserialize(json, BasicTypesJsonContext.Default.UpdateNotes) ?? new UpdateNotes(); + return _latestUpdateNotes; + } + catch (Exception) + { + _latestUpdateNotes = new UpdateNotes(); + return _latestUpdateNotes; + } + } + + public bool ShouldShowUpdateNotes() + => !_configurationService.Get(GetVersionSeenKey(), false); + + public async Task> GetFeaturesAsync() + { + try + { + var json = await _fileService.GetFileContentByApplicationUriAsync(FeaturesResourcePath); + + if (string.IsNullOrEmpty(json)) + return []; + + return JsonSerializer.Deserialize(json, BasicTypesJsonContext.Default.ListUpdateNoteSection) ?? []; + } + catch (Exception) + { + return []; + } + } + + public void MarkUpdateNotesAsSeen() + => _configurationService.Set(GetVersionSeenKey(), true); +}