fix(startup): revert the .dpr hide (AV) and hide on first activate instead

The .dpr version crashed with an EAccessViolation writing to 000000CE —
touching MainForm.Visible/Handle between CreateForm and Run is evidently too
early for FMX. Reverted; the app builds and runs as before.

Replaced with a one-shot OnActivate handler installed in FormCreate only for
--tray: it fires the instant FMX shows the form, hides it (FMX + Win32) and
unhooks itself, so it can never fight the user later. That runs far earlier
than the deferred MinimizeToTray, which waits for the message loop and hence
for the DB open, server start and WebView2 init — the second the window used
to spend on screen.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
r-zakarya
2026-07-27 05:42:04 +01:00
parent 169cdddf9d
commit eec7bc4f80
2 changed files with 25 additions and 24 deletions
-16
View File
@@ -1,11 +1,8 @@
program PMServer;
uses
Winapi.Windows,
System.SysUtils,
System.StartUpCopy,
FMX.Forms,
FMX.Platform.Win,
PM.SingleInstance in 'Source\PM.SingleInstance.pas',
UMainForm in 'UMainForm.pas' {MainForm},
PM.JSON in 'Source\PM.JSON.pas',
@@ -47,18 +44,5 @@ begin
Application.Initialize;
Application.CreateForm(TMainForm, MainForm);
// --tray ("Start with Windows"): keep the window off screen entirely.
// FormCreate already sets Visible := False, but FMX re-shows the main form
// after the constructor returns, which is why the window still flashed for
// ~1 s during the Windows logon. Doing it HERE — after CreateForm, before
// Run pumps any message — is the point where it sticks. The handle still
// exists, so WebView2 initialises normally and the vault is ready the
// moment the user clicks the tray icon.
if FindCmdLineSwitch('tray', True) then
begin
MainForm.Visible := False;
if MainForm.Handle <> nil then
ShowWindow(WindowHandleToPlatform(MainForm.Handle).Wnd, SW_HIDE);
end;
Application.Run;
end.