Persistence of settings window size/position (#2319)

should be good enough imo
This commit is contained in:
pizzaboxer 2024-09-13 00:28:57 +01:00
parent 47cf9e70cb
commit 83e3c487a9
No known key found for this signature in database
GPG Key ID: 59D4A1DBAD0F2BA8
4 changed files with 52 additions and 1 deletions

View File

@ -140,7 +140,9 @@ namespace Bloxstrap
if (interlock.IsAcquired) if (interlock.IsAcquired)
{ {
bool showAlreadyRunningWarning = Process.GetProcessesByName(App.ProjectName).Length > 1; bool showAlreadyRunningWarning = Process.GetProcessesByName(App.ProjectName).Length > 1;
new UI.Elements.Settings.MainWindow(showAlreadyRunningWarning).Show();
var window = new UI.Elements.Settings.MainWindow(showAlreadyRunningWarning);
window.Show();
} }
else else
{ {

View File

@ -10,6 +10,8 @@
public AppState Studio { get; set; } = new(); public AppState Studio { get; set; } = new();
public WindowState SettingsWindow { get; set; } = new();
public List<string> ModManifest { get; set; } = new(); public List<string> ModManifest { get; set; } = new();
} }
} }

View File

@ -0,0 +1,13 @@
namespace Bloxstrap.Models
{
public class WindowState
{
public double Width { get; set; }
public double Height { get; set; }
public double Left { get; set; }
public double Top { get; set; }
}
}

View File

@ -14,6 +14,8 @@ namespace Bloxstrap.UI.Elements.Settings
/// </summary> /// </summary>
public partial class MainWindow : INavigationWindow public partial class MainWindow : INavigationWindow
{ {
private Models.WindowState _state => App.State.Prop.SettingsWindow;
public MainWindow(bool showAlreadyRunningWarning) public MainWindow(bool showAlreadyRunningWarning)
{ {
var viewModel = new MainWindowViewModel(); var viewModel = new MainWindowViewModel();
@ -33,6 +35,30 @@ namespace Bloxstrap.UI.Elements.Settings
if (showAlreadyRunningWarning) if (showAlreadyRunningWarning)
ShowAlreadyRunningSnackbar(); ShowAlreadyRunningSnackbar();
LoadState();
}
public void LoadState()
{
if (_state.Left > SystemParameters.VirtualScreenWidth)
_state.Left = 0;
if (_state.Top > SystemParameters.VirtualScreenHeight)
_state.Top = 0;
if (_state.Width > 0)
this.Width = _state.Width;
if (_state.Height > 0)
this.Height = _state.Height;
if (_state.Left > 0 && _state.Top > 0)
{
this.WindowStartupLocation = WindowStartupLocation.Manual;
this.Left = _state.Left;
this.Top = _state.Top;
}
} }
private async void ShowAlreadyRunningSnackbar() private async void ShowAlreadyRunningSnackbar()
@ -67,6 +93,14 @@ namespace Bloxstrap.UI.Elements.Settings
e.Cancel = true; e.Cancel = true;
} }
_state.Width = this.Width;
_state.Height = this.Height;
_state.Top = this.Top;
_state.Left = this.Left;
App.State.Save();
if (!e.Cancel) if (!e.Cancel)
App.Terminate(); App.Terminate();
} }