Skip to content

Commit

Permalink
Added DispatcherQueue dispatching for high contrast theme change
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergio0694 committed Sep 14, 2021
1 parent 5dfc575 commit aaa9036
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
13 changes: 8 additions & 5 deletions Microsoft.Toolkit.Uwp.UI/Helpers/ThemeListener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,23 +79,26 @@ public ThemeListener(DispatcherQueue dispatcherQueue = null)
}
}

private void Accessible_HighContrastChanged(AccessibilitySettings sender, object args)
private async void Accessible_HighContrastChanged(AccessibilitySettings sender, object args)
{
#if DEBUG
System.Diagnostics.Debug.WriteLine("HighContrast Changed");
#endif

UpdateProperties();
await OnThemePropertyChangedAsync();
}

// Note: This can get called multiple times during HighContrast switch, do we care?
private async void Settings_ColorValuesChanged(UISettings sender, object args)
{
await OnColorValuesChanged();
await OnThemePropertyChangedAsync();
}

// Internal abstraction is used by the Unit Tests
internal Task OnColorValuesChanged()
/// <summary>
/// Dispatches an update for the public properties and the firing of <see cref="ThemeChanged"/> on <see cref="DispatcherQueue"/>.
/// </summary>
/// <returns>A <see cref="Task"/> that indicates when the dispatching has completed.</returns>
internal Task OnThemePropertyChangedAsync()
{
// Getting called off thread, so we need to dispatch to request value.
return DispatcherQueue.EnqueueAsync(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public Task Init()
[TestMethod]
public async Task ThemeListenerDispatcherTestAsync()
{
await _themeListener.OnColorValuesChanged();
await _themeListener.OnThemePropertyChangedAsync();

await _taskCompletionSource.Task;
}
Expand All @@ -49,7 +49,7 @@ public async Task ThemeListenerDispatcherTestFromOtherThreadAsync()
{
await Task.Run(async () =>
{
await _themeListener.OnColorValuesChanged();
await _themeListener.OnThemePropertyChangedAsync();
});
await _taskCompletionSource.Task;
}
Expand Down

0 comments on commit aaa9036

Please sign in to comment.