From 17e48aa688821e0c3f5607237e7ea68dce08c57e Mon Sep 17 00:00:00 2001 From: r-zakarya <82443831+r-zakarya@users.noreply.github.com> Date: Mon, 27 Jul 2026 12:33:26 +0100 Subject: [PATCH] fix(startup): start the server AFTER the tray hide, not before MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The visible thing is only the taskbar button — the form window is never shown (form_visible_was=False throughout). That button belongs to the FMX proxy, created partway through FormCreate, and FormCreate runs for ~1 s because it opens the DB, binds the Indy server and kicks off WebView2. The thread pumps no message during that second, so nothing could hide the proxy until it ended: hooks and hide points alike were powerless by construction. So stop trying to react faster and remove the wait instead: on a --tray launch btnStartClick now runs inside the deferred block, after MinimizeToTray. FormCreate returns in milliseconds, the proxy is hidden immediately, and the server starts once nothing is on screen. FServer is constructed earlier (line 295), so FServer.Active stays safe meanwhile. Normal launches keep the original order untouched. The EVENT_OBJECT_SHOW hook stays armed across the deferred start, so a proxy re-shown during it is hidden again. Co-Authored-By: Claude Opus 4.8 --- delphi-backend/UMainForm.pas | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/delphi-backend/UMainForm.pas b/delphi-backend/UMainForm.pas index cabb1f5..e46a6b0 100644 --- a/delphi-backend/UMainForm.pas +++ b/delphi-backend/UMainForm.pas @@ -342,7 +342,18 @@ begin FreeAndNil(configList); end; end; - btnStartClick(Nil); + // Starting the server (DB open + Indy bind + WebView2 navigation) is what + // makes FormCreate run for ~1 s. The FMX taskbar proxy is created somewhere + // inside that second, and since the thread never pumps a message while it + // runs, nothing can hide the proxy until it is over — that is the taskbar + // button sitting there during the Windows logon. + // + // On a --tray launch, do it AFTER the tray hide instead: FormCreate then + // returns in milliseconds, MinimizeToTray runs immediately, and the proxy is + // gone before it can be drawn. A normal launch is unchanged (the window is + // meant to be on screen anyway, so ordering does not matter there). + if not FindCmdLineSwitch('tray', True) then + btnStartClick(Nil); btnToggleLogClick(nil); // CLI flag --tray (set by the "Start with Windows" registry entry): @@ -361,6 +372,8 @@ begin procedure begin FBridge.MinimizeToTray; + // Hidden now — safe to pay the startup cost. + btnStartClick(Nil); GTrayStartupPending := False; if FShowEventHook <> 0 then begin