From a76e6921832bdd27cd01c6c4fe4e304ceef0e6f7 Mon Sep 17 00:00:00 2001 From: Kenneth Skovhede Date: Tue, 7 May 2024 18:00:45 +0200 Subject: [PATCH] Removed trace logs from Avaloni by default. Addded option to get logs from Avalonia via env variables `DEBUG_AVALONIA=1` or `DEBUG_AVALONIA=2` Added 1s delay for initializing UI to counter sporadic crashes on startup. --- .../GUI/Duplicati.GUI.TrayIcon/AvaloniaRunner.cs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/Duplicati/GUI/Duplicati.GUI.TrayIcon/AvaloniaRunner.cs b/Duplicati/GUI/Duplicati.GUI.TrayIcon/AvaloniaRunner.cs index 6d18f1c55..77c78bffb 100644 --- a/Duplicati/GUI/Duplicati.GUI.TrayIcon/AvaloniaRunner.cs +++ b/Duplicati/GUI/Duplicati.GUI.TrayIcon/AvaloniaRunner.cs @@ -23,6 +23,7 @@ using System; using System.Collections.Generic; using System.Linq; using System.Reflection; +using System.Threading.Tasks; using Avalonia; using Avalonia.Controls; using Avalonia.Controls.ApplicationLifetimes; @@ -67,15 +68,25 @@ namespace Duplicati.GUI.TrayIcon var builder = AppBuilder .Configure() .UsePlatformDetect() - .LogToTrace() .With(new MacOSPlatformOptions() { ShowInDock = false }) .SetupWithLifetime(lifetime); +#if DEBUG + builder = builder.LogToTrace(); +#else + if (Environment.GetEnvironmentVariable("DEBUG_AVALONIA") == "1") + builder = builder.LogToTrace(); + else if (Environment.GetEnvironmentVariable("DEBUG_AVALONIA") == "2") + builder = builder.LogToTrace(Avalonia.Logging.LogEventLevel.Verbose); +#endif + application = builder.Instance as AvaloniaApp; application.SetMenu(menuItems); application.Configure(); - postInit?.Invoke(); + // Delay postInit to allow the UI to initialize before calling updates + if (postInit != null) + Task.Delay(1000).ContinueWith(_ => postInit()); lifetime.Start(args); }