From e6a749465eb0a52b14606f9052ca1d374eb61875 Mon Sep 17 00:00:00 2001 From: r-zakarya <82443831+r-zakarya@users.noreply.github.com> Date: Mon, 27 Jul 2026 05:29:01 +0100 Subject: [PATCH] fix(startup): --tray launch no longer flashes the window MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- delphi-backend/UMainForm.pas | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/delphi-backend/UMainForm.pas b/delphi-backend/UMainForm.pas index ca06c3b..62a2c86 100644 --- a/delphi-backend/UMainForm.pas +++ b/delphi-backend/UMainForm.pas @@ -206,6 +206,16 @@ procedure WinStateEventProc(hWinEventHook: THandle; AEvent: DWORD; AWnd: HWND; procedure TMainForm.FormCreate(Sender: TObject); 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. // Wired here (not in the .fmx) to keep the designer file untouched. FWantMaximized := (WindowState = TWindowState.wsMaximized); @@ -300,8 +310,9 @@ begin // CLI flag --tray (set by the "Start with Windows" registry entry): // launch directly into the tray instead of popping a window during - // the Windows login. Defer to ForceQueue so the form has finished its - // initial Show before we hide it — minimises the visible flash. + // the Windows login. The window was already made invisible at the top of + // 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 begin // Suppress the first-time tray balloon for autostart launches —