Skip to content

Commit

Permalink
chore: Adjust for Uno WinUI
Browse files Browse the repository at this point in the history
  • Loading branch information
Youssef1313 committed Dec 20, 2023
1 parent d12e886 commit a9bfb90
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,8 @@ internal set
/// <returns></returns>
public static async Task WaitForIdle()
{
#if WINDOWS_WINUI || HAS_UNO_WINUI
// This is a wrong implementation. It doesn't really wait for "Idle".
await RootElementDispatcher.RunAsync(UnitTestDispatcherCompat.Priority.Low, () => { });
await RootElementDispatcher.RunAsync(UnitTestDispatcherCompat.Priority.Low, () => { });
#else
await RootElementDispatcher.RunIdleAsync(_ => { /* Empty to wait for the idle queue to be reached */ });
await RootElementDispatcher.RunIdleAsync(_ => { /* Empty to wait for the idle queue to be reached */ });
#endif
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,27 +47,50 @@ public enum Priority { Low = -1, Normal = 0, High = 1 }
public partial class UnitTestDispatcherCompat
{
private readonly _Impl _impl;
private readonly Windows.UI.Core.CoreDispatcher? _dispatcher;

Check failure on line 50 in src/Uno.UI.RuntimeTests.Engine.Library/Engine/UI/_Private/UnitTestDispatcherCompat.cs

View workflow job for this annotation

GitHub Actions / build

The field 'UnitTestDispatcherCompat._dispatcher' is never used

Check failure on line 50 in src/Uno.UI.RuntimeTests.Engine.Library/Engine/UI/_Private/UnitTestDispatcherCompat.cs

View workflow job for this annotation

GitHub Actions / build

Unused field '_dispatcher' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1823)

Check failure on line 50 in src/Uno.UI.RuntimeTests.Engine.Library/Engine/UI/_Private/UnitTestDispatcherCompat.cs

View workflow job for this annotation

GitHub Actions / build

The field 'UnitTestDispatcherCompat._dispatcher' is never used

Check failure on line 50 in src/Uno.UI.RuntimeTests.Engine.Library/Engine/UI/_Private/UnitTestDispatcherCompat.cs

View workflow job for this annotation

GitHub Actions / build

Unused field '_dispatcher' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1823)

Check failure on line 50 in src/Uno.UI.RuntimeTests.Engine.Library/Engine/UI/_Private/UnitTestDispatcherCompat.cs

View workflow job for this annotation

GitHub Actions / build

The field 'UnitTestDispatcherCompat._dispatcher' is never used

Check failure on line 50 in src/Uno.UI.RuntimeTests.Engine.Library/Engine/UI/_Private/UnitTestDispatcherCompat.cs

View workflow job for this annotation

GitHub Actions / build

Unused field '_dispatcher' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1823)

Check failure on line 50 in src/Uno.UI.RuntimeTests.Engine.Library/Engine/UI/_Private/UnitTestDispatcherCompat.cs

View workflow job for this annotation

GitHub Actions / build

The field 'UnitTestDispatcherCompat._dispatcher' is never used

Check failure on line 50 in src/Uno.UI.RuntimeTests.Engine.Library/Engine/UI/_Private/UnitTestDispatcherCompat.cs

View workflow job for this annotation

GitHub Actions / build

Unused field '_dispatcher' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1823)

Check failure on line 50 in src/Uno.UI.RuntimeTests.Engine.Library/Engine/UI/_Private/UnitTestDispatcherCompat.cs

View workflow job for this annotation

GitHub Actions / build

The field 'UnitTestDispatcherCompat._dispatcher' is never used

Check failure on line 50 in src/Uno.UI.RuntimeTests.Engine.Library/Engine/UI/_Private/UnitTestDispatcherCompat.cs

View workflow job for this annotation

GitHub Actions / build

Unused field '_dispatcher' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1823)

#if WINDOWS_WINUI || HAS_UNO_WINUI
public UnitTestDispatcherCompat(_Impl impl, Windows.UI.Core.CoreDispatcher? dispatcher = null)
{
this._impl = impl;
this._dispatcher = dispatcher;
}
#else
public UnitTestDispatcherCompat(_Impl impl)
{
this._impl = impl;
}
#endif

#if !WINDOWS_WINUI && !HAS_UNO_WINUI
public Windows.Foundation.IAsyncAction RunIdleAsync(Windows.UI.Core.IdleDispatchedHandler agileCallback)
=> _impl.RunIdleAsync(agileCallback);
{
#if !WINDOWS_WINUI && !HAS_UNO_WINUI
// Windows UWP and Uno UWP can use CoreDispatcher.RunIdleAsync without issues.
return _impl.RunIdleAsync(agileCallback);
#else
// For now, Uno WinUI Dispatcher is non-null.
// In the future, this will break and it will be null.
if (_dispatcher is not null)
{
return _dispatcher.RunIdleAsync(agileCallback);
}

// This code path is for Windows WinUI, and "potentially" Uno WinUI in future when the breaking change is taken.
// This is a wrong implementation. It doesn't really wait for "Idle".
return RunAsync(UnitTestDispatcherCompat.Priority.Low, () => { }).AsAsyncAction();
#endif
}

public static UnitTestDispatcherCompat From(UIElement x) =>
#if HAS_UNO_WINUI || WINDOWS_WINUI
new UnitTestDispatcherCompat(x.DispatcherQueue);
new UnitTestDispatcherCompat(x.DispatcherQueue, x.Dispatcher);
#else
new UnitTestDispatcherCompat(x.Dispatcher);
#endif

public static UnitTestDispatcherCompat From(Window x) =>
#if HAS_UNO_WINUI || WINDOWS_WINUI
new UnitTestDispatcherCompat(x.DispatcherQueue);
new UnitTestDispatcherCompat(x.DispatcherQueue, x.Dispatcher);
#else
new UnitTestDispatcherCompat(x.Dispatcher);
#endif
Expand Down

0 comments on commit a9bfb90

Please sign in to comment.