Merge Common to Desktop
This commit is contained in:
parent
26915defe1
commit
e9c6e14965
40 changed files with 447 additions and 282 deletions
75
app/InkForge.Desktop/App.axaml.cs
Normal file
75
app/InkForge.Desktop/App.axaml.cs
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Controls.ApplicationLifetimes;
|
||||
using Avalonia.Markup.Xaml;
|
||||
|
||||
using InkForge.Desktop.ViewModels;
|
||||
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.FileProviders;
|
||||
|
||||
using ReactiveUI;
|
||||
|
||||
using Splat;
|
||||
using Splat.Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace InkForge.Desktop;
|
||||
|
||||
public partial class App : Application
|
||||
{
|
||||
public static readonly StyledProperty<IServiceProvider> ServiceProviderProperty
|
||||
= AvaloniaProperty.Register<App, IServiceProvider>(
|
||||
name: nameof(ServiceProvider),
|
||||
coerce: OnServiceProviderChanged);
|
||||
|
||||
public IServiceProvider ServiceProvider => GetValue(ServiceProviderProperty);
|
||||
|
||||
public static void Configure(IServiceCollection services, IConfigurationManager configuration)
|
||||
{
|
||||
configuration.SetBasePath(AppContext.BaseDirectory);
|
||||
configuration.AddJsonFile(
|
||||
new ManifestEmbeddedFileProvider(typeof(App).Assembly),
|
||||
"Properties/appsettings.json", false, false);
|
||||
configuration.AddJsonFile(
|
||||
Path.Combine(
|
||||
Environment.GetFolderPath(
|
||||
Environment.SpecialFolder.ApplicationData,
|
||||
Environment.SpecialFolderOption.DoNotVerify),
|
||||
"InkForge",
|
||||
"usersettings.json"), true, true);
|
||||
configuration.AddJsonFile("appsettings.json", true, true);
|
||||
|
||||
services.UseMicrosoftDependencyResolver();
|
||||
Locator.CurrentMutable.InitializeSplat();
|
||||
Locator.CurrentMutable.InitializeReactiveUI();
|
||||
|
||||
services.AddInkForge();
|
||||
}
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
AvaloniaXamlLoader.Load(this);
|
||||
}
|
||||
|
||||
public override void OnFrameworkInitializationCompleted()
|
||||
{
|
||||
var viewModel = ActivatorUtilities.GetServiceOrCreateInstance<AppViewModel>(ServiceProvider);
|
||||
var view = ViewLocator.Current.ResolveView(viewModel)!;
|
||||
view.ViewModel = viewModel;
|
||||
_ = ApplicationLifetime switch
|
||||
{
|
||||
IClassicDesktopStyleApplicationLifetime desktop => desktop.MainWindow = view as Window,
|
||||
ISingleViewApplicationLifetime singleView => singleView.MainView = view as Control,
|
||||
_ => throw new NotSupportedException(),
|
||||
};
|
||||
|
||||
base.OnFrameworkInitializationCompleted();
|
||||
}
|
||||
|
||||
private static IServiceProvider OnServiceProviderChanged(AvaloniaObject @object, IServiceProvider provider)
|
||||
{
|
||||
provider.UseMicrosoftDependencyResolver();
|
||||
return provider;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue