fix: eliminate black-square flash on startup, start cleanly in tray#47
Merged
Conversation
StartupUri="MainWindow.xaml" forced WPF to Show() the window during startup; the StartInTray check (and Hide()) only ran later in the Loaded handler. With WindowStyle="None" + WindowChrome, the frame shown before the WPF content painted appeared as a black square that then vanished. Stop showing the window when starting in the tray. App.OnStartup now creates MainWindow explicitly and calls InitializeApplication(), which realizes the native handle via WindowInteropHelper.EnsureHandle() (so global hotkeys can still bind) without ever painting the window. The window is only Show()n when StartInTray is false. ShutdownMode is set to OnExplicitShutdown so the app doesn't quit when a transient dialog (e.g. the editor) closes while the main window has never been shown. Verified: build clean, 109/109 tests pass, and an EnumWindows sweep confirms zero visible top-level windows for the running process. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Fixes the black square that briefly appears on app startup and ensures the app starts minimized to the system tray with no visible window.
Why
App.xamlusedStartupUri="MainWindow.xaml", which makes WPF Show() the window during startup. TheStartInTraycheck (andHide()) only ran afterward in theLoadedhandler — which fires after the window is shown and composed. WithWindowStyle="None"+WindowChrome, the brief frame before the WPF content painted appeared as a black square that then vanished. It was an unavoidable Show-then-Hide flash.How
App.xaml— removedStartupUri(which forcesShow()); setShutdownMode="OnExplicitShutdown", the correct mode for a tray app whose main window may never be shown (otherwise WPF could quit when a transient dialog like the editor closes).App.xaml.cs—OnStartupnow createsMainWindowexplicitly and callsInitializeApplication()instead of relying onStartupUri.MainWindow.xaml.cs— replaced theLoadedhandler withInitializeApplication(). WhenStartInTrayis set it callsWindowInteropHelper.EnsureHandle()to realize the native HWND (needed for global hotkey registration) without painting the window; otherwise it shows the window normally. Hotkeys bind after the handle exists in both paths.Testing
dotnet buildclean (0 warnings / 0 errors).dotnet test— 109/109 service tests pass.MainWindowHandle: 0, and anEnumWindowssweep confirmed zero visible top-level windows for the process — starts silently in the tray, no black-square flash.Reviewer notes
DEVELOPER.md). Manual check worth doing on Windows: launch, then tray icon → "Show Window", and confirm a capture hotkey (Print Screen) still fires.WindowStartupLocation="CenterScreen"is computed at handle-creation time insideCreateSourceWindow, so it is still honored even when the handle is realized early viaEnsureHandle().🤖 Generated with Claude Code