Skip to content

Commit

Permalink
Fixed application lockup when writing logs on close
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaoticz committed Dec 31, 2024
1 parent 73da876 commit 91a6ceb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
30 changes: 19 additions & 11 deletions NadekoHub/Features/AppWindow/Views/Windows/AppView.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,15 +156,24 @@ protected override void OnClosing(WindowClosingEventArgs eventArgs)

base.OnClosing(eventArgs);
}

/// <inheritdoc/>
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();
await _logWriter.FlushAllAsync(true);
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
finally
{
base.OnClosed(eventArgs);
}
}

/// <summary>
Expand Down Expand Up @@ -255,8 +264,7 @@ private async Task UpdateAndCloseAsync()
return;

_ = new UpdateView().ShowDialog(this);



try
{
await _appResolver.InstallOrUpdateAsync(AppContext.BaseDirectory);
Expand All @@ -276,13 +284,13 @@ private async Task UpdateAndCloseAsync()
[SupportedOSPlatform("windows")]
private async Task MigrateOldBotsAsync()
{
var configFileUri = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), "NadekoBotUpdater", "bots.json");
var configFileUri = Path.Join(Environment.GetFolderPath(Environment.SpecialFolder.Personal), "NadekoBotUpdater", "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, "NadekoBot.exe")))
.Where(x => !string.IsNullOrWhiteSpace(x.PathUri) && File.Exists(Path.Join(x.PathUri, "NadekoBot.exe")))
.Select((x, y) => new BotEntry(x.Guid, new(x.Name, x.PathUri!, (uint)y, x.Version, x.IconUri)));

foreach (var botEntry in bots)
Expand Down
2 changes: 1 addition & 1 deletion NadekoHub/Features/Home/Services/AppResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ await GetDownloadUrlAsync(latestVersion, cToken),
}
}

// 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 = KotzUtilities.StartProcess("chmod", ["+x", BinaryUri]);
Expand Down

0 comments on commit 91a6ceb

Please sign in to comment.