Browse Source

Add WindowSettings to save/load window positions on exit/startup

pull/55/head
JT 1 year ago
parent
commit
dc80858076
  1. 18
      StabilityMatrix.Avalonia/App.axaml.cs
  2. BIN
      StabilityMatrix.Avalonia/Assets/win-x64/get-pip.pyc
  3. 6
      StabilityMatrix.Avalonia/Views/MainWindow.axaml
  4. 2
      StabilityMatrix.Core/Models/Settings/Settings.cs
  5. 2
      StabilityMatrix.Core/Models/Settings/WindowSettings.cs

18
StabilityMatrix.Avalonia/App.axaml.cs

@ -42,6 +42,7 @@ using StabilityMatrix.Core.Helper.Cache;
using StabilityMatrix.Core.Helper.Factory;
using StabilityMatrix.Core.Models.Api;
using StabilityMatrix.Core.Models.Packages;
using StabilityMatrix.Core.Models.Settings;
using StabilityMatrix.Core.Python;
using StabilityMatrix.Core.Services;
using StabilityMatrix.Core.Updater;
@ -88,6 +89,19 @@ public sealed class App : Application
mainWindow.DataContext = mainViewModel;
mainWindow.NotificationService = notificationService;
var settingsManager = Services.GetRequiredService<ISettingsManager>();
var windowSettings = settingsManager.Settings.WindowSettings;
if (windowSettings != null)
{
mainWindow.Position = new PixelPoint(windowSettings.X, windowSettings.Y);
mainWindow.Width = windowSettings.Width;
mainWindow.Height = windowSettings.Height;
}
else
{
mainWindow.WindowStartupLocation = WindowStartupLocation.CenterScreen;
}
VisualRoot = mainWindow;
StorageProvider = mainWindow.StorageProvider;
@ -376,6 +390,10 @@ public sealed class App : Application
sharedFolders.RemoveLinksForAllPackages();
}
var mainWindow = Services.GetRequiredService<MainWindow>();
settingsManager.Transaction(s => s.WindowSettings = new WindowSettings(mainWindow.Width,
mainWindow.Height, mainWindow.Position.X, mainWindow.Position.Y));
Debug.WriteLine("Start OnExit: Disposing services");
// Dispose all services
foreach (var disposable in Services.GetServices<IDisposable>())

BIN
StabilityMatrix.Avalonia/Assets/win-x64/get-pip.pyc

Binary file not shown.

6
StabilityMatrix.Avalonia/Views/MainWindow.axaml

@ -12,12 +12,10 @@
x:CompileBindings="True"
Icon="/Assets/Icon.ico"
Width="1100"
Height="850"
Height="750"
Title="Stability Matrix"
WindowStartupLocation="CenterScreen"
x:Class="StabilityMatrix.Avalonia.Views.MainWindow">
<Grid RowDefinitions="Auto,Auto,*">
<Grid Name="TitleBarHost"
ColumnDefinitions="Auto,Auto,*,Auto"

2
StabilityMatrix.Core/Models/Settings/Settings.cs

@ -22,7 +22,7 @@ public class Settings
SharedFolderType.Lora |
SharedFolderType.LyCORIS;
public string? Placement { get; set; }
public WindowSettings? WindowSettings { get; set; }
public ModelSearchOptions? ModelSearchOptions { get; set; }

2
StabilityMatrix.Core/Models/Settings/WindowSettings.cs

@ -1,3 +1,3 @@
namespace StabilityMatrix.Core.Models.Settings;
public record WindowSettings(double Width, double Height);
public record WindowSettings(double Width, double Height, int X, int Y);

Loading…
Cancel
Save