New startup window.
This commit is contained in:
@@ -2,8 +2,7 @@ using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
using Microsoft.UI.Xaml.Input;
|
||||
using Windows.System;
|
||||
using Wino.Core.Domain;
|
||||
using Wino.Core.Domain.Interfaces;
|
||||
using Wino.Core.Domain.Models.Updates;
|
||||
|
||||
@@ -12,61 +11,93 @@ namespace Wino.Dialogs;
|
||||
public sealed partial class WhatIsNewDialog : ContentDialog
|
||||
{
|
||||
private readonly IUpdateManager _updateManager;
|
||||
private readonly UpdateNotes _notes;
|
||||
|
||||
public List<UpdateNoteSection> Sections { get; }
|
||||
|
||||
private bool _canClose = false;
|
||||
|
||||
public WhatIsNewDialog(UpdateNotes notes, IUpdateManager updateManager)
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
_notes = notes;
|
||||
_updateManager = updateManager;
|
||||
Sections = notes.Sections;
|
||||
|
||||
// Set the number of pages in the pip pager after sections are assigned.
|
||||
FlipViewPager.NumberOfPages = Sections.Count;
|
||||
|
||||
// Show the Get Started button immediately when there is only one page.
|
||||
if (Sections.Count <= 1)
|
||||
GetStartedButton.Visibility = Visibility.Visible;
|
||||
UpdateNotesControl.SelectedIndexChanged += OnUpdateSectionChanged;
|
||||
UpdateGetStartedButtonVisibility(UpdateNotesControl.SelectedIndex);
|
||||
|
||||
InitializeMigrationStatus();
|
||||
Closing += OnDialogClosing;
|
||||
}
|
||||
|
||||
protected override void OnKeyDown(KeyRoutedEventArgs e)
|
||||
private void OnUpdateSectionChanged(object? sender, int selectedIndex)
|
||||
=> UpdateGetStartedButtonVisibility(selectedIndex);
|
||||
|
||||
private void UpdateGetStartedButtonVisibility(int selectedIndex)
|
||||
{
|
||||
// Block ESC key to prevent accidental dismissal.
|
||||
if (e.Key == VirtualKey.Escape)
|
||||
{
|
||||
e.Handled = true;
|
||||
return;
|
||||
}
|
||||
|
||||
base.OnKeyDown(e);
|
||||
}
|
||||
|
||||
private void OnFlipViewSelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||
{
|
||||
int selectedIndex = UpdateFlipView.SelectedIndex;
|
||||
|
||||
// Keep pip pager in sync with the flip view.
|
||||
FlipViewPager.SelectedPageIndex = selectedIndex;
|
||||
|
||||
// Show Get Started button only on the last page.
|
||||
GetStartedButton.Visibility = selectedIndex == Sections.Count - 1
|
||||
? Visibility.Visible
|
||||
: Visibility.Collapsed;
|
||||
}
|
||||
|
||||
private void OnPipsPagerSelectedIndexChanged(PipsPager sender, PipsPagerSelectedIndexChangedEventArgs args)
|
||||
private void InitializeMigrationStatus()
|
||||
{
|
||||
UpdateFlipView.SelectedIndex = sender.SelectedPageIndex;
|
||||
if (!_notes.HasPendingMigrations ||
|
||||
string.IsNullOrWhiteSpace(_notes.Migration.TitleKey) ||
|
||||
string.IsNullOrWhiteSpace(_notes.Migration.DescriptionKey))
|
||||
return;
|
||||
|
||||
MigrationTitleText.Text = Translator.GetTranslatedString(_notes.Migration.TitleKey);
|
||||
MigrationDescriptionText.Text = Translator.GetTranslatedString(_notes.Migration.DescriptionKey);
|
||||
}
|
||||
|
||||
private void OnDialogClosing(ContentDialog sender, ContentDialogClosingEventArgs args)
|
||||
{
|
||||
// Only allow closing when Get Started button was clicked.
|
||||
if (!_canClose)
|
||||
args.Cancel = true;
|
||||
}
|
||||
|
||||
private async void OnGetStartedClicked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
GetStartedButton.IsEnabled = false;
|
||||
ContinueAnywayButton.Visibility = Visibility.Collapsed;
|
||||
MigrationErrorText.Visibility = Visibility.Collapsed;
|
||||
|
||||
await _updateManager.RunPendingMigrationsAsync();
|
||||
if (_notes.HasPendingMigrations)
|
||||
{
|
||||
GetStartedButton.Content = Translator.WhatIsNew_PreparingForNewVersionButton;
|
||||
MigrationPanel.Visibility = Visibility.Visible;
|
||||
MigrationProgressBar.Visibility = Visibility.Visible;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
await _updateManager.RunPendingMigrationsAsync();
|
||||
_updateManager.MarkUpdateNotesAsSeen();
|
||||
}
|
||||
catch (System.Exception ex)
|
||||
{
|
||||
MigrationProgressBar.Visibility = Visibility.Collapsed;
|
||||
MigrationErrorText.Text = string.Format(Translator.WhatIsNew_MigrationFailedMessage, ex.GetType().Name);
|
||||
MigrationErrorText.Visibility = Visibility.Visible;
|
||||
ContinueAnywayButton.Visibility = Visibility.Visible;
|
||||
GetStartedButton.IsEnabled = true;
|
||||
GetStartedButton.Content = Translator.WhatIsNew_GetStartedButton;
|
||||
return;
|
||||
}
|
||||
|
||||
_canClose = true;
|
||||
Hide();
|
||||
}
|
||||
|
||||
private void OnContinueAnywayClicked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
_updateManager.MarkUpdateNotesAsSeen();
|
||||
|
||||
_canClose = true;
|
||||
Hide();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user