2026-10-11 23:23:20 +00:00
|
|
|
namespace UCVL.VPNPlus;
|
|
|
|
|
|
|
|
|
|
internal sealed partial class MainForm
|
|
|
|
|
{
|
|
|
|
|
private WindowChrome? _windowChrome;
|
2026-10-13 04:32:04 +00:00
|
|
|
private bool _minimizedToTray;
|
2026-10-11 23:23:20 +00:00
|
|
|
internal WindowChrome? WindowChromeForTest => _windowChrome;
|
|
|
|
|
|
|
|
|
|
// Remove the native caption before HWND creation, not only after its first
|
|
|
|
|
// style/paint messages. This avoids a transient second caption at startup.
|
|
|
|
|
protected override CreateParams CreateParams
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
var parameters = base.CreateParams;
|
|
|
|
|
parameters.Style = unchecked((int)ChromeNative.ClientChromeStyle(parameters.Style));
|
|
|
|
|
return parameters;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnLoad(EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
base.OnLoad(e);
|
|
|
|
|
LayoutBrandHeader();
|
|
|
|
|
CenterCards();
|
|
|
|
|
LayoutDashboard();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Explicit title/tray Exit and installer IPC share the graceful exit path.
|
|
|
|
|
private void InitializeWindowChrome(Panel header)
|
|
|
|
|
{
|
|
|
|
|
if (_windowChrome is not null) return;
|
2026-10-13 04:32:04 +00:00
|
|
|
_windowChrome = new WindowChrome(this, header, RequestExit, MinimizeToTray);
|
2026-10-11 23:23:20 +00:00
|
|
|
_windowChrome.SetLoginMode(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void LayoutWindowChrome() => _windowChrome?.LayoutButtons();
|
|
|
|
|
|
2026-10-13 04:32:04 +00:00
|
|
|
// Keep the core and timers alive. Only the window presentation changes;
|
|
|
|
|
// restore/exit remain the existing tray menu actions.
|
|
|
|
|
private void MinimizeToTray()
|
|
|
|
|
{
|
|
|
|
|
if (_exiting || IsDisposed || Disposing || _windowChrome is not { LoginMode: false }) return;
|
|
|
|
|
_minimizedToTray = true;
|
|
|
|
|
Hide();
|
|
|
|
|
ShowInTaskbar = false;
|
|
|
|
|
UpdateTaskbarPresentation();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void RestoreFromTrayPresentation()
|
|
|
|
|
{
|
|
|
|
|
_minimizedToTray = false;
|
|
|
|
|
ShowInTaskbar = true;
|
|
|
|
|
WindowState = FormWindowState.Normal;
|
|
|
|
|
UpdateTaskbarPresentation();
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-11 23:23:20 +00:00
|
|
|
private void UpdateTaskbarPresentation()
|
|
|
|
|
{
|
|
|
|
|
if (_exitResourcesDisposed) return;
|
2026-10-13 04:32:04 +00:00
|
|
|
if (!_minimizedToTray && Visible && WindowState == FormWindowState.Minimized
|
|
|
|
|
&& _windowChrome is { LoginMode: false })
|
|
|
|
|
{
|
|
|
|
|
MinimizeToTray();
|
|
|
|
|
return;
|
|
|
|
|
}
|
2026-10-11 23:23:20 +00:00
|
|
|
_notifyIcon.Visible = ShouldShowTrayIcon(WindowState, _preview || _uiOnly || _exiting);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal static bool ShouldShowTrayIcon(FormWindowState state, bool suppressed) =>
|
2026-10-13 04:32:04 +00:00
|
|
|
!suppressed;
|
2026-10-11 23:23:20 +00:00
|
|
|
|
2026-10-13 04:32:04 +00:00
|
|
|
internal bool MinimizedToTrayForTest => _minimizedToTray && !Visible && !ShowInTaskbar && !_exiting
|
|
|
|
|
&& (_preview || _uiOnly || _notifyIcon.Visible);
|
2026-10-11 23:23:20 +00:00
|
|
|
}
|