Added: - New `ProgressService` class for managing progress indicators. - New `AssetDatabase`, `AssetOpenHandlerAttribute`, and `AsyncAssetOpenHandlerAttribute` classes for asset handling. - `Ghost.UnitTest` project for unit testing with associated files and configurations. Changed: - `ActivationHandler` class to ensure correct handling of `LaunchActivatedEventArgs`. - `App.xaml.cs` to register `INotificationService` and `IProgressService`, replacing `StackedNotificationService`. - `OnLaunched` method in `App.xaml.cs` to correctly call `ActivationHandler.Handle(args)` and start the host. - `INavigationAware` interface from internal to public for broader access. - `EditorState.cs` to activate `EditorApplication` with the current service provider. - Property names in `AssetItem` and `ExplorerItem` structs to `Name` and `FullName`. - `NotificationService` class to implement `INotificationService` and refactor notification handling. - `AssetPathToGlyphConverter` to handle file extensions consistently. - Bindings in `ProjectPage.xaml` and `ProjectPage.xaml.cs` to use `FullName` instead of `Path`. - `EngineEditorWindow` and `LandingWindow` classes to utilize new notification and progress services. - `Logger` class to include a new method for logging errors with exceptions. Updated: - Manifest files and project files to reflect new structure and dependencies. - Solution file `GhostEngine.sln` to include the new unit test project. - Added several new test classes and methods in `UnitTests.cs`.
102 lines
3.1 KiB
C#
102 lines
3.1 KiB
C#
using Ghost.App.Infrastructures.AppState;
|
|
using Ghost.App.Services;
|
|
using Ghost.App.Utilities;
|
|
using Ghost.Editor.Services.Contracts;
|
|
using Ghost.Engine.Services;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Hosting;
|
|
using Microsoft.UI.Xaml;
|
|
using System;
|
|
|
|
// To learn more about WinUI, the WinUI project structure,
|
|
// and more about our project templates, see: http://aka.ms/winui-project-info.
|
|
|
|
namespace Ghost.App;
|
|
|
|
/// <summary>
|
|
/// Provides application-specific behavior to supplement the default Application class.
|
|
/// </summary>
|
|
public partial class GhostApplication : Application
|
|
{
|
|
private Window? _window;
|
|
|
|
internal static Window? Window
|
|
{
|
|
get => (Current as GhostApplication)!._window;
|
|
set
|
|
{
|
|
if (Current is GhostApplication app)
|
|
{
|
|
app._window = value;
|
|
}
|
|
}
|
|
}
|
|
|
|
internal IHost Host
|
|
{
|
|
get;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Initializes the singleton application object. This is the first line of authored code
|
|
/// executed, and as such is the logical equivalent of main() or WinMain().
|
|
/// </summary>
|
|
internal GhostApplication()
|
|
{
|
|
InitializeComponent();
|
|
|
|
Host = Microsoft.Extensions.Hosting.Host.
|
|
CreateDefaultBuilder().
|
|
UseContentRoot(AppContext.BaseDirectory).
|
|
ConfigureServices((context, services) =>
|
|
{
|
|
HostHelper.AddLandingScope(context, services);
|
|
HostHelper.AddEngineScope(context, services);
|
|
|
|
services.AddSingleton<AppStateMachine>();
|
|
services.AddSingleton<INotificationService, NotificationService>();
|
|
services.AddSingleton<IProgressService, ProgressService>();
|
|
})
|
|
.Build();
|
|
|
|
UnhandledException += App_UnhandledException;
|
|
}
|
|
|
|
internal static IServiceScope CreateScope()
|
|
{
|
|
return (Current as GhostApplication)!.Host.Services.CreateScope();
|
|
}
|
|
|
|
public static T GetService<T>() where T : class
|
|
{
|
|
if ((Current as GhostApplication)!.Host.Services.GetService(typeof(T)) is not T service)
|
|
{
|
|
throw new ArgumentException($"{typeof(T)} needs to be registered in ConfigureServices within App.xaml.cs.");
|
|
}
|
|
|
|
return service;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Invoked when the application is launched.
|
|
/// </summary>
|
|
/// <param name="args">Details about the launch request and process.</param>
|
|
protected override async void OnLaunched(LaunchActivatedEventArgs args)
|
|
{
|
|
base.OnLaunched(args);
|
|
|
|
Host.Start();
|
|
ActivationHandler.Handle(args);
|
|
|
|
var stateMachine = GetService<AppStateMachine>();
|
|
stateMachine.RegisterState(StateKey.Landing, () => new LandingState());
|
|
stateMachine.RegisterState(StateKey.EngineEditor, () => new EditorState());
|
|
|
|
await stateMachine.TransitionToAsync(StateKey.Landing);
|
|
}
|
|
|
|
private void App_UnhandledException(object sender, Microsoft.UI.Xaml.UnhandledExceptionEventArgs e)
|
|
{
|
|
Logger.LogError(e.Exception);
|
|
}
|
|
} |