fix(startup): --tray launch no longer flashes the window

With "Start with Windows" the window sat on screen for a second or two before
dropping to the tray. The hide was deferred with ForceQueue, which only runs
once the message loop is free — i.e. after the DB open, the HTTP server start
and the WebView2 init, all of which happen first.

Set Visible := False at the very top of FormCreate instead, before any of that
work, so there is nothing to show in the first place. The deferred
MinimizeToTray stays: it still adds the tray icon and drops the taskbar entry,
and doubles as the safety net if FMX shows the main form regardless — worst
case the behaviour is exactly what it is today.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
r-zakarya
2026-07-27 05:29:01 +01:00
parent 087eb52d66
commit e6a749465e
+13 -2
View File
@@ -206,6 +206,16 @@ procedure WinStateEventProc(hWinEventHook: THandle; AEvent: DWORD; AWnd: HWND;
procedure TMainForm.FormCreate(Sender: TObject); procedure TMainForm.FormCreate(Sender: TObject);
begin begin
// --tray (the "Start with Windows" registry entry): never let the window
// become visible at all. Hiding it later — even via ForceQueue — only runs
// once the message loop is free, i.e. AFTER the DB open, the HTTP server
// start and the WebView2 init have finished, so the window sat on screen
// for a second or two during the Windows logon. Setting Visible here, before
// any of that, means there is nothing to flash. MinimizeToTray still runs
// below to add the tray icon and drop the taskbar entry.
if FindCmdLineSwitch('tray', True) then
Visible := False;
// The .fmx ships WindowState = wsMaximized, so that is the starting intent. // The .fmx ships WindowState = wsMaximized, so that is the starting intent.
// Wired here (not in the .fmx) to keep the designer file untouched. // Wired here (not in the .fmx) to keep the designer file untouched.
FWantMaximized := (WindowState = TWindowState.wsMaximized); FWantMaximized := (WindowState = TWindowState.wsMaximized);
@@ -300,8 +310,9 @@ begin
// CLI flag --tray (set by the "Start with Windows" registry entry): // CLI flag --tray (set by the "Start with Windows" registry entry):
// launch directly into the tray instead of popping a window during // launch directly into the tray instead of popping a window during
// the Windows login. Defer to ForceQueue so the form has finished its // the Windows login. The window was already made invisible at the top of
// initial Show before we hide it — minimises the visible flash. // FormCreate; this adds the tray icon and drops the taskbar entry. Still
// deferred: it is also the safety net if FMX shows the main form anyway.
if FindCmdLineSwitch('tray', True) then if FindCmdLineSwitch('tray', True) then
begin begin
// Suppress the first-time tray balloon for autostart launches — // Suppress the first-time tray balloon for autostart launches —