From 4deaa828c5f73ac19decb53dd51d39e2d1803260 Mon Sep 17 00:00:00 2001 From: Toastie Date: Tue, 7 Jan 2025 18:16:21 +1300 Subject: [PATCH] Fixed application lockup when writing logs on close --- .../AppWindow/Views/Windows/AppView.axaml.cs | 26 ++++++++++++------- .../Features/Home/Services/AppResolver.cs | 2 +- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/EllieHub/Features/AppWindow/Views/Windows/AppView.axaml.cs b/EllieHub/Features/AppWindow/Views/Windows/AppView.axaml.cs index c5bda17..fa56a81 100644 --- a/EllieHub/Features/AppWindow/Views/Windows/AppView.axaml.cs +++ b/EllieHub/Features/AppWindow/Views/Windows/AppView.axaml.cs @@ -158,13 +158,22 @@ public partial class AppView : ReactiveWindow } /// - protected override void OnClosed(EventArgs eventArgs) + protected override async void OnClosed(EventArgs eventArgs) { - // When the updater is closed, kill all bots and write their logs. - _botOrchestrator.StopAllBots(); - _logWriter.FlushAllAsync(true).Wait(); - - base.OnClosed(eventArgs); + try + { + // When the updater is closed, kill all bots and write their logs. + _botOrchestrator.StopAllBots(); + _logWriter.FlushAllAsync(true).Wait(); + } + catch (Exception ex) + { + Console.WriteLine(ex); + } + finally + { + base.OnClosed(eventArgs); + } } /// @@ -256,7 +265,6 @@ public partial class AppView : ReactiveWindow _ = new UpdateView().ShowDialog(this); - try { await _appResolver.InstallOrUpdateAsync(AppContext.BaseDirectory); @@ -276,13 +284,13 @@ public partial class AppView : ReactiveWindow [SupportedOSPlatform("windows")] private async Task MigrateOldBotsAsync() { - var configFileUri = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), "EllieBotUpdater", "bots.json"); + var configFileUri = Path.Join(Environment.GetFolderPath(Environment.SpecialFolder.Personal), "EllieBotUpdater", "bots.json"); if (File.Exists(AppStatics.AppConfigUri) || !File.Exists(configFileUri)) return; var bots = (JsonSerializer.Deserialize(await File.ReadAllTextAsync(configFileUri)) ?? []) - .Where(x => !string.IsNullOrWhiteSpace(x.PathUri) && File.Exists(Path.Combine(x.PathUri, "EllieBot.exe"))) + .Where(x => !string.IsNullOrWhiteSpace(x.PathUri) && File.Exists(Path.Join(x.PathUri, "EllieBot.exe"))) .Select((x, y) => new BotEntry(x.Guid, new(x.Name, x.PathUri!, (uint)y, x.Version, x.IconUri))); foreach (var botEntry in bots) diff --git a/EllieHub/Features/Home/Services/AppResolver.cs b/EllieHub/Features/Home/Services/AppResolver.cs index d02d7bd..6400cb1 100644 --- a/EllieHub/Features/Home/Services/AppResolver.cs +++ b/EllieHub/Features/Home/Services/AppResolver.cs @@ -159,7 +159,7 @@ public sealed class AppResolver : IAppResolver } } - // Mark the new binary file as executable. + // Mark the new binary file as executable.c if (Environment.OSVersion.Platform is PlatformID.Unix) { using var chmod = ToastieUtilities.StartProcess("chmod", ["+x", BinaryUri]);