Skip to content
Open
Show file tree
Hide file tree
Changes from 4 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
10 changes: 9 additions & 1 deletion src/LogoFX.Client.Core.Platform/src/CommonProperties.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
#if NET || NETCORE

#if (NET || NETCORE) && !WINUI3
Comment thread
glyad marked this conversation as resolved.
Outdated
using System.Windows;
#endif

using System.Diagnostics.CodeAnalysis;
Comment thread
glyad marked this conversation as resolved.
Outdated
#if WINUI3
using Microsoft.UI.Xaml;
#endif

namespace LogoFX.Client.Core
{
/// <summary>
Expand All @@ -14,6 +20,7 @@ public class CommonProperties
/// </summary>
/// <param name="obj"></param>
/// <returns></returns>
[SuppressMessage("ReSharper", "UnusedMember.Global")]
Comment thread
glyad marked this conversation as resolved.
public static DependencyObject GetOwner(DependencyObject obj)
{
return (DependencyObject)obj.GetValue(OwnerProperty);
Expand All @@ -24,6 +31,7 @@ public static DependencyObject GetOwner(DependencyObject obj)
/// </summary>
/// <param name="obj"></param>
/// <param name="value"></param>
[SuppressMessage("ReSharper", "UnusedMember.Global")]
Comment thread
glyad marked this conversation as resolved.
public static void SetOwner(DependencyObject obj, DependencyObject value)
{
obj.SetValue(OwnerProperty, value);
Expand Down
10 changes: 9 additions & 1 deletion 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>
#if !WINUI3
Comment thread
glyad marked this conversation as resolved.
Outdated
public const System.Windows.Threading.DispatcherPriority
DispatcherPriority = System.Windows.Threading.DispatcherPriority.DataBind;
#else
public const Microsoft.UI.Dispatching.DispatcherQueuePriority
DispatcherPriority = Microsoft.UI.Dispatching.DispatcherQueuePriority.Normal;
#endif
}
}
55 changes: 46 additions & 9 deletions src/LogoFX.Client.Core.Platform/src/PlatformDispatch.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,28 @@
using System.Windows.Threading;
using System.Diagnostics.CodeAnalysis;
Comment thread
glyad marked this conversation as resolved.
using LogoFX.Client.Core;

#if !WINUI3
Comment thread
glyad marked this conversation as resolved.
Outdated
using System.Windows.Threading;
#endif

#if WINUI3
using Microsoft.UI.Dispatching;
#endif

// ReSharper disable once CheckNamespace
namespace System.Threading
{
/// <summary>
/// Platform-specific dispatcher
/// </summary>
[SuppressMessage("ReSharper", "UnusedMember.Global")]
Comment thread
glyad marked this conversation as resolved.
public class PlatformDispatch : IDispatch
{
private Action<Action, bool, DispatcherPriority> _dispatch;

#if !WINUI3
Comment thread
glyad marked this conversation as resolved.
Outdated
private Action<Action, bool, DispatcherPriority> _dispatch;
#else
private Action<Action, bool, DispatcherQueuePriority> _dispatch;
#endif
private void EnsureDispatch()
{
if (_dispatch == null)
Expand All @@ -24,19 +36,34 @@ private void EnsureDispatch()
/// </summary>
public void InitializeDispatch()
{
var dispatcher = Dispatcher.CurrentDispatcher;
var dispatcher
#if !WINUI3
= Dispatcher.CurrentDispatcher;
#else
= DispatcherQueue.GetForCurrentThread();
#endif
if (dispatcher == null)
throw new InvalidOperationException("Dispatch is not initialized correctly");
_dispatch = (action, @async, priority) =>
_dispatch = (action, async, priority) =>
{
if (!@async && dispatcher.CheckAccess())
if (!async &&
Comment thread
glyad marked this conversation as resolved.
#if !WINUI3
dispatcher.CheckAccess()
#else
dispatcher.HasThreadAccess
#endif
)
{
action();
}
else
{
#if !WINUI3
dispatcher.BeginInvoke(action, priority);
}
#else
dispatcher.TryEnqueue(priority, () => action());
#endif
}
};
}

Expand All @@ -52,7 +79,12 @@ public void BeginOnUiThread(Action action)
/// <param name="priority">Desired priority</param>
/// <param name="action">Action</param>
public void BeginOnUiThread(
DispatcherPriority priority, Action action)
#if !WINUI3
DispatcherPriority priority,
#else
DispatcherQueuePriority priority,
#endif
Action action)
{
EnsureDispatch();
_dispatch(action, true, priority);
Expand All @@ -70,7 +102,12 @@ public void OnUiThread(Action action)
/// <param name="priority">Desired priority</param>
/// <param name="action">Action</param>
public void OnUiThread(
DispatcherPriority priority, Action action)
#if !WINUI3
DispatcherPriority priority,
#else
DispatcherQueuePriority priority,
#endif
Action action)
{
EnsureDispatch();
_dispatch(action, false, priority);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0-windows10.0.19041.0</TargetFramework>
<TargetPlatformMinVersion>10.0.17763.0</TargetPlatformMinVersion>
<RootNamespace>LogoFX.Client.Core.Platform.WinUI3</RootNamespace>
Comment thread
glyad marked this conversation as resolved.
Outdated
<RuntimeIdentifiers>win10-x86;win10-x64;win10-arm64</RuntimeIdentifiers>
<UseWinUI>true</UseWinUI>
</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.3" />
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.22000.194" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\LogoFX.Client.Core\LogoFX.Client.Core.csproj" />
</ItemGroup>
</Project>
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