Skip to content

Commit

Permalink
Replace CoreDispatcher with DispatcherQueue.
Browse files Browse the repository at this point in the history
  • Loading branch information
AnalogFeelings committed Jul 4, 2023
1 parent 06bd538 commit 8207b39
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/AmbientSounds.Uwp/Controls/FocusTimerModule.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using Windows.Foundation.Metadata;
using Windows.UI.Shell;
using System;
using JeniusApps.Common.Tools;

namespace AmbientSounds.Controls;

Expand All @@ -22,10 +23,13 @@ public sealed partial class FocusTimerModule : UserControl, ICanInitialize
{ "page", "focus" }
};

private IDispatcherQueue _dispatcherQueue;

public FocusTimerModule()
{
this.InitializeComponent();
DataContext = App.Services.GetRequiredService<FocusTimerModuleViewModel>();
_dispatcherQueue = App.Services.GetRequiredService<IDispatcherQueue>();

// This is not present in Windows 10, prevent exception.
if (ApiInformation.IsTypePresent("Windows.UI.Shell.FocusSessionManager"))
Expand Down Expand Up @@ -125,10 +129,10 @@ private void CloseAll()
TeachingTip4.IsOpen = false;
}

private async void Manager_IsFocusActiveChanged(FocusSessionManager sender, object args)
private void Manager_IsFocusActiveChanged(FocusSessionManager sender, object args)
{
// Must run in UI thread, otherwise it gets mad.
await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
_dispatcherQueue.TryEnqueue(() =>
{
ViewModel.IsFocusEnabled = sender.IsFocusActive;
});
Expand Down

0 comments on commit 8207b39

Please sign in to comment.