Gui startup optimizations
This commit is contained in:
@@ -85,7 +85,11 @@ public partial class MainWindowViewModel : IMainWindowViewModel
|
||||
_modalService.AllModalClosed += (_, _) => FocusDefaultElement?.Invoke();
|
||||
_instanceMessageHandler.ShowWindow += () => ShowWindow?.Invoke();
|
||||
|
||||
Task.Run(async () => await _lifecycleService.InitStartupHandlersAsync()).Wait();
|
||||
Task.Run(async () =>
|
||||
{
|
||||
await Task.Delay(100);
|
||||
await _lifecycleService.InitStartupHandlersAsync();
|
||||
});
|
||||
}
|
||||
|
||||
public void ProcessKeyDown(KeyEventArgs e)
|
||||
|
||||
@@ -51,39 +51,46 @@ public partial class MainWindow : Window, IUiAccessor
|
||||
_initializer = initializer;
|
||||
}
|
||||
|
||||
private void OnWindowOpened(object sender, EventArgs e)
|
||||
private async void OnWindowOpened(object sender, EventArgs e)
|
||||
{
|
||||
if (DataContext is not MainWindowViewModel && !Design.IsDesignMode)
|
||||
try
|
||||
{
|
||||
_initializer?.Invoke();
|
||||
|
||||
_logger = DI.ServiceProvider.GetService<ILogger<MainWindow>>();
|
||||
_modalService = DI.ServiceProvider.GetRequiredService<IModalService>();
|
||||
DI.ServiceProvider.GetRequiredService<SystemClipboardService>().UiAccessor = this;
|
||||
|
||||
ReadInputContainer.PropertyChanged += ReadInputContainerOnPropertyChanged;
|
||||
|
||||
_logger?.LogInformation(
|
||||
$"{nameof(MainWindow)} opened, starting {nameof(MainWindowViewModel)} initialization...");
|
||||
|
||||
try
|
||||
if (DataContext is not MainWindowViewModel && !Design.IsDesignMode)
|
||||
{
|
||||
var viewModel = DI.ServiceProvider.GetRequiredService<MainWindowViewModel>();
|
||||
viewModel.FocusDefaultElement = () => Focus();
|
||||
viewModel.ShowWindow = Activate;
|
||||
ViewModel = viewModel;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger?.LogError(ex, "Error initializing {ViewModel}", nameof(MainWindowViewModel));
|
||||
if (DataContext is IMainWindowViewModelBase mainWindowViewModelBase)
|
||||
await Task.Delay(100);
|
||||
_initializer?.Invoke();
|
||||
|
||||
_logger = DI.ServiceProvider.GetService<ILogger<MainWindow>>();
|
||||
_modalService = DI.ServiceProvider.GetRequiredService<IModalService>();
|
||||
DI.ServiceProvider.GetRequiredService<SystemClipboardService>().UiAccessor = this;
|
||||
|
||||
ReadInputContainer.PropertyChanged += ReadInputContainerOnPropertyChanged;
|
||||
|
||||
_logger?.LogInformation(
|
||||
$"{nameof(MainWindow)} opened, starting {nameof(MainWindowViewModel)} initialization...");
|
||||
|
||||
try
|
||||
{
|
||||
mainWindowViewModelBase.FatalError.SetValueSafe(
|
||||
$"Error initializing {nameof(MainWindowViewModel)}: " + ex.Message
|
||||
);
|
||||
var viewModel = DI.ServiceProvider.GetRequiredService<MainWindowViewModel>();
|
||||
viewModel.FocusDefaultElement = () => Focus();
|
||||
viewModel.ShowWindow = Activate;
|
||||
ViewModel = viewModel;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger?.LogError(ex, "Error initializing {ViewModel}", nameof(MainWindowViewModel));
|
||||
if (DataContext is IMainWindowViewModelBase mainWindowViewModelBase)
|
||||
{
|
||||
mainWindowViewModelBase.FatalError.SetValueSafe(
|
||||
$"Error initializing {nameof(MainWindowViewModel)}: " + ex.Message
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
private void OnKeyDown(object sender, KeyEventArgs e)
|
||||
|
||||
@@ -16,6 +16,7 @@ using FileTime.Server;
|
||||
using FileTime.Tools.Compression;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Serilog;
|
||||
|
||||
namespace FileTime.GuiApp;
|
||||
|
||||
@@ -23,6 +24,7 @@ public class Application : Avalonia.Application
|
||||
{
|
||||
private static void InitializeApp()
|
||||
{
|
||||
Log.Logger.Information("App initialization starting...");
|
||||
var configuration = Startup.CreateConfiguration();
|
||||
var services = DependencyInjection
|
||||
.RegisterDefaultServices(configuration: configuration)
|
||||
@@ -62,6 +64,7 @@ public class Application : Avalonia.Application
|
||||
{
|
||||
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
|
||||
{
|
||||
Log.Logger.Information("Creating MainWindow instance...");
|
||||
desktop.MainWindow = new MainWindow(InitializeApp)
|
||||
{
|
||||
DataContext = new MainWindowLoadingViewModel(),
|
||||
|
||||
@@ -22,7 +22,7 @@ public static class Program
|
||||
public static string EnvironmentName { get; private set; } = null!;
|
||||
|
||||
private static ILogger _logger = null!;
|
||||
|
||||
|
||||
internal static List<string> DirectoriesToOpen { get; } = new();
|
||||
|
||||
private static void InitLogging()
|
||||
@@ -41,7 +41,8 @@ public static class Program
|
||||
.WriteTo.File(
|
||||
Path.Combine(logFolder, "appLog.log"),
|
||||
fileSizeLimitBytes: 10 * 1024 * 1024,
|
||||
outputTemplate: "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level:u3}] [{SourceContext}] {Message:lj}{NewLine}{Exception}",
|
||||
outputTemplate:
|
||||
"{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level:u3}] [{SourceContext}] {Message:lj}{NewLine}{Exception}",
|
||||
rollingInterval: RollingInterval.Day,
|
||||
rollOnFileSizeLimit: true)
|
||||
.CreateBootstrapLogger();
|
||||
@@ -128,15 +129,16 @@ public static class Program
|
||||
{
|
||||
Log.CloseAndFlush();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Avalonia configuration, don't remove; also used by visual designer.
|
||||
public static AppBuilder BuildAvaloniaApp()
|
||||
=> AppBuilder.Configure<Application>()
|
||||
.UsePlatformDetect()
|
||||
.UseReactiveUI()
|
||||
.LogToTrace();
|
||||
#if DEBUG
|
||||
.LogToTrace()
|
||||
#endif
|
||||
;
|
||||
|
||||
private static void OnTaskSchedulerUnobservedTaskException(object? sender, UnobservedTaskExceptionEventArgs e)
|
||||
=> HandleUnhandledException(sender, e.Exception);
|
||||
|
||||
Reference in New Issue
Block a user