Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create WinUI 3 platform implementation #11

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from
Open
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 @@ -6,14 +6,14 @@
<UseWPF>true</UseWPF>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="FluentAssertions" Version="6.3.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
<PackageReference Include="SpecFlow" Version="3.9.58" />
<PackageReference Include="FluentAssertions" Version="6.7.0" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@glyad How is this related to WinUI3?

<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.1" />
<PackageReference Include="SpecFlow" Version="3.9.74" />
<PackageReference Include="SpecFlow.Plus.LivingDocPlugin" Version="3.9.57" />
<PackageReference Include="SpecFlow.Tools.MsBuild.Generation" Version="3.9.58" />
<PackageReference Include="SpecFlow.xUnit" Version="3.9.58" />
<PackageReference Include="xunit.core" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<PackageReference Include="SpecFlow.Tools.MsBuild.Generation" Version="3.9.74" />
<PackageReference Include="SpecFlow.xUnit" Version="3.9.74" />
<PackageReference Include="xunit.core" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 16 additions & 11 deletions src/LogoFX.Client.Core.Platform/src/CommonProperties.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#if NET || NETCORE
using System.Diagnostics.CodeAnalysis;
#if WINUI3
using Microsoft.UI.Xaml;
#else
using System.Windows;
#endif

Expand All @@ -14,26 +17,28 @@ public class CommonProperties
/// </summary>
/// <param name="obj"></param>
/// <returns></returns>
public static DependencyObject GetOwner(DependencyObject obj)
{
return (DependencyObject)obj.GetValue(OwnerProperty);
}
[SuppressMessage("ReSharper", "UnusedMember.Global")]
glyad marked this conversation as resolved.
Show resolved Hide resolved
public static DependencyObject GetOwner(DependencyObject obj)
=> (DependencyObject)obj.GetValue(OwnerProperty);

/// <summary>
/// Sets the owner value
/// </summary>
/// <param name="obj"></param>
/// <param name="value"></param>
public static void SetOwner(DependencyObject obj, DependencyObject value)
{
obj.SetValue(OwnerProperty, value);
}

[SuppressMessage("ReSharper", "UnusedMember.Global")]
glyad marked this conversation as resolved.
Show resolved Hide resolved
public static void SetOwner(DependencyObject obj, DependencyObject value)
=> obj.SetValue(OwnerProperty, value);

// Using a DependencyProperty as the backing store for Owner. This enables animation, styling, binding, etc...
/// <summary>
/// Owner which is usually the parent.
/// </summary>
public static readonly DependencyProperty OwnerProperty =
DependencyProperty.RegisterAttached("Owner", typeof(DependencyObject), typeof(CommonProperties), new PropertyMetadata(null));
DependencyProperty.RegisterAttached(
"Owner",
typeof(DependencyObject),
typeof(CommonProperties),
new PropertyMetadata(null));
}
}
14 changes: 11 additions & 3 deletions src/LogoFX.Client.Core.Platform/src/Consts.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
namespace LogoFX.Client.Core
using System.Diagnostics.CodeAnalysis;

namespace LogoFX.Client.Core
{
/// <summary>
/// Dispatcher-related constants.
/// </summary>
[SuppressMessage("ReSharper", "IdentifierTypo")]
public static class Consts
{
/// <summary>
/// The dispatcher priority
/// </summary>
public const System.Windows.Threading.DispatcherPriority
DispatcherPriority = System.Windows.Threading.DispatcherPriority.DataBind;
#if WINUI3
public const Microsoft.UI.Dispatching.DispatcherQueuePriority DispatcherPriority
= Microsoft.UI.Dispatching.DispatcherQueuePriority.Normal;
#else
public const System.Windows.Threading.DispatcherPriority DispatcherPriority
= System.Windows.Threading.DispatcherPriority.DataBind;
#endif
}
}
67 changes: 50 additions & 17 deletions src/LogoFX.Client.Core.Platform/src/PlatformDispatch.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
using System.Diagnostics.CodeAnalysis;
glyad marked this conversation as resolved.
Show resolved Hide resolved
#if WINUI3
using Microsoft.UI.Dispatching;
#else
using System.Windows.Threading;
#endif
using LogoFX.Client.Core;

// ReSharper disable once CheckNamespace
Expand All @@ -7,10 +12,14 @@ namespace System.Threading
/// <summary>
/// Platform-specific dispatcher
/// </summary>
[SuppressMessage("ReSharper", "UnusedMember.Global")]
glyad marked this conversation as resolved.
Show resolved Hide resolved
public class PlatformDispatch : IDispatch
{
private Action<Action, bool, DispatcherPriority> _dispatch;

#if WINUI3
private Action<Action, bool, DispatcherQueuePriority> _dispatch;
#else
private Action<Action, bool, DispatcherPriority> _dispatch;
#endif
private void EnsureDispatch()
{
if (_dispatch == null)
Expand All @@ -24,53 +33,77 @@ private void EnsureDispatch()
/// </summary>
public void InitializeDispatch()
{
var dispatcher = Dispatcher.CurrentDispatcher;
if (dispatcher == null)
throw new InvalidOperationException("Dispatch is not initialized correctly");
_dispatch = (action, @async, priority) =>
var dispatcher
#if WINUI3
= DispatcherQueue.GetForCurrentThread();
#else
= Dispatcher.CurrentDispatcher;
#endif
if (dispatcher == null)
{
throw new InvalidOperationException("Dispatch is not initialized correctly");
}

_dispatch = (action, async, priority) =>
{
if (!@async && dispatcher.CheckAccess())
if (!async &&
glyad marked this conversation as resolved.
Show resolved Hide resolved
#if WINUI3
dispatcher.HasThreadAccess
#else
dispatcher.CheckAccess()
#endif
)
{
action();
}
else
{
#if WINUI3
dispatcher.TryEnqueue(priority, () => action());
#else
dispatcher.BeginInvoke(action, priority);
}
#endif
}
};
}

/// <inheritdoc />
public void BeginOnUiThread(Action action)
{
BeginOnUiThread(Consts.DispatcherPriority, action);
}
=> BeginOnUiThread(Consts.DispatcherPriority, action);

/// <summary>
/// Begins the action on the UI thread according to the specified priority
/// </summary>
/// <param name="priority">Desired priority</param>
/// <param name="action">Action</param>
public void BeginOnUiThread(
DispatcherPriority priority, Action action)
#if WINUI3
DispatcherQueuePriority priority,
#else
DispatcherPriority priority,
#endif
Action action)
{
EnsureDispatch();
_dispatch(action, true, priority);
}

/// <inheritdoc />
public void OnUiThread(Action action)
{
OnUiThread(Consts.DispatcherPriority, action);
}
public void OnUiThread(Action action)
=> OnUiThread(Consts.DispatcherPriority, action);

/// <summary>
/// Executes the action on the UI thread according to the specified priority
/// </summary>
/// <param name="priority">Desired priority</param>
/// <param name="action">Action</param>
public void OnUiThread(
DispatcherPriority priority, Action action)
#if WINUI3
DispatcherQueuePriority priority,
#else
DispatcherPriority priority,
#endif
Action action)
{
EnsureDispatch();
_dispatch(action, false, priority);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0-windows10.0.19041.0</TargetFramework>
<TargetPlatformMinVersion>10.0.17763.0</TargetPlatformMinVersion>
<RootNamespace>LogoFX.Client.Core</RootNamespace>
<RuntimeIdentifiers>win10-x86;win10-x64;win10-arm64</RuntimeIdentifiers>
<UseWinUI>true</UseWinUI>
<AssemblyName>LogoFX.Client.Core.Platform</AssemblyName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DefineConstants>TRACE;WINUI3</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<DefineConstants>TRACE;WINUI3</DefineConstants>
</PropertyGroup>
<ItemGroup>
<Compile Include="..\src\CommonProperties.cs" Link="CommonProperties.cs" />
<Compile Include="..\src\Consts.cs" Link="Consts.cs" />
<Compile Include="..\src\PlatformDispatch.cs" Link="PlatformDispatch.cs" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.1.5" />
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.22621.1" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\LogoFX.Client.Core\LogoFX.Client.Core.csproj" />
</ItemGroup>
</Project>
14 changes: 7 additions & 7 deletions src/LogoFX.Client.Core.Specs/LogoFX.Client.Core.Specs.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Attest.Tests.SpecFlow" Version="2.4.5" />
<PackageReference Include="FluentAssertions" Version="6.3.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
<PackageReference Include="SpecFlow" Version="3.9.58" />
<PackageReference Include="FluentAssertions" Version="6.7.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.1" />
<PackageReference Include="SpecFlow" Version="3.9.74" />
<PackageReference Include="SpecFlow.Plus.LivingDocPlugin" Version="3.9.57" />
<PackageReference Include="SpecFlow.Tools.MsBuild.Generation" Version="3.9.58" />
<PackageReference Include="SpecFlow.xUnit" Version="3.9.58" />
<PackageReference Include="xunit.core" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<PackageReference Include="SpecFlow.Tools.MsBuild.Generation" Version="3.9.74" />
<PackageReference Include="SpecFlow.xUnit" Version="3.9.74" />
<PackageReference Include="xunit.core" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Attest.Tests.SpecFlow" Version="2.4.5" />
<PackageReference Include="FluentAssertions" Version="6.3.0" />
<PackageReference Include="FluentAssertions" Version="6.7.0" />
</ItemGroup>
</Project>
14 changes: 7 additions & 7 deletions src/LogoFX.Core.Specs/LogoFX.Core.Specs.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Attest.Tests.SpecFlow" Version="2.4.5" />
<PackageReference Include="FluentAssertions" Version="6.3.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
<PackageReference Include="SpecFlow" Version="3.9.58" />
<PackageReference Include="FluentAssertions" Version="6.7.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.1" />
<PackageReference Include="SpecFlow" Version="3.9.74" />
<PackageReference Include="SpecFlow.Plus.LivingDocPlugin" Version="3.9.57" />
<PackageReference Include="SpecFlow.Tools.MsBuild.Generation" Version="3.9.58" />
<PackageReference Include="SpecFlow.xUnit" Version="3.9.58" />
<PackageReference Include="xunit.core" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<PackageReference Include="SpecFlow.Tools.MsBuild.Generation" Version="3.9.74" />
<PackageReference Include="SpecFlow.xUnit" Version="3.9.74" />
<PackageReference Include="xunit.core" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
8 changes: 4 additions & 4 deletions src/LogoFX.Core.Tests/LogoFX.Core.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="FluentAssertions" Version="6.3.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
<PackageReference Include="xunit.core" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<PackageReference Include="FluentAssertions" Version="6.7.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.1" />
<PackageReference Include="xunit.core" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
19 changes: 19 additions & 0 deletions src/LogoFX.Core.sln
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LogoFX.Core.Specs", "LogoFX
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LogoFX.Core.Specs.Common", "LogoFX.Core.Specs.Common\LogoFX.Core.Specs.Common.csproj", "{C2C89A94-96B9-43DA-841C-3F78ED059DDF}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LogoFX.Client.Core.Platform.WinUI3", "LogoFX.Client.Core.Platform\winui3\LogoFX.Client.Core.Platform.WinUI3.csproj", "{74DFE24B-28FA-48B8-818D-9671F05EBFE2}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -401,6 +403,22 @@ Global
{C2C89A94-96B9-43DA-841C-3F78ED059DDF}.Release|x64.Build.0 = Release|Any CPU
{C2C89A94-96B9-43DA-841C-3F78ED059DDF}.Release|x86.ActiveCfg = Release|Any CPU
{C2C89A94-96B9-43DA-841C-3F78ED059DDF}.Release|x86.Build.0 = Release|Any CPU
{74DFE24B-28FA-48B8-818D-9671F05EBFE2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{74DFE24B-28FA-48B8-818D-9671F05EBFE2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{74DFE24B-28FA-48B8-818D-9671F05EBFE2}.Debug|ARM.ActiveCfg = Debug|Any CPU
{74DFE24B-28FA-48B8-818D-9671F05EBFE2}.Debug|ARM.Build.0 = Debug|Any CPU
{74DFE24B-28FA-48B8-818D-9671F05EBFE2}.Debug|x64.ActiveCfg = Debug|Any CPU
{74DFE24B-28FA-48B8-818D-9671F05EBFE2}.Debug|x64.Build.0 = Debug|Any CPU
{74DFE24B-28FA-48B8-818D-9671F05EBFE2}.Debug|x86.ActiveCfg = Debug|Any CPU
{74DFE24B-28FA-48B8-818D-9671F05EBFE2}.Debug|x86.Build.0 = Debug|Any CPU
{74DFE24B-28FA-48B8-818D-9671F05EBFE2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{74DFE24B-28FA-48B8-818D-9671F05EBFE2}.Release|Any CPU.Build.0 = Release|Any CPU
{74DFE24B-28FA-48B8-818D-9671F05EBFE2}.Release|ARM.ActiveCfg = Release|Any CPU
{74DFE24B-28FA-48B8-818D-9671F05EBFE2}.Release|ARM.Build.0 = Release|Any CPU
{74DFE24B-28FA-48B8-818D-9671F05EBFE2}.Release|x64.ActiveCfg = Release|Any CPU
{74DFE24B-28FA-48B8-818D-9671F05EBFE2}.Release|x64.Build.0 = Release|Any CPU
{74DFE24B-28FA-48B8-818D-9671F05EBFE2}.Release|x86.ActiveCfg = Release|Any CPU
{74DFE24B-28FA-48B8-818D-9671F05EBFE2}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -427,6 +445,7 @@ Global
{728663E9-62A0-4482-8F0A-832699835760} = {F555D153-CB40-4452-B5E4-E9731566272E}
{DF5B56B9-783A-457F-B8E1-EEA9EE033E91} = {F555D153-CB40-4452-B5E4-E9731566272E}
{C2C89A94-96B9-43DA-841C-3F78ED059DDF} = {F555D153-CB40-4452-B5E4-E9731566272E}
{74DFE24B-28FA-48B8-818D-9671F05EBFE2} = {F555D153-CB40-4452-B5E4-E9731566272E}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {AC15861E-3935-4FBC-AA56-C0C4CFF71FC3}
Expand Down
14 changes: 7 additions & 7 deletions src/LogoFX.Practices.IoC.Specs/LogoFX.Practices.IoC.Specs.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Attest.Tests.SpecFlow" Version="2.4.5" />
<PackageReference Include="FluentAssertions" Version="6.3.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
<PackageReference Include="SpecFlow" Version="3.9.58" />
<PackageReference Include="FluentAssertions" Version="6.7.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.1" />
<PackageReference Include="SpecFlow" Version="3.9.74" />
<PackageReference Include="SpecFlow.Plus.LivingDocPlugin" Version="3.9.57" />
<PackageReference Include="SpecFlow.Tools.MsBuild.Generation" Version="3.9.58" />
<PackageReference Include="SpecFlow.xUnit" Version="3.9.58" />
<PackageReference Include="xunit.core" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<PackageReference Include="SpecFlow.Tools.MsBuild.Generation" Version="3.9.74" />
<PackageReference Include="SpecFlow.xUnit" Version="3.9.74" />
<PackageReference Include="xunit.core" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
Expand Down