fix(startup): start the server AFTER the tray hide, not before

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 <noreply@anthropic.com>
This commit is contained in:
r-zakarya
2026-07-27 12:33:26 +01:00
parent 8fa956f07f
commit 17e48aa688
+14 -1
View File
@@ -342,7 +342,18 @@ begin
FreeAndNil(configList); FreeAndNil(configList);
end; end;
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); btnToggleLogClick(nil);
// CLI flag --tray (set by the "Start with Windows" registry entry): // CLI flag --tray (set by the "Start with Windows" registry entry):
@@ -361,6 +372,8 @@ begin
procedure procedure
begin begin
FBridge.MinimizeToTray; FBridge.MinimizeToTray;
// Hidden now — safe to pay the startup cost.
btnStartClick(Nil);
GTrayStartupPending := False; GTrayStartupPending := False;
if FShowEventHook <> 0 then if FShowEventHook <> 0 then
begin begin