Some issues with changing the app mode and notifications have been fixed.
This commit is contained in:
@@ -8,12 +8,38 @@ namespace Wino.Mail.WinUI;
|
||||
|
||||
public class WinUIDispatcher : IDispatcher
|
||||
{
|
||||
private readonly DispatcherQueue _coreDispatcher;
|
||||
private DispatcherQueue? _coreDispatcher;
|
||||
|
||||
public WinUIDispatcher()
|
||||
{
|
||||
}
|
||||
|
||||
public WinUIDispatcher(DispatcherQueue coreDispatcher)
|
||||
{
|
||||
_coreDispatcher = coreDispatcher;
|
||||
}
|
||||
|
||||
public Task ExecuteOnUIThread(Action action) => _coreDispatcher.EnqueueAsync(action, DispatcherQueuePriority.Normal);
|
||||
public bool HasThreadAccess => _coreDispatcher?.HasThreadAccess == true;
|
||||
|
||||
public void Initialize(DispatcherQueue coreDispatcher)
|
||||
{
|
||||
_coreDispatcher ??= coreDispatcher ?? throw new ArgumentNullException(nameof(coreDispatcher));
|
||||
}
|
||||
|
||||
public Task ExecuteOnUIThread(Action action)
|
||||
{
|
||||
if (action == null)
|
||||
throw new ArgumentNullException(nameof(action));
|
||||
|
||||
if (_coreDispatcher == null)
|
||||
throw new InvalidOperationException("UI dispatcher is not initialized.");
|
||||
|
||||
if (_coreDispatcher.HasThreadAccess)
|
||||
{
|
||||
action();
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
return _coreDispatcher.EnqueueAsync(action, DispatcherQueuePriority.Normal);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user