From 2a7ff864bf779322d7d5558a408b93b318fe6b5d Mon Sep 17 00:00:00 2001 From: AliveDevil Date: Thu, 8 Feb 2024 00:54:45 +0100 Subject: [PATCH] Add core UI --- Directory.Packages.props | 8 ++ InkForge.sln | 14 ++-- app/InkForge.Common/App.axaml | 11 +++ app/InkForge.Common/App.axaml.cs | 45 +++++++++++ app/InkForge.Common/InkForge.Common.csproj | 22 ++++++ app/InkForge.Desktop/InkForge.Desktop.csproj | 10 +++ app/InkForge.Desktop/Program.cs | 80 +++++++++++++++++++- app/InkForge/InkForge.csproj | 10 --- 8 files changed, 181 insertions(+), 19 deletions(-) create mode 100644 app/InkForge.Common/App.axaml create mode 100644 app/InkForge.Common/App.axaml.cs create mode 100644 app/InkForge.Common/InkForge.Common.csproj delete mode 100644 app/InkForge/InkForge.csproj diff --git a/Directory.Packages.props b/Directory.Packages.props index afcde05..a950adb 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -4,6 +4,10 @@ true + + + + @@ -12,7 +16,11 @@ + + + + diff --git a/InkForge.sln b/InkForge.sln index 2b33bc8..314516f 100644 --- a/InkForge.sln +++ b/InkForge.sln @@ -13,8 +13,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "InkForge.Sqlite", "shared\m EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "app", "app", "{84CBD204-9573-4472-9334-68FB360BD6ED}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "InkForge", "app\InkForge\InkForge.csproj", "{D44F8BF4-CB4D-407D-B623-495165BD3A6E}" -EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "InkForge.Desktop", "app\InkForge.Desktop\InkForge.Desktop.csproj", "{5AFA8AD9-9230-4218-BBFD-BD75F1E752DC}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "InkForge.Api", "InkForge.Api\InkForge.Api.csproj", "{DEB06372-672A-412E-89B1-E4D97EEBBA25}" @@ -29,6 +27,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "design", "design", "{C78684 EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "InkForge.Migrations", "design\InkForge.Migrations\InkForge.Migrations.csproj", "{8DF3397E-2717-49F0-9592-82ABE9327A73}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "InkForge.Common", "app\InkForge.Common\InkForge.Common.csproj", "{DCE2DCD6-D15C-4F0D-8D7F-22FF82F62F6F}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -46,10 +46,6 @@ Global {C504E59E-16CB-41CD-B9C7-F07E9A8A2E16}.Debug|Any CPU.Build.0 = Debug|Any CPU {C504E59E-16CB-41CD-B9C7-F07E9A8A2E16}.Release|Any CPU.ActiveCfg = Release|Any CPU {C504E59E-16CB-41CD-B9C7-F07E9A8A2E16}.Release|Any CPU.Build.0 = Release|Any CPU - {D44F8BF4-CB4D-407D-B623-495165BD3A6E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {D44F8BF4-CB4D-407D-B623-495165BD3A6E}.Debug|Any CPU.Build.0 = Debug|Any CPU - {D44F8BF4-CB4D-407D-B623-495165BD3A6E}.Release|Any CPU.ActiveCfg = Release|Any CPU - {D44F8BF4-CB4D-407D-B623-495165BD3A6E}.Release|Any CPU.Build.0 = Release|Any CPU {5AFA8AD9-9230-4218-BBFD-BD75F1E752DC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {5AFA8AD9-9230-4218-BBFD-BD75F1E752DC}.Debug|Any CPU.Build.0 = Debug|Any CPU {5AFA8AD9-9230-4218-BBFD-BD75F1E752DC}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -70,14 +66,18 @@ Global {8DF3397E-2717-49F0-9592-82ABE9327A73}.Debug|Any CPU.Build.0 = Debug|Any CPU {8DF3397E-2717-49F0-9592-82ABE9327A73}.Release|Any CPU.ActiveCfg = Release|Any CPU {8DF3397E-2717-49F0-9592-82ABE9327A73}.Release|Any CPU.Build.0 = Release|Any CPU + {DCE2DCD6-D15C-4F0D-8D7F-22FF82F62F6F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {DCE2DCD6-D15C-4F0D-8D7F-22FF82F62F6F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {DCE2DCD6-D15C-4F0D-8D7F-22FF82F62F6F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {DCE2DCD6-D15C-4F0D-8D7F-22FF82F62F6F}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(NestedProjects) = preSolution {DD595B76-5FDE-4C37-822E-CB58BBB02C8C} = {C73D8E17-EA0A-4206-91D4-9E5BD63B3DB0} {12D30DD9-8615-4947-A13D-88E6478242E4} = {C73D8E17-EA0A-4206-91D4-9E5BD63B3DB0} {C504E59E-16CB-41CD-B9C7-F07E9A8A2E16} = {12D30DD9-8615-4947-A13D-88E6478242E4} - {D44F8BF4-CB4D-407D-B623-495165BD3A6E} = {84CBD204-9573-4472-9334-68FB360BD6ED} {5AFA8AD9-9230-4218-BBFD-BD75F1E752DC} = {84CBD204-9573-4472-9334-68FB360BD6ED} {F8A7563F-2647-4623-88E7-470D20F25E93} = {A9F8087F-F148-47A5-94AE-F7B6E1D33096} {8DF3397E-2717-49F0-9592-82ABE9327A73} = {C7868400-84D7-45C5-B594-C30777EE5191} + {DCE2DCD6-D15C-4F0D-8D7F-22FF82F62F6F} = {84CBD204-9573-4472-9334-68FB360BD6ED} EndGlobalSection EndGlobal diff --git a/app/InkForge.Common/App.axaml b/app/InkForge.Common/App.axaml new file mode 100644 index 0000000..9cccb4b --- /dev/null +++ b/app/InkForge.Common/App.axaml @@ -0,0 +1,11 @@ + + + + + + + \ No newline at end of file diff --git a/app/InkForge.Common/App.axaml.cs b/app/InkForge.Common/App.axaml.cs new file mode 100644 index 0000000..b92102b --- /dev/null +++ b/app/InkForge.Common/App.axaml.cs @@ -0,0 +1,45 @@ +using Avalonia; +using Avalonia.Controls; +using Avalonia.Controls.ApplicationLifetimes; +using Avalonia.Markup.Xaml; + +using Microsoft.Extensions.Hosting; + +using ReactiveUI; + +namespace InkForge.Common; + +public partial class App : Application +{ + public static readonly StyledProperty HostProperty = AvaloniaProperty.Register("Host"); + + public IHost Host => GetValue(HostProperty); + + public IServiceProvider Services => Host.Services; + + public override void Initialize() + { + AvaloniaXamlLoader.Load(this); + } + + public override void OnFrameworkInitializationCompleted() + { + // var viewModel = Services.Activate(); + // var view = ViewLocator.Current.ResolveView(viewModel); + // switch (ApplicationLifetime) + // { + // case IClassicDesktopStyleApplicationLifetime desktop: + // desktop.MainWindow = view as Window; + // break; + + // case ISingleViewApplicationLifetime singleView: + // singleView.MainView = view as Control; + // break; + + // default: + // throw new NotSupportedException(); + // } + + base.OnFrameworkInitializationCompleted(); + } +} diff --git a/app/InkForge.Common/InkForge.Common.csproj b/app/InkForge.Common/InkForge.Common.csproj new file mode 100644 index 0000000..cc5502b --- /dev/null +++ b/app/InkForge.Common/InkForge.Common.csproj @@ -0,0 +1,22 @@ + + + + net8.0 + InkForge + enable + enable + + + + + + + + + + + + + + + diff --git a/app/InkForge.Desktop/InkForge.Desktop.csproj b/app/InkForge.Desktop/InkForge.Desktop.csproj index f9b0b6b..9d2d36f 100644 --- a/app/InkForge.Desktop/InkForge.Desktop.csproj +++ b/app/InkForge.Desktop/InkForge.Desktop.csproj @@ -5,6 +5,16 @@ net8.0 enable enable + InkForge + + + + + + + + + diff --git a/app/InkForge.Desktop/Program.cs b/app/InkForge.Desktop/Program.cs index 3751555..4b67b25 100644 --- a/app/InkForge.Desktop/Program.cs +++ b/app/InkForge.Desktop/Program.cs @@ -1,2 +1,78 @@ -// See https://aka.ms/new-console-template for more information -Console.WriteLine("Hello, World!"); +using Avalonia; +using Avalonia.ReactiveUI; +using Avalonia.Threading; + +using InkForge.Common; + +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; + +using ReactiveUI; + +using Splat; +using Splat.Microsoft.Extensions.DependencyInjection; + +static class Program +{ + [STAThread] + public static void Main(string[] args) + => BuildAvaloniaApp() + .UseMicrosoftExtensionsHosting(args) + .StartWithClassicDesktopLifetime(args); + + public static AppBuilder BuildAvaloniaApp() + => AppBuilder.Configure() + .UsePlatformDetect() + .UseReactiveUI() + .LogToTrace(); + + private static void ConfigureServices(IServiceCollection services) + { + services.UseMicrosoftDependencyResolver(); + var mutableResolver = Locator.CurrentMutable; + mutableResolver.InitializeSplat(); + mutableResolver.InitializeReactiveUI(); + + services.AddHttpClient(); + + // services.UseFactories(); + // services.AddViewModelFactory(); + // services.AddTransient, MainWindow>(); + } + + private static void OnSetup(this HostApplicationBuilder hostBuilder, AppBuilder appBuilder) + { + var dispatcher = Dispatcher.UIThread; + + var app = appBuilder.Instance!; + hostBuilder.Services + .AddSingleton(app) + .AddSingleton(app.ApplicationLifetime!) + .AddSingleton(app.PlatformSettings!) + .AddSingleton(dispatcher); + + var host = hostBuilder.Build(); + host.Services.UseMicrosoftDependencyResolver(); + app.SetValue(App.HostProperty, host); + dispatcher.ShutdownStarted += host.Shutdown; + + dispatcher.Post(static arg => + { + var host = (IHost)arg!; + host.StartAsync() + .GetAwaiter() + .GetResult(); + }, host, DispatcherPriority.Send); + } + + private static void Shutdown(this IHost host, object? sender, EventArgs e) + => host.StopAsync().GetAwaiter().GetResult(); + + private static AppBuilder UseMicrosoftExtensionsHosting(this AppBuilder builder, string[] args) + { + var hostBuilder = Host.CreateApplicationBuilder(args); + ConfigureServices(hostBuilder.Services); + builder.AfterSetup(hostBuilder.OnSetup); + return builder; + } +} diff --git a/app/InkForge/InkForge.csproj b/app/InkForge/InkForge.csproj deleted file mode 100644 index 26da779..0000000 --- a/app/InkForge/InkForge.csproj +++ /dev/null @@ -1,10 +0,0 @@ - - - - net8.0 - InkForge - enable - enable - - -