fix(startup): start the proxy watcher from the .dpr, before the form exists

Decisive observation: the taskbar button is already up before FormCreate is
entered. Everything I had tried lived inside the form, so all of it ran after
the button was drawn — the watcher included, which is why moving it around
never helped.

StartTrayProxyHider is now exported from UMainForm and called from the .dpr
right after Application.Initialize, before CreateForm. It polls every 5 ms and
hides our TFMAppClass proxy unconditionally (the button can be up before
WS_VISIBLE reads as set, which the previous IsWindowVisible check would have
skipped), stopping as soon as the tray startup completes so a user restoring
from the tray is never fought.

Raw Win32 only — FindWindowEx + ShowWindow, no FMX object touched at that
point, which is what made the earlier .dpr attempt crash.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
r-zakarya
2026-07-27 13:15:32 +01:00
parent 4f2aff9de4
commit ab8186ef75
3 changed files with 61 additions and 24 deletions
+8
View File
@@ -1,6 +1,7 @@
program PMServer;
uses
System.SysUtils, // FindCmdLineSwitch
System.StartUpCopy,
FMX.Forms,
PM.SingleInstance in 'Source\PM.SingleInstance.pas',
@@ -43,6 +44,13 @@ begin
Exit;
Application.Initialize;
// --tray ("Start with Windows"): FMX puts its taskbar proxy on screen before
// FormCreate is ever reached — measured — so the watcher has to start here,
// before the form is built. It only touches raw Win32 (FindWindowEx +
// ShowWindow), never an FMX object: an earlier attempt that poked
// MainForm.Visible/Handle at this point died with an access violation.
if FindCmdLineSwitch('tray', True) then
StartTrayProxyHider;
Application.CreateForm(TMainForm, MainForm);
Application.Run;
end.