From c052a28aa6980420c1780214d29f02d04f9d25f5 Mon Sep 17 00:00:00 2001 From: ColorlessColor <171957320+ColorlessColor@users.noreply.github.com> Date: Tue, 12 Nov 2024 06:41:26 +0800 Subject: [PATCH] Fixed window will never show up again if the window is closed when minimized (#977) * `Show()` must be called before changing `WindowState`, otherwise the internal state of the window will be messed up. If you don't do this, when the window is closed when minimized, even if you click the tray menu icon, it will never show up. * Remember window state before minimized. If window was maximized before minimized, it should be restore to maximized when `Focus_Window` called. --- Dotnet/MainForm.cs | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/Dotnet/MainForm.cs b/Dotnet/MainForm.cs index 6db54a50..bfde0a1e 100644 --- a/Dotnet/MainForm.cs +++ b/Dotnet/MainForm.cs @@ -25,11 +25,25 @@ namespace VRCX private int LastSizeWidth; private int LastSizeHeight; + private FormWindowState _LastWindowStateToRestore = FormWindowState.Normal; + private FormWindowState LastWindowStateToRestore + { + get => _LastWindowStateToRestore; + set + { + // Used to restore window state after minimized + if (FormWindowState.Minimized != value) + { + _LastWindowStateToRestore = value; + } + } + } + public MainForm() { Instance = this; InitializeComponent(); - + // adding a 5s delay here to avoid excessive writes to disk _saveTimer = new Timer(); _saveTimer.Interval = 5000; @@ -129,28 +143,32 @@ namespace VRCX jslogger.Error(ex); } + LastWindowStateToRestore = WindowState; + // 가끔 화면 위치가 안맞음.. 이걸로 해결 될지는 모르겠음 Browser.Invalidate(); } private void MainForm_Resize(object sender, System.EventArgs e) { + LastWindowStateToRestore = WindowState; + if (WindowState != FormWindowState.Normal) { return; } 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) @@ -159,7 +177,7 @@ namespace VRCX } LastLocationX = Location.X; LastLocationY = Location.Y; - + _saveTimer?.Start(); } @@ -172,7 +190,7 @@ namespace VRCX Hide(); } } - + private void SaveWindowState() { VRCXStorage.Instance.Set("VRCX_LocationX", LastLocationX.ToString()); @@ -203,11 +221,11 @@ namespace VRCX public void Focus_Window() { + Show(); if (WindowState == FormWindowState.Minimized) { - WindowState = FormWindowState.Normal; + WindowState = LastWindowStateToRestore; } - Show(); // Focus(); Activate(); }