Skip to content

fix(legacy): report show/hide and fix restore tracking - #602

Open
palmoni5 wants to merge 1 commit into
leanflutter:mainfrom
palmoni5:upstream/legacy-show-hide-restore
Open

palmoni5 wants to merge 1 commit into
leanflutter:mainfrom
palmoni5:upstream/legacy-show-hide-restore

Conversation

@palmoni5

@palmoni5 palmoni5 commented Nov 10, 2026 •

Copy link
Copy Markdown

Problem

Two gaps in the 0.5.x bridge (package:window_manager/legacy.dart):

  • No show/hide events. nativeapi has no show/hide window event, so code that pauses and resumes work on onWindowEvent('show' / 'hide') never hears about it under the bridge.
  • Stale minimized state. A minimized window that is maximized comes back with a maximized event alone. The bridge kept believing it was minimized, so the next restored event was reported as restore instead of unmaximize.

Change

  • show() / hide() emit onWindowEvent('show' / 'hide') only when the call actually changes the window's visibility, re-checked after the native call (a refused or no-op change emits nothing). When hiding, a minimized window counts as shown, since macOS reports it as not visible. Visibility changes made outside the legacy API are still not reported, as nativeapi offers no event for them.
  • A maximized event clears the minimized flag; a restored event re-reads isMaximized from the window instead of guessing.
  • @visibleForTesting debugBindWindow(nativeapi.Window?) lets tests drive the bridge with a simulated nativeapi.Window.

Tests

New test/legacy_visibility_test.dart with a fake nativeapi.Window: show/hide only on visibility change (including minimized windows), nothing when the platform refuses the change, restore/unmaximize tracking in both orders, and the named callbacks following the tracked state.

dart format --set-exit-if-changed ., flutter analyze (package and example) and flutter test (package and example) pass locally (Flutter 3.47.7, Windows), and the full CI workflow passes on the identical commit in my fork.

Related

Part of a set of independent PRs, each based on main and mergeable on its own: widgets #598, #599, #600, #601; legacy bridge #602 (this), #603, #604, #605, #606.

#604 and #605 add the identical debugBindWindow test seam and merge cleanly with this PR. Expected conflict with #606 (late window resolution) in show()/hide(): resolve by keeping #606's pending-show handling and moving this PR's visibility check and show/hide emits into _showWindow/hide(); debugBindWindow can then delegate to bindWindow.

nativeapi has no show/hide window event, so 0.5.x code that pauses and
resumes work on onWindowEvent('show'/'hide') went silent under the
legacy bridge. show() and hide() now emit those events when the call
actually changes the window's visibility, re-checked after the native
call. When hiding, a minimized window counts as shown, since macOS
reports it as not visible. Visibility changes made outside the legacy
API are still not reported: nativeapi offers no event for them.

A minimized window that is maximized comes back with a maximized event
alone, which left the bridge believing it was still minimized, so the
next restored event was reported as restore instead of unmaximize. A
maximized event now clears the minimized flag, and a restored event
re-reads isMaximized from the window instead of guessing.

Adds a @VisibleForTesting debugBindWindow so the bridge can be driven
by a simulated nativeapi.Window in tests.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant