diff --git a/StabilityMatrix.Avalonia/App.axaml.cs b/StabilityMatrix.Avalonia/App.axaml.cs index ea643cb8..70f5dcc1 100644 --- a/StabilityMatrix.Avalonia/App.axaml.cs +++ b/StabilityMatrix.Avalonia/App.axaml.cs @@ -152,7 +152,7 @@ public sealed class App : Application var settingsManager = Services.GetRequiredService(); var windowSettings = settingsManager.Settings.WindowSettings; - if (windowSettings != null) + if (windowSettings != null && !Program.Args.ResetWindowPosition) { mainWindow.Position = new PixelPoint(windowSettings.X, windowSettings.Y); mainWindow.Width = windowSettings.Width; @@ -165,12 +165,16 @@ public sealed class App : Application mainWindow.Closing += (_, _) => { + var validWindowPosition = + mainWindow.Screens.All.Any(screen => screen.Bounds.Contains(mainWindow.Position)); + settingsManager.Transaction(s => - { - s.WindowSettings = new WindowSettings( - mainWindow.Width, mainWindow.Height, - mainWindow.Position.X, mainWindow.Position.Y); - }, ignoreMissingLibraryDir: true); + { + s.WindowSettings = new WindowSettings( + mainWindow.Width, mainWindow.Height, + validWindowPosition ? mainWindow.Position.X : 0, + validWindowPosition ? mainWindow.Position.Y : 0); + }, ignoreMissingLibraryDir: true); }; mainWindow.Closed += (_, _) => Shutdown(); diff --git a/StabilityMatrix.Avalonia/Models/AppArgs.cs b/StabilityMatrix.Avalonia/Models/AppArgs.cs index ead4cce4..d3ee5412 100644 --- a/StabilityMatrix.Avalonia/Models/AppArgs.cs +++ b/StabilityMatrix.Avalonia/Models/AppArgs.cs @@ -25,4 +25,9 @@ public class AppArgs /// Whether to disable window chrome effects /// public bool NoWindowChromeEffects { get; set; } + + /// + /// Flag to indicate if we should reset the saved window position back to (O,0) + /// + public bool ResetWindowPosition { get; set; } } diff --git a/StabilityMatrix.Avalonia/Program.cs b/StabilityMatrix.Avalonia/Program.cs index bb488236..d37f84a6 100644 --- a/StabilityMatrix.Avalonia/Program.cs +++ b/StabilityMatrix.Avalonia/Program.cs @@ -12,6 +12,7 @@ using Avalonia; using Avalonia.Controls; using Avalonia.Controls.ApplicationLifetimes; using Avalonia.Threading; +using Microsoft.Extensions.DependencyInjection; using NLog; using Polly.Contrib.WaitAndRetry; using Projektanker.Icons.Avalonia; @@ -44,6 +45,7 @@ public class Program Args.DebugSentry = args.Contains("--debug-sentry"); Args.NoSentry = args.Contains("--no-sentry"); Args.NoWindowChromeEffects = args.Contains("--no-window-chrome-effects"); + Args.ResetWindowPosition = args.Contains("--reset-window-position"); SetDebugBuild();