From 3af869f49fa66af99c260af0d5a4f88fc1916ca2 Mon Sep 17 00:00:00 2001 From: Nikita Tsukanov Date: Fri, 26 Aug 2016 01:45:20 +0300 Subject: [PATCH] Moved IPclPlatformWrapper and IAssetLoader to a separate assembly --- Avalonia.DotNetFrameworkRuntime/AppBuilder.cs | 40 +++++++++ .../Avalonia.DotNetFrameworkRuntime.csproj | 81 +++++++++++++++++++ .../Properties/AssemblyInfo.cs | 36 +++++++++ .../packages.config | 5 ++ Avalonia.sln | 45 ++++++++++- samples/BindingTest/BindingTest.csproj | 4 + samples/ControlCatalog.Desktop/App.config | 8 +- .../ControlCatalog.Desktop.csproj | 4 + .../TestApplication/TestApplication.csproj | 4 + samples/VirtualizationTest/App.config | 8 +- .../VirtualizationTest.csproj | 4 + .../XamlTestApplication.csproj | 4 + .../Avalonia.Android/AndroidPlatform.cs | 2 +- src/Avalonia.Base/Avalonia.Base.csproj | 2 +- src/Avalonia.Base/AvaloniaDisposable.cs | 2 +- ...PlatformWrapper.cs => IRuntimePlatform.cs} | 2 +- .../Threading/SingleThreadDispatcher.cs | 4 +- src/Avalonia.Controls/AppBuilder.cs | 54 +++++++------ .../DesignerAssist.cs | 14 +++- src/Gtk/Avalonia.Cairo/CairoPlatform.cs | 2 +- src/Gtk/Avalonia.Gtk/Avalonia.Gtk.csproj | 1 - src/Gtk/Avalonia.Gtk/GtkPlatform.cs | 4 +- .../Context/AvaloniaNamespaceRegistry.cs | 2 +- .../PlatformSupport/PlatformSupport.projitems | 6 +- ...mWrapper.cs => StandardRuntimePlatform.cs} | 4 +- ....cs => StandardRuntimePlatformServices.cs} | 4 +- src/Skia/Avalonia.Skia/SkiaPlatform.cs | 2 +- .../Avalonia.Direct2D1/Direct2D1Platform.cs | 2 +- .../Avalonia.Win32/Avalonia.Win32.csproj | 1 - src/Windows/Avalonia.Win32/Win32Platform.cs | 6 +- src/iOS/Avalonia.iOS/iOSPlatform.cs | 6 +- .../Avalonia.DesignerSupport.TestApp.csproj | 4 + .../FullLayoutTests.cs | 2 +- tests/Avalonia.UnitTests/TestServices.cs | 14 ++-- .../Avalonia.UnitTests/UnitTestApplication.cs | 2 +- 35 files changed, 312 insertions(+), 73 deletions(-) create mode 100644 Avalonia.DotNetFrameworkRuntime/AppBuilder.cs create mode 100644 Avalonia.DotNetFrameworkRuntime/Avalonia.DotNetFrameworkRuntime.csproj create mode 100644 Avalonia.DotNetFrameworkRuntime/Properties/AssemblyInfo.cs create mode 100644 Avalonia.DotNetFrameworkRuntime/packages.config rename src/Avalonia.Base/Platform/{IPclPlatformWrapper.cs => IRuntimePlatform.cs} (90%) rename src/Shared/PlatformSupport/{PclPlatformWrapper.cs => StandardRuntimePlatform.cs} (93%) rename src/Shared/PlatformSupport/{SharedPlatform.cs => StandardRuntimePlatformServices.cs} (74%) diff --git a/Avalonia.DotNetFrameworkRuntime/AppBuilder.cs b/Avalonia.DotNetFrameworkRuntime/AppBuilder.cs new file mode 100644 index 0000000000..5dc36865ee --- /dev/null +++ b/Avalonia.DotNetFrameworkRuntime/AppBuilder.cs @@ -0,0 +1,40 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; +using Avalonia.Controls; +using Avalonia.Platform; +using Avalonia.Shared.PlatformSupport; + +namespace Avalonia +{ + public sealed class AppBuilder : AppBuilderBase + { + public AppBuilder() : base(new StandardRuntimePlatform(), () => StandardRuntimePlatformServices.Register()) + { + } + + public AppBuilder(Application app) : this() + { + Instance = app; + } + + public AppBuilder UsePlatformDetect() + { + var platformId = (int)Environment.OSVersion.Platform; + if (platformId == 4 || platformId == 6) + { + UseRenderingSubsystem("Avalonia.Cairo"); + UseWindowingSubsystem("Avalonia.Gtk"); + } + else + { + UseRenderingSubsystem("Avalonia.Direct2D1"); + UseWindowingSubsystem("Avalonia.Win32"); + } + return this; + } + } +} diff --git a/Avalonia.DotNetFrameworkRuntime/Avalonia.DotNetFrameworkRuntime.csproj b/Avalonia.DotNetFrameworkRuntime/Avalonia.DotNetFrameworkRuntime.csproj new file mode 100644 index 0000000000..0512255fc0 --- /dev/null +++ b/Avalonia.DotNetFrameworkRuntime/Avalonia.DotNetFrameworkRuntime.csproj @@ -0,0 +1,81 @@ + + + + + Debug + AnyCPU + {4A1ABB09-9047-4BD5-A4AD-A055E52C5EE0} + Library + Properties + Avalonia.DotNetFrameworkRuntime + Avalonia.DotNetFrameworkRuntime + v4.5 + 512 + + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + ..\packages\System.Reactive.Core.3.0.0\lib\net45\System.Reactive.Core.dll + True + + + ..\packages\System.Reactive.Interfaces.3.0.0\lib\net45\System.Reactive.Interfaces.dll + True + + + + + + + + + + + + + + + {B09B78D8-9B26-48B0-9149-D64A2F120F3F} + Avalonia.Base + + + {D2221C82-4A25-4583-9B43-D791E3F6820C} + Avalonia.Controls + + + {f1baa01a-f176-4c6a-b39d-5b40bb1b148f} + Avalonia.Styling + + + + + + + + + \ No newline at end of file diff --git a/Avalonia.DotNetFrameworkRuntime/Properties/AssemblyInfo.cs b/Avalonia.DotNetFrameworkRuntime/Properties/AssemblyInfo.cs new file mode 100644 index 0000000000..f55d3056f6 --- /dev/null +++ b/Avalonia.DotNetFrameworkRuntime/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("Avalonia.DotNetFrameworkRuntime")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Avalonia.DotNetFrameworkRuntime")] +[assembly: AssemblyCopyright("Copyright © 2016")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("4a1abb09-9047-4bd5-a4ad-a055e52c5ee0")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Avalonia.DotNetFrameworkRuntime/packages.config b/Avalonia.DotNetFrameworkRuntime/packages.config new file mode 100644 index 0000000000..1e93a8c9e7 --- /dev/null +++ b/Avalonia.DotNetFrameworkRuntime/packages.config @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/Avalonia.sln b/Avalonia.sln index a67f75991a..d2b5d9c0d6 100644 --- a/Avalonia.sln +++ b/Avalonia.sln @@ -163,6 +163,8 @@ Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "Avalonia.RenderTests", "tes EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VirtualizationTest", "samples\VirtualizationTest\VirtualizationTest.csproj", "{FBCAF3D0-2808-4934-8E96-3F607594517B}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Avalonia.DotNetFrameworkRuntime", "Avalonia.DotNetFrameworkRuntime\Avalonia.DotNetFrameworkRuntime.csproj", "{4A1ABB09-9047-4BD5-A4AD-A055E52C5EE0}" +EndProject Global GlobalSection(SharedMSBuildProjectFiles) = preSolution src\Skia\Avalonia.Skia\Avalonia.Skia.projitems*{2f59f3d0-748d-4652-b01e-e0d954756308}*SharedItemsImports = 13 @@ -172,10 +174,9 @@ Global src\Shared\RenderHelpers\RenderHelpers.projitems*{47be08a7-5985-410b-9ffc-2264b8ea595f}*SharedItemsImports = 4 src\Skia\Avalonia.Skia\Avalonia.Skia.projitems*{47be08a7-5985-410b-9ffc-2264b8ea595f}*SharedItemsImports = 4 tests\Avalonia.RenderTests\Avalonia.RenderTests.projitems*{48840edd-24bf-495d-911e-2eb12ae75d3b}*SharedItemsImports = 13 - src\Shared\PlatformSupport\PlatformSupport.projitems*{54f237d5-a70a-4752-9656-0c70b1a7b047}*SharedItemsImports = 4 + src\Shared\PlatformSupport\PlatformSupport.projitems*{4a1abb09-9047-4bd5-a4ad-a055e52c5ee0}*SharedItemsImports = 4 samples\TestApplicationShared\TestApplicationShared.projitems*{78345174-5b52-4a14-b9fd-d5f2428137f0}*SharedItemsImports = 13 src\Shared\PlatformSupport\PlatformSupport.projitems*{7b92af71-6287-4693-9dcb-bd5b6e927e23}*SharedItemsImports = 4 - src\Shared\PlatformSupport\PlatformSupport.projitems*{811a76cf-1cf6-440f-963b-bbe31bd72a82}*SharedItemsImports = 4 src\Shared\PlatformSupport\PlatformSupport.projitems*{88060192-33d5-4932-b0f9-8bd2763e857d}*SharedItemsImports = 4 samples\TestApplicationShared\TestApplicationShared.projitems*{8c923867-8a8f-4f6b-8b80-47d9e8436166}*SharedItemsImports = 4 src\Shared\RenderHelpers\RenderHelpers.projitems*{925dd807-b651-475f-9f7c-cbeb974ce43d}*SharedItemsImports = 4 @@ -2242,6 +2243,46 @@ Global {FBCAF3D0-2808-4934-8E96-3F607594517B}.Release|Mono.Build.0 = Release|Any CPU {FBCAF3D0-2808-4934-8E96-3F607594517B}.Release|x86.ActiveCfg = Release|Any CPU {FBCAF3D0-2808-4934-8E96-3F607594517B}.Release|x86.Build.0 = Release|Any CPU + {4A1ABB09-9047-4BD5-A4AD-A055E52C5EE0}.Ad-Hoc|Any CPU.ActiveCfg = Release|Any CPU + {4A1ABB09-9047-4BD5-A4AD-A055E52C5EE0}.Ad-Hoc|Any CPU.Build.0 = Release|Any CPU + {4A1ABB09-9047-4BD5-A4AD-A055E52C5EE0}.Ad-Hoc|iPhone.ActiveCfg = Release|Any CPU + {4A1ABB09-9047-4BD5-A4AD-A055E52C5EE0}.Ad-Hoc|iPhone.Build.0 = Release|Any CPU + {4A1ABB09-9047-4BD5-A4AD-A055E52C5EE0}.Ad-Hoc|iPhoneSimulator.ActiveCfg = Release|Any CPU + {4A1ABB09-9047-4BD5-A4AD-A055E52C5EE0}.Ad-Hoc|iPhoneSimulator.Build.0 = Release|Any CPU + {4A1ABB09-9047-4BD5-A4AD-A055E52C5EE0}.Ad-Hoc|Mono.ActiveCfg = Release|Any CPU + {4A1ABB09-9047-4BD5-A4AD-A055E52C5EE0}.Ad-Hoc|Mono.Build.0 = Release|Any CPU + {4A1ABB09-9047-4BD5-A4AD-A055E52C5EE0}.Ad-Hoc|x86.ActiveCfg = Release|Any CPU + {4A1ABB09-9047-4BD5-A4AD-A055E52C5EE0}.Ad-Hoc|x86.Build.0 = Release|Any CPU + {4A1ABB09-9047-4BD5-A4AD-A055E52C5EE0}.AppStore|Any CPU.ActiveCfg = Release|Any CPU + {4A1ABB09-9047-4BD5-A4AD-A055E52C5EE0}.AppStore|Any CPU.Build.0 = Release|Any CPU + {4A1ABB09-9047-4BD5-A4AD-A055E52C5EE0}.AppStore|iPhone.ActiveCfg = Release|Any CPU + {4A1ABB09-9047-4BD5-A4AD-A055E52C5EE0}.AppStore|iPhone.Build.0 = Release|Any CPU + {4A1ABB09-9047-4BD5-A4AD-A055E52C5EE0}.AppStore|iPhoneSimulator.ActiveCfg = Release|Any CPU + {4A1ABB09-9047-4BD5-A4AD-A055E52C5EE0}.AppStore|iPhoneSimulator.Build.0 = Release|Any CPU + {4A1ABB09-9047-4BD5-A4AD-A055E52C5EE0}.AppStore|Mono.ActiveCfg = Release|Any CPU + {4A1ABB09-9047-4BD5-A4AD-A055E52C5EE0}.AppStore|Mono.Build.0 = Release|Any CPU + {4A1ABB09-9047-4BD5-A4AD-A055E52C5EE0}.AppStore|x86.ActiveCfg = Release|Any CPU + {4A1ABB09-9047-4BD5-A4AD-A055E52C5EE0}.AppStore|x86.Build.0 = Release|Any CPU + {4A1ABB09-9047-4BD5-A4AD-A055E52C5EE0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4A1ABB09-9047-4BD5-A4AD-A055E52C5EE0}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4A1ABB09-9047-4BD5-A4AD-A055E52C5EE0}.Debug|iPhone.ActiveCfg = Debug|Any CPU + {4A1ABB09-9047-4BD5-A4AD-A055E52C5EE0}.Debug|iPhone.Build.0 = Debug|Any CPU + {4A1ABB09-9047-4BD5-A4AD-A055E52C5EE0}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU + {4A1ABB09-9047-4BD5-A4AD-A055E52C5EE0}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU + {4A1ABB09-9047-4BD5-A4AD-A055E52C5EE0}.Debug|Mono.ActiveCfg = Debug|Any CPU + {4A1ABB09-9047-4BD5-A4AD-A055E52C5EE0}.Debug|Mono.Build.0 = Debug|Any CPU + {4A1ABB09-9047-4BD5-A4AD-A055E52C5EE0}.Debug|x86.ActiveCfg = Debug|Any CPU + {4A1ABB09-9047-4BD5-A4AD-A055E52C5EE0}.Debug|x86.Build.0 = Debug|Any CPU + {4A1ABB09-9047-4BD5-A4AD-A055E52C5EE0}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4A1ABB09-9047-4BD5-A4AD-A055E52C5EE0}.Release|Any CPU.Build.0 = Release|Any CPU + {4A1ABB09-9047-4BD5-A4AD-A055E52C5EE0}.Release|iPhone.ActiveCfg = Release|Any CPU + {4A1ABB09-9047-4BD5-A4AD-A055E52C5EE0}.Release|iPhone.Build.0 = Release|Any CPU + {4A1ABB09-9047-4BD5-A4AD-A055E52C5EE0}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU + {4A1ABB09-9047-4BD5-A4AD-A055E52C5EE0}.Release|iPhoneSimulator.Build.0 = Release|Any CPU + {4A1ABB09-9047-4BD5-A4AD-A055E52C5EE0}.Release|Mono.ActiveCfg = Release|Any CPU + {4A1ABB09-9047-4BD5-A4AD-A055E52C5EE0}.Release|Mono.Build.0 = Release|Any CPU + {4A1ABB09-9047-4BD5-A4AD-A055E52C5EE0}.Release|x86.ActiveCfg = Release|Any CPU + {4A1ABB09-9047-4BD5-A4AD-A055E52C5EE0}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/samples/BindingTest/BindingTest.csproj b/samples/BindingTest/BindingTest.csproj index 3ed2671d0a..1587f42ad5 100644 --- a/samples/BindingTest/BindingTest.csproj +++ b/samples/BindingTest/BindingTest.csproj @@ -93,6 +93,10 @@ + + {4a1abb09-9047-4bd5-a4ad-a055e52c5ee0} + Avalonia.DotNetFrameworkRuntime + {3e53a01a-b331-47f3-b828-4a5717e77a24} Avalonia.Markup.Xaml diff --git a/samples/ControlCatalog.Desktop/App.config b/samples/ControlCatalog.Desktop/App.config index 7ef9d715f8..2231c71e63 100644 --- a/samples/ControlCatalog.Desktop/App.config +++ b/samples/ControlCatalog.Desktop/App.config @@ -1,13 +1,13 @@ - + - + - - + + diff --git a/samples/ControlCatalog.Desktop/ControlCatalog.Desktop.csproj b/samples/ControlCatalog.Desktop/ControlCatalog.Desktop.csproj index f42902b534..18a52743e3 100644 --- a/samples/ControlCatalog.Desktop/ControlCatalog.Desktop.csproj +++ b/samples/ControlCatalog.Desktop/ControlCatalog.Desktop.csproj @@ -60,6 +60,10 @@ + + {4a1abb09-9047-4bd5-a4ad-a055e52c5ee0} + Avalonia.DotNetFrameworkRuntime + {799a7bb5-3c2c-48b6-85a7-406a12c420da} Avalonia.DesignerSupport diff --git a/samples/TestApplication/TestApplication.csproj b/samples/TestApplication/TestApplication.csproj index bb18d97766..21594da6d0 100644 --- a/samples/TestApplication/TestApplication.csproj +++ b/samples/TestApplication/TestApplication.csproj @@ -83,6 +83,10 @@ + + {4a1abb09-9047-4bd5-a4ad-a055e52c5ee0} + Avalonia.DotNetFrameworkRuntime + {FB05AC90-89BA-4F2F-A924-F37875FB547C} Avalonia.Cairo diff --git a/samples/VirtualizationTest/App.config b/samples/VirtualizationTest/App.config index 7ef9d715f8..2231c71e63 100644 --- a/samples/VirtualizationTest/App.config +++ b/samples/VirtualizationTest/App.config @@ -1,13 +1,13 @@ - + - + - - + + diff --git a/samples/VirtualizationTest/VirtualizationTest.csproj b/samples/VirtualizationTest/VirtualizationTest.csproj index 98ca3ab970..8b81a012c1 100644 --- a/samples/VirtualizationTest/VirtualizationTest.csproj +++ b/samples/VirtualizationTest/VirtualizationTest.csproj @@ -83,6 +83,10 @@ + + {4a1abb09-9047-4bd5-a4ad-a055e52c5ee0} + Avalonia.DotNetFrameworkRuntime + {d211e587-d8bc-45b9-95a4-f297c8fa5200} Avalonia.Animation diff --git a/samples/XamlTestApplication/XamlTestApplication.csproj b/samples/XamlTestApplication/XamlTestApplication.csproj index f70928c398..d07f22cffb 100644 --- a/samples/XamlTestApplication/XamlTestApplication.csproj +++ b/samples/XamlTestApplication/XamlTestApplication.csproj @@ -91,6 +91,10 @@ + + {4a1abb09-9047-4bd5-a4ad-a055e52c5ee0} + Avalonia.DotNetFrameworkRuntime + {6417e941-21bc-467b-a771-0de389353ce6} Avalonia.Markup diff --git a/src/Android/Avalonia.Android/AndroidPlatform.cs b/src/Android/Avalonia.Android/AndroidPlatform.cs index 1840e90886..7ab6bf8a3c 100644 --- a/src/Android/Avalonia.Android/AndroidPlatform.cs +++ b/src/Android/Avalonia.Android/AndroidPlatform.cs @@ -49,7 +49,7 @@ namespace Avalonia.Android public void Init(Type applicationType) { - SharedPlatform.Register(applicationType.Assembly); + StandardRuntimePlatformServices.Register(applicationType.Assembly); } public IWindowImpl CreateWindow() diff --git a/src/Avalonia.Base/Avalonia.Base.csproj b/src/Avalonia.Base/Avalonia.Base.csproj index 107c0e7071..1dfc5cf65b 100644 --- a/src/Avalonia.Base/Avalonia.Base.csproj +++ b/src/Avalonia.Base/Avalonia.Base.csproj @@ -85,7 +85,7 @@ - + diff --git a/src/Avalonia.Base/AvaloniaDisposable.cs b/src/Avalonia.Base/AvaloniaDisposable.cs index 773c7a6e67..9e43a65f26 100644 --- a/src/Avalonia.Base/AvaloniaDisposable.cs +++ b/src/Avalonia.Base/AvaloniaDisposable.cs @@ -20,7 +20,7 @@ namespace Avalonia { IsDisposed = true; #if DEBUG_DISPOSE - DisposedAt = AvaloniaLocator.Current.GetService().GetStackTrace(); + DisposedAt = AvaloniaLocator.Current.GetService().GetStackTrace(); #endif DoDispose(); } diff --git a/src/Avalonia.Base/Platform/IPclPlatformWrapper.cs b/src/Avalonia.Base/Platform/IRuntimePlatform.cs similarity index 90% rename from src/Avalonia.Base/Platform/IPclPlatformWrapper.cs rename to src/Avalonia.Base/Platform/IRuntimePlatform.cs index 2a21f20f91..63a4795a74 100644 --- a/src/Avalonia.Base/Platform/IPclPlatformWrapper.cs +++ b/src/Avalonia.Base/Platform/IRuntimePlatform.cs @@ -7,7 +7,7 @@ using System.Threading.Tasks; namespace Avalonia.Platform { - public interface IPclPlatformWrapper + public interface IRuntimePlatform { Assembly[] GetLoadedAssemblies(); void PostThreadPoolItem(Action cb); diff --git a/src/Avalonia.Base/Threading/SingleThreadDispatcher.cs b/src/Avalonia.Base/Threading/SingleThreadDispatcher.cs index 815d95ac6e..76d47b30b0 100644 --- a/src/Avalonia.Base/Threading/SingleThreadDispatcher.cs +++ b/src/Avalonia.Base/Threading/SingleThreadDispatcher.cs @@ -33,7 +33,7 @@ namespace Avalonia.Threading } public IDisposable StartTimer(TimeSpan interval, Action tick) - => AvaloniaLocator.Current.GetService().StartSystemTimer(interval, + => AvaloniaLocator.Current.GetService().StartSystemTimer(interval, () => _timerJobRunner.Post(tick, DispatcherPriority.Normal)); public void Signal() => _evnt.Set(); @@ -50,7 +50,7 @@ namespace Avalonia.Threading public static Dispatcher StartNew(CancellationToken token) { var dispatcher = new SingleThreadDispatcher(); - AvaloniaLocator.Current.GetService().PostThreadPoolItem(() => + AvaloniaLocator.Current.GetService().PostThreadPoolItem(() => { dispatcher.MainLoop(token); }); diff --git a/src/Avalonia.Controls/AppBuilder.cs b/src/Avalonia.Controls/AppBuilder.cs index 8b3e0e731a..82698acde7 100644 --- a/src/Avalonia.Controls/AppBuilder.cs +++ b/src/Avalonia.Controls/AppBuilder.cs @@ -3,14 +3,25 @@ using System; using System.Reflection; +using Avalonia.Platform; namespace Avalonia.Controls { /// /// Initializes up platform-specific services for an . /// - public class AppBuilder + public abstract class AppBuilderBase where AppBuilder : AppBuilderBase, new() { + /// + /// Gets or sets the instance. + /// + public IRuntimePlatform RuntimePlatform { get; set; } + + /// + /// Gets or sets a method to call the initialize the runtime platform services (e. g. AssetLoader) + /// + public Action RuntimePlatformServices { get; set; } + /// /// Gets or sets the instance being initialized. /// @@ -32,6 +43,12 @@ namespace Avalonia.Controls /// public Action BeforeStartCallback { get; set; } + protected AppBuilderBase(IRuntimePlatform platform, Action platformSevices) + { + RuntimePlatform = platform; + RuntimePlatformServices = platformSevices; + } + /// /// Begin configuring an . /// @@ -57,6 +74,8 @@ namespace Avalonia.Controls }; } + protected AppBuilder Self => (AppBuilder) this; + /// /// Registers a callback to call before is called on the /// . @@ -66,7 +85,7 @@ namespace Avalonia.Controls public AppBuilder BeforeStarting(Action callback) { BeforeStartCallback = callback; - return this; + return Self; } /// @@ -77,7 +96,7 @@ namespace Avalonia.Controls where TMainWindow : Window, new() { Setup(); - BeforeStartCallback?.Invoke(this); + BeforeStartCallback?.Invoke(Self); var window = new TMainWindow(); window.Show(); @@ -91,7 +110,7 @@ namespace Avalonia.Controls public AppBuilder SetupWithoutStarting() { Setup(); - return this; + return Self; } /// @@ -102,7 +121,7 @@ namespace Avalonia.Controls public AppBuilder UseWindowingSubsystem(Action initializer) { WindowingSubsystem = initializer; - return this; + return Self; } /// @@ -120,7 +139,7 @@ namespace Avalonia.Controls public AppBuilder UseRenderingSubsystem(Action initializer) { RenderingSubsystem = initializer; - return this; + return Self; } /// @@ -140,23 +159,6 @@ namespace Avalonia.Controls init.Invoke(null, null); }; - public AppBuilder UsePlatformDetect() - { - var platformId = (int) - ((dynamic) Type.GetType("System.Environment").GetRuntimeProperty("OSVersion").GetValue(null)).Platform; - if (platformId == 4 || platformId == 6) - { - UseRenderingSubsystem("Avalonia.Cairo"); - UseWindowingSubsystem("Avalonia.Gtk"); - } - else - { - UseRenderingSubsystem("Avalonia.Direct2D1"); - UseWindowingSubsystem("Avalonia.Win32"); - } - return this; - } - /// /// Sets up the platform-speciic services for the . /// @@ -167,6 +169,11 @@ namespace Avalonia.Controls throw new InvalidOperationException("No App instance configured."); } + if (RuntimePlatformServices == null) + { + throw new InvalidOperationException("No runtime platform services configured."); + } + if (WindowingSubsystem == null) { throw new InvalidOperationException("No windowing system configured."); @@ -178,6 +185,7 @@ namespace Avalonia.Controls } Instance.RegisterServices(); + RuntimePlatformServices(); WindowingSubsystem(); RenderingSubsystem(); Instance.Initialize(); diff --git a/src/Avalonia.DesignerSupport/DesignerAssist.cs b/src/Avalonia.DesignerSupport/DesignerAssist.cs index 8787144665..95e7345227 100644 --- a/src/Avalonia.DesignerSupport/DesignerAssist.cs +++ b/src/Avalonia.DesignerSupport/DesignerAssist.cs @@ -37,8 +37,11 @@ namespace Avalonia.DesignerSupport { Design.IsDesignMode = true; Api = new DesignerApi(shared) {UpdateXaml = UpdateXaml, UpdateXaml2 = UpdateXaml2, SetScalingFactor = SetScalingFactor}; - var plat = (IPclPlatformWrapper) Activator.CreateInstance(Assembly.Load(new AssemblyName("Avalonia.Win32")) - .DefinedTypes.First(typeof (IPclPlatformWrapper).GetTypeInfo().IsAssignableFrom).AsType()); + + var runtimeAssembly = Assembly.Load(new AssemblyName("Avalonia.DotNetFrameworkRuntime")); + + var plat = (IRuntimePlatform) Activator.CreateInstance(runtimeAssembly + .DefinedTypes.First(typeof (IRuntimePlatform).GetTypeInfo().IsAssignableFrom).AsType()); TypeInfo app = null; var asms = plat.GetLoadedAssemblies(); @@ -58,7 +61,12 @@ namespace Avalonia.DesignerSupport //Ignore, Assembly.DefinedTypes threw an exception, we can't do anything about that } } - AppBuilder.Configure(app == null ? new DesignerApp() : (Application) Activator.CreateInstance(app.AsType())) + + var builderType = runtimeAssembly.GetType("Avalonia.AppBuilder"); + + var builder = (dynamic)Activator.CreateInstance(builderType, + app == null ? new DesignerApp() : (Application) Activator.CreateInstance(app.AsType())); + builder .UseWindowingSubsystem("Avalonia.Win32") .UseRenderingSubsystem("Avalonia.Direct2D1") .SetupWithoutStarting(); diff --git a/src/Gtk/Avalonia.Cairo/CairoPlatform.cs b/src/Gtk/Avalonia.Cairo/CairoPlatform.cs index 5b85e6c68f..3b0d7d08da 100644 --- a/src/Gtk/Avalonia.Cairo/CairoPlatform.cs +++ b/src/Gtk/Avalonia.Cairo/CairoPlatform.cs @@ -12,7 +12,7 @@ namespace Avalonia { public static class GtkApplicationExtensions { - public static AppBuilder UseCairo(this AppBuilder builder) + public static T UseCairo(this T builder) where T : AppBuilderBase, new() { builder.RenderingSubsystem = Avalonia.Cairo.CairoPlatform.Initialize; return builder; diff --git a/src/Gtk/Avalonia.Gtk/Avalonia.Gtk.csproj b/src/Gtk/Avalonia.Gtk/Avalonia.Gtk.csproj index fe075bca77..2a47aa99fa 100644 --- a/src/Gtk/Avalonia.Gtk/Avalonia.Gtk.csproj +++ b/src/Gtk/Avalonia.Gtk/Avalonia.Gtk.csproj @@ -95,5 +95,4 @@ - \ No newline at end of file diff --git a/src/Gtk/Avalonia.Gtk/GtkPlatform.cs b/src/Gtk/Avalonia.Gtk/GtkPlatform.cs index 4169f5949d..c8246fc9f5 100644 --- a/src/Gtk/Avalonia.Gtk/GtkPlatform.cs +++ b/src/Gtk/Avalonia.Gtk/GtkPlatform.cs @@ -8,14 +8,13 @@ using Avalonia.Controls.Platform; using Avalonia.Input.Platform; using Avalonia.Input; using Avalonia.Platform; -using Avalonia.Shared.PlatformSupport; using Avalonia.Controls; namespace Avalonia { public static class GtkApplicationExtensions { - public static AppBuilder UseGtk(this AppBuilder builder) + public static T UseGtk(this T builder) where T : AppBuilderBase, new() { builder.WindowingSubsystem = Avalonia.Gtk.GtkPlatform.Initialize; return builder; @@ -56,7 +55,6 @@ namespace Avalonia.Gtk .Bind().ToConstant(s_instance) .Bind().ToSingleton() .Bind().ToConstant(s_instance); - SharedPlatform.Register(); _uiThread = Thread.CurrentThread; } diff --git a/src/Markup/Avalonia.Markup.Xaml/Context/AvaloniaNamespaceRegistry.cs b/src/Markup/Avalonia.Markup.Xaml/Context/AvaloniaNamespaceRegistry.cs index 11205972fe..b591654621 100644 --- a/src/Markup/Avalonia.Markup.Xaml/Context/AvaloniaNamespaceRegistry.cs +++ b/src/Markup/Avalonia.Markup.Xaml/Context/AvaloniaNamespaceRegistry.cs @@ -168,7 +168,7 @@ namespace Avalonia.Markup.Xaml.Context private void ScanNewAssemblies() { IEnumerable assemblies = AvaloniaLocator.Current - .GetService() + .GetService() ?.GetLoadedAssemblies(); if (assemblies != null) diff --git a/src/Shared/PlatformSupport/PlatformSupport.projitems b/src/Shared/PlatformSupport/PlatformSupport.projitems index 0bf2184e09..a9b6a8fa2a 100644 --- a/src/Shared/PlatformSupport/PlatformSupport.projitems +++ b/src/Shared/PlatformSupport/PlatformSupport.projitems @@ -1,4 +1,4 @@ - + $(MSBuildAllProjects);$(MSBuildThisFileFullPath) @@ -10,7 +10,7 @@ - - + + \ No newline at end of file diff --git a/src/Shared/PlatformSupport/PclPlatformWrapper.cs b/src/Shared/PlatformSupport/StandardRuntimePlatform.cs similarity index 93% rename from src/Shared/PlatformSupport/PclPlatformWrapper.cs rename to src/Shared/PlatformSupport/StandardRuntimePlatform.cs index ba705c7634..9c0b7bcc73 100644 --- a/src/Shared/PlatformSupport/PclPlatformWrapper.cs +++ b/src/Shared/PlatformSupport/StandardRuntimePlatform.cs @@ -10,7 +10,7 @@ using Avalonia.Platform; namespace Avalonia.Shared.PlatformSupport { - internal class PclPlatformWrapper : IPclPlatformWrapper + internal class StandardRuntimePlatform : IRuntimePlatform { public Assembly[] GetLoadedAssemblies() => AppDomain.CurrentDomain.GetAssemblies(); public void PostThreadPoolItem(Action cb) => ThreadPool.UnsafeQueueUserWorkItem(_ => cb(), null); @@ -23,6 +23,8 @@ namespace Avalonia.Shared.PlatformSupport return Disposable.Create(() => timer.Dispose()); } + + public string GetStackTrace() => Environment.StackTrace; } } \ No newline at end of file diff --git a/src/Shared/PlatformSupport/SharedPlatform.cs b/src/Shared/PlatformSupport/StandardRuntimePlatformServices.cs similarity index 74% rename from src/Shared/PlatformSupport/SharedPlatform.cs rename to src/Shared/PlatformSupport/StandardRuntimePlatformServices.cs index 0db01367bb..70601fdf4a 100644 --- a/src/Shared/PlatformSupport/SharedPlatform.cs +++ b/src/Shared/PlatformSupport/StandardRuntimePlatformServices.cs @@ -6,12 +6,12 @@ using Avalonia.Platform; namespace Avalonia.Shared.PlatformSupport { - static class SharedPlatform + static class StandardRuntimePlatformServices { public static void Register(Assembly assembly = null) { AvaloniaLocator.CurrentMutable - .Bind().ToSingleton() + .Bind().ToSingleton() .Bind().ToConstant(new AssetLoader(assembly)); } } diff --git a/src/Skia/Avalonia.Skia/SkiaPlatform.cs b/src/Skia/Avalonia.Skia/SkiaPlatform.cs index 1d93089e45..3f9e49d3c3 100644 --- a/src/Skia/Avalonia.Skia/SkiaPlatform.cs +++ b/src/Skia/Avalonia.Skia/SkiaPlatform.cs @@ -8,7 +8,7 @@ namespace Avalonia { public static class SkiaApplicationExtensions { - public static AppBuilder UseSkia(this AppBuilder builder) + public static T UseSkia(this T builder) where T : AppBuilderBase, new() { builder.RenderingSubsystem = Avalonia.Skia.SkiaPlatform.Initialize; return builder; diff --git a/src/Windows/Avalonia.Direct2D1/Direct2D1Platform.cs b/src/Windows/Avalonia.Direct2D1/Direct2D1Platform.cs index 6ad64aced1..10f32861e8 100644 --- a/src/Windows/Avalonia.Direct2D1/Direct2D1Platform.cs +++ b/src/Windows/Avalonia.Direct2D1/Direct2D1Platform.cs @@ -12,7 +12,7 @@ namespace Avalonia { public static class Direct2DApplicationExtensions { - public static AppBuilder UseDirect2D1(this AppBuilder builder) + public static T UseDirect2D1(this T builder) where T : AppBuilderBase, new() { builder.RenderingSubsystem = Avalonia.Direct2D1.Direct2D1Platform.Initialize; return builder; diff --git a/src/Windows/Avalonia.Win32/Avalonia.Win32.csproj b/src/Windows/Avalonia.Win32/Avalonia.Win32.csproj index e9627e2033..3fdde9339f 100644 --- a/src/Windows/Avalonia.Win32/Avalonia.Win32.csproj +++ b/src/Windows/Avalonia.Win32/Avalonia.Win32.csproj @@ -114,7 +114,6 @@ -