Fixed application lockup when writing logs on close
Some checks failed
EllieBotDevs/EllieHub/pipeline/head There was a failure building this commit

This commit is contained in:
Toastie 2025-01-07 18:16:21 +13:00
parent f5c48cd8c4
commit 4deaa828c5
Signed by: toastie_t0ast
GPG key ID: 0861BE54AD481DC7
2 changed files with 18 additions and 10 deletions

View file

@ -158,14 +158,23 @@ public partial class AppView : ReactiveWindow<AppViewModel>
}
/// <inheritdoc/>
protected override void OnClosed(EventArgs eventArgs)
protected override async void OnClosed(EventArgs 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);
}
}
/// <summary>
/// Saves the size of this window to the application settings after the specified <paramref name="waitTime"/> elapses.
@ -256,7 +265,6 @@ public partial class AppView : ReactiveWindow<AppViewModel>
_ = new UpdateView().ShowDialog(this);
try
{
await _appResolver.InstallOrUpdateAsync(AppContext.BaseDirectory);
@ -276,13 +284,13 @@ public partial class AppView : ReactiveWindow<AppViewModel>
[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<OldUpdaterBotEntry[]>(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)

View file

@ -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]);