Skip to content

Commit

Permalink
Made launcher quit request also quit the background watcher loop
Browse files Browse the repository at this point in the history
fixes #503
  • Loading branch information
hhyyrylainen committed Mar 21, 2024
1 parent 27e97d4 commit d554a26
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
17 changes: 17 additions & 0 deletions ThriveLauncher/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ internal class Program

private static bool reActivationRequested;

private static bool launcherQuitRequested;

// Initialization code. Don't use any Avalonia, third-party APIs or any
// SynchronizationContext-reliant code before AppMain is called: things aren't initialized
// yet and stuff might break.
Expand Down Expand Up @@ -95,6 +97,14 @@ public static int Main(string[] args)
}
}

/// <summary>
/// Signals the main loop that the launcher should quit now
/// </summary>
public static void OnLauncherWantsToCloseNow()
{
launcherQuitRequested = true;
}

// Avalonia configuration, don't remove; also used by visual designer.
// Can't be made private without breaking the designer
// ReSharper disable once MemberCanBePrivate.Global
Expand Down Expand Up @@ -319,6 +329,13 @@ private static async Task RunCustomShutdownWatcher(AppBuilder avaloniaBuilder, S
{
await Task.Delay(runInterval);

if (launcherQuitRequested)
{
programLogger.LogInformation("Launcher quit requested, exiting shutdown watcher loop");
lifetime.Shutdown();
break;
}

try
{
// If there are Avalonia windows open, we don't need to do anything
Expand Down
7 changes: 5 additions & 2 deletions ThriveLauncher/Views/MainWindow.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1007,10 +1007,13 @@ private void OnWantedWindowHiddenStateChanged(bool hidden)

private void OnLauncherWantsToClose(bool close)
{
// TODO: should this close all windows always (or signal to the main loop that quit is wanted)?
// Especially on mac: https://github.com/Revolutionary-Games/Thrive-Launcher/issues/503
if (close)
{
Close();

// Signal main loop to also quit immediately to not hang around on mac or if there are other windows open
Program.OnLauncherWantsToCloseNow();
}
}

private async void CopyLogsToClipboard(object? sender, RoutedEventArgs e)
Expand Down

0 comments on commit d554a26

Please sign in to comment.