Gui startup optimizations
This commit is contained in:
@@ -70,7 +70,8 @@ public class TabPersistenceService : ITabPersistenceService
|
||||
|
||||
foreach (var (requestedTabNumber, nativePath) in _tabsToOpen.TabsToOpen)
|
||||
{
|
||||
if (await _timelessContentProvider.GetItemByNativePathAsync(nativePath) is not IContainer container) continue;
|
||||
if (await _timelessContentProvider.GetItemByNativePathAsync(nativePath) is not IContainer container)
|
||||
continue;
|
||||
|
||||
containers.Add((requestedTabNumber, container));
|
||||
}
|
||||
@@ -111,14 +112,16 @@ public class TabPersistenceService : ITabPersistenceService
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
private async Task<IEnumerable<ITabViewModel>> LoadStatesAsync(bool createEmptyIfNecessary, CancellationToken token = default)
|
||||
private async Task<IEnumerable<ITabViewModel>> LoadStatesAsync(
|
||||
bool createEmptyIfNecessary,
|
||||
CancellationToken token = default)
|
||||
{
|
||||
if (!File.Exists(_settingsPath) || !_tabPersistenceSettings.LoadState)
|
||||
{
|
||||
if (createEmptyIfNecessary)
|
||||
{
|
||||
var tabViewModel = await CreateEmptyTab();
|
||||
return new[] {tabViewModel};
|
||||
return new[] { tabViewModel };
|
||||
}
|
||||
|
||||
return Enumerable.Empty<ITabViewModel>();
|
||||
@@ -142,7 +145,7 @@ public class TabPersistenceService : ITabPersistenceService
|
||||
if (createEmptyIfNecessary)
|
||||
{
|
||||
var tabViewModel = await CreateEmptyTab();
|
||||
return new[] {tabViewModel};
|
||||
return new[] { tabViewModel };
|
||||
}
|
||||
|
||||
return Enumerable.Empty<ITabViewModel>();
|
||||
@@ -162,7 +165,8 @@ public class TabPersistenceService : ITabPersistenceService
|
||||
// ignored
|
||||
}
|
||||
|
||||
var tab = await _serviceProvider.GetAsyncInitableResolver<IContainer>(currentDirectory ?? _localContentProvider)
|
||||
var tab = await _serviceProvider
|
||||
.GetAsyncInitableResolver<IContainer>(currentDirectory ?? _localContentProvider)
|
||||
.GetRequiredServiceAsync<ITab>();
|
||||
var tabViewModel = _serviceProvider.GetInitableResolver(tab, 1).GetRequiredService<ITabViewModel>();
|
||||
|
||||
@@ -265,8 +269,7 @@ public class TabPersistenceService : ITabPersistenceService
|
||||
foreach (var tab in _appState.Tabs)
|
||||
{
|
||||
var currentLocation = tab.CurrentLocation.Value;
|
||||
if (currentLocation is null) continue;
|
||||
var path = currentLocation.FullName!.Path;
|
||||
if (currentLocation?.FullName?.Path is not { } path) continue;
|
||||
|
||||
if (currentLocation.GetExtension<RealContainerProviderExtension>()?.RealContainer() is { } realPath)
|
||||
{
|
||||
|
||||
@@ -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,10 +51,13 @@ public partial class MainWindow : Window, IUiAccessor
|
||||
_initializer = initializer;
|
||||
}
|
||||
|
||||
private void OnWindowOpened(object sender, EventArgs e)
|
||||
private async void OnWindowOpened(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (DataContext is not MainWindowViewModel && !Design.IsDesignMode)
|
||||
{
|
||||
await Task.Delay(100);
|
||||
_initializer?.Invoke();
|
||||
|
||||
_logger = DI.ServiceProvider.GetService<ILogger<MainWindow>>();
|
||||
@@ -85,6 +88,10 @@ public partial class MainWindow : Window, IUiAccessor
|
||||
}
|
||||
}
|
||||
}
|
||||
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(),
|
||||
|
||||
@@ -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