Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/UniGetUI.Avalonia/App.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using UniGetUI.Avalonia.Infrastructure;
using UniGetUI.Avalonia.Views;
using UniGetUI.Avalonia.Views.DialogPages;
using UniGetUI.Core.Data;
using UniGetUI.PackageEngine;
using CoreSettings = global::UniGetUI.Core.SettingsEngine.Settings;

Expand Down Expand Up @@ -48,6 +49,13 @@ public override void OnFrameworkInitializationCompleted()
ApplyTheme(CoreSettings.GetValue(CoreSettings.K.PreferredTheme));
var mainWindow = new MainWindow();
desktop.MainWindow = mainWindow;

if (CoreData.WasDaemon)
{
// Start silently: hide the window as soon as Avalonia opens it.
mainWindow.Opened += (_, _) => mainWindow.Hide();
}

_ = StartupAsync(mainWindow);
}

Expand Down Expand Up @@ -94,7 +102,13 @@ private static async Task StartupAsync(MainWindow mainWindow)
// Yield once so the main window has time to open before
// ShowDialog tries to attach to it as owner.
await Task.Yield();

// ShowDialog requires a visible owner. In daemon mode the main window
// is hidden, so temporarily show it and re-hide after the dialog closes.
bool reshide = CoreData.WasDaemon;
if (reshide) mainWindow.Show();
await new CrashReportWindow(report).ShowDialog(mainWindow);
if (reshide) mainWindow.Hide();
}
catch { /* must not prevent normal startup */ }
}
Expand Down
3 changes: 3 additions & 0 deletions src/UniGetUI.Avalonia/Program.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using Avalonia;
using UniGetUI.Core.Data;

namespace UniGetUI.Avalonia;

Expand All @@ -14,6 +15,8 @@ public static void Main(string[] args)
AppDomain.CurrentDomain.UnhandledException += (_, e) =>
CrashHandler.ReportFatalException((Exception)e.ExceptionObject);

CoreData.WasDaemon = CoreData.IsDaemon = args.Contains("--daemon");

BuildAvaloniaApp().StartWithClassicDesktopLifetime(args);
}

Expand Down
21 changes: 19 additions & 2 deletions src/UniGetUI/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -332,21 +332,37 @@ private async Task LoadComponentsAsync()

// Create MainWindow
InitializeMainWindow();
MainWindow.Activate();
if (!CoreData.WasDaemon)
MainWindow.Activate();

// Show crash report from the previous session on top of the loading
// screen and wait for the user to dismiss it before continuing.
if (File.Exists(CrashHandler.PendingCrashFile))
{
try
{
// In daemon mode the DWM/XAML threads are suspended; resume them
// temporarily so the crash window can render, then re-suspend.
bool resumedForCrash = CoreData.WasDaemon;
if (resumedForCrash)
{
DWMThreadHelper.ChangeState_DWM(false);
DWMThreadHelper.ChangeState_XAML(false);
}

string report = File.ReadAllText(CrashHandler.PendingCrashFile);
File.Delete(CrashHandler.PendingCrashFile);
var tcs = new TaskCompletionSource();
var crashWindow = new CrashReportWindow(report);
crashWindow.Closed += (_, _) => tcs.TrySetResult();
crashWindow.Activate();
await tcs.Task;

if (resumedForCrash)
{
DWMThreadHelper.ChangeState_DWM(true);
DWMThreadHelper.ChangeState_XAML(true);
}
}
catch { /* must not prevent normal startup */ }
}
Expand Down Expand Up @@ -505,7 +521,8 @@ private async Task CheckForMissingDependencies()

protected override void OnLaunched(LaunchActivatedEventArgs args)
{
MainWindow?.Activate();
if (!CoreData.WasDaemon)
MainWindow?.Activate();
}

public async Task ShowMainWindowFromRedirectAsync(AppActivationArguments rawArgs)
Expand Down
Loading