Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,6 @@
xmlns:tkcontrols="using:CommunityToolkit.WinUI.Controls"
Loaded="Page_Loaded"
mc:Ignorable="d">
<Page.Resources>
<tkcontrols:MarkdownThemes
x:Key="ReleaseNotesMarkdownThemeConfig"
BoldFontWeight="SemiBold"
H1FontSize="28"
H1FontWeight="SemiBold"
H1Margin="0, 36, 0, 8"
H2FontSize="20"
H2FontWeight="SemiBold"
H2Margin="0, 16, 0, 4"
H3FontSize="16"
H3FontWeight="SemiBold"
H3Margin="0, 16, 0, 4"
HorizontalRuleBrush="{StaticResource DividerStrokeColorDefaultBrush}"
HorizontalRuleThickness="1"
ImageStretch="Uniform"
ListBulletSpacing="1"
ListGutterWidth="10" />
<tkcontrols:MarkdownConfig x:Key="ReleaseNotesMarkdownConfig" Themes="{StaticResource ReleaseNotesMarkdownThemeConfig}" />
</Page.Resources>

<!-- Main layout container -->
<Grid>
<ScrollViewer HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
Expand All @@ -51,7 +30,7 @@
Visibility="Visible" />
<tkcontrols:MarkdownTextBlock
x:Name="ReleaseNotesMarkdown"
Config="{StaticResource ReleaseNotesMarkdownConfig}"
Foreground="{ThemeResource TextFillColorPrimaryBrush}"
UseAutoLinks="True"
UseEmphasisExtras="True"
UseListExtras="True"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@
using System.Globalization;
using System.Text;
using System.Text.RegularExpressions;
using CommunityToolkit.WinUI.Controls;
using ManagedCommon;
using Microsoft.PowerToys.Settings.UI.Helpers;
using Microsoft.UI.Text;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Media;
using Microsoft.UI.Xaml.Media.Imaging;
using Microsoft.UI.Xaml.Navigation;

Expand All @@ -19,13 +22,15 @@ namespace Microsoft.PowerToys.Settings.UI.OOBE.Views
public sealed partial class ScoobeReleaseNotesPage : Page
{
private IList<PowerToysReleaseInfo> _currentReleases;
private string _currentMarkdown;

/// <summary>
/// Initializes a new instance of the <see cref="ScoobeReleaseNotesPage"/> class.
/// </summary>
public ScoobeReleaseNotesPage()
{
this.InitializeComponent();
Unloaded += OnUnloaded;
}

/// <summary>
Expand Down Expand Up @@ -128,6 +133,7 @@ private void DisplayReleaseNotes()
LoadingProgressRing.Visibility = Visibility.Collapsed;

var (releaseNotesMarkdown, heroImageUrl) = ProcessReleaseNotesMarkdown(_currentReleases);
_currentMarkdown = releaseNotesMarkdown;

// Set the Hero image if found
if (!string.IsNullOrEmpty(heroImageUrl))
Expand All @@ -140,7 +146,7 @@ private void DisplayReleaseNotes()
HeroImageHolder.Visibility = Visibility.Collapsed;
}

ReleaseNotesMarkdown.Text = releaseNotesMarkdown;
ApplyThemeAndRenderMarkdown();
ReleaseNotesMarkdown.Visibility = Visibility.Visible;
}
catch (Exception ex)
Expand All @@ -151,9 +157,81 @@ private void DisplayReleaseNotes()

private void Page_Loaded(object sender, RoutedEventArgs e)
{
ActualThemeChanged += OnActualThemeChanged;
App.ThemeService.ThemeChanged += OnAppThemeChanged;
DisplayReleaseNotes();
}

private void OnActualThemeChanged(FrameworkElement sender, object args)
{
ApplyThemeAndRenderMarkdown();
}

private void OnAppThemeChanged(object sender, ElementTheme theme)
{
if (DispatcherQueue.HasThreadAccess)
{
ApplyThemeAndRenderMarkdown();
return;
}

_ = DispatcherQueue.TryEnqueue(ApplyThemeAndRenderMarkdown);
}

private void ApplyThemeAndRenderMarkdown()
{
var headingForeground = ReleaseNotesMarkdown.Foreground as Brush;
if (headingForeground == null)
{
return;
}

ReleaseNotesMarkdown.Config = BuildMarkdownConfig(headingForeground);

if (string.IsNullOrEmpty(_currentMarkdown))
{
return;
}

// Force markdown regeneration so headings pick up the updated theme config.
ReleaseNotesMarkdown.Text = string.Empty;
ReleaseNotesMarkdown.Text = _currentMarkdown;
}

private static MarkdownConfig BuildMarkdownConfig(Brush headingForeground)
{
return new MarkdownConfig
{
Themes = new MarkdownThemes
{
BoldFontWeight = FontWeights.SemiBold,
H1FontSize = 28,
H1FontWeight = FontWeights.SemiBold,
H1Margin = new Thickness(0, 36, 0, 8),
H1Foreground = headingForeground,
H2FontSize = 20,
H2FontWeight = FontWeights.SemiBold,
H2Margin = new Thickness(0, 16, 0, 4),
H2Foreground = headingForeground,
H3FontSize = 16,
H3FontWeight = FontWeights.SemiBold,
H3Margin = new Thickness(0, 16, 0, 4),
H3Foreground = headingForeground,
HorizontalRuleThickness = 1,
ImageStretch = Stretch.Uniform,
ListBulletSpacing = 1,
ListGutterWidth = 10,
},
};
}

private void OnUnloaded(object sender, RoutedEventArgs e)
{
ActualThemeChanged -= OnActualThemeChanged;
App.ThemeService.ThemeChanged -= OnAppThemeChanged;
Unloaded -= OnUnloaded;
}

protected override void OnNavigatedTo(NavigationEventArgs e)
{
if (e.Parameter is IList<PowerToysReleaseInfo> releases)
Expand Down
Loading