Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed issues with saving window resize and move #699

Merged
merged 1 commit into from
Dec 4, 2023
Merged
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
30 changes: 26 additions & 4 deletions Dotnet/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

using System;
using System.Drawing;
using System.IO;
using System.Reflection;
using System.Windows.Forms;
using CefSharp;
Expand All @@ -19,6 +18,7 @@ public partial class MainForm : WinformBase
public static MainForm Instance;
private static NLog.Logger jslogger = NLog.LogManager.GetLogger("Javascript");
public ChromiumWebBrowser Browser;
private readonly Timer _saveTimer;
private int LastLocationX;
private int LastLocationY;
private int LastSizeWidth;
Expand All @@ -29,6 +29,11 @@ public MainForm()
Instance = this;
InitializeComponent();


// adding a 5s delay here to avoid excessive writes to disk
_saveTimer = new Timer();
_saveTimer.Interval = 5000;
_saveTimer.Tick += SaveTimer_Tick;
try
{
var location = Assembly.GetExecutingAssembly().Location;
Expand Down Expand Up @@ -133,8 +138,15 @@ private void MainForm_Resize(object sender, System.EventArgs e)
}
LastSizeWidth = Size.Width;
LastSizeHeight = Size.Height;

_saveTimer.Start();
}

private void SaveTimer_Tick(object sender, EventArgs e)
{
SaveWindowState();
_saveTimer.Stop();
}

private void MainForm_Move(object sender, System.EventArgs e)
{
if (WindowState != FormWindowState.Normal)
Expand All @@ -143,6 +155,8 @@ private void MainForm_Move(object sender, System.EventArgs e)
}
LastLocationX = Location.X;
LastLocationY = Location.Y;

_saveTimer.Start();
}

private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
Expand All @@ -154,14 +168,21 @@ private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
Hide();
}
}

private void MainForm_FormClosed(object sender, FormClosedEventArgs e)


private void SaveWindowState()
{
VRCXStorage.Instance.Set("VRCX_LocationX", LastLocationX.ToString());
VRCXStorage.Instance.Set("VRCX_LocationY", LastLocationY.ToString());
VRCXStorage.Instance.Set("VRCX_SizeWidth", LastSizeWidth.ToString());
VRCXStorage.Instance.Set("VRCX_SizeHeight", LastSizeHeight.ToString());
VRCXStorage.Instance.Set("VRCX_WindowState", ((int)WindowState).ToString());
VRCXStorage.Instance.Flush();
}

private void MainForm_FormClosed(object sender, FormClosedEventArgs e)
{
SaveWindowState();
}

private void TrayIcon_MouseClick(object sender, MouseEventArgs e)
Expand Down Expand Up @@ -195,6 +216,7 @@ private void TrayMenu_DevTools_Click(object sender, System.EventArgs e)

private void TrayMenu_Quit_Click(object sender, System.EventArgs e)
{
SaveWindowState();
Application.Exit();
}
}
Expand Down