Skip to content

Fix closeOverlay() hanging forever when overlay isn't running - #183

Open
mtranchi wants to merge 2 commits into
X-SLAYER:mainfrom
mtranchi:fix/close-overlay-hang-when-not-running
Open

Fix closeOverlay() hanging forever when overlay isn't running#183
mtranchi wants to merge 2 commits into
X-SLAYER:mainfrom
mtranchi:fix/close-overlay-hang-when-not-running

Conversation

@mtranchi

@mtranchi mtranchi commented Jul 4, 2026

Copy link
Copy Markdown

Summary

Two separate bugs, both in overlay service lifecycle handling:

  1. Fixes closeOverlay() hangs forever when overlay isn't currently running #182 — `closeOverlay`'s handler only calls `result.success(true)` inside the `if (OverlayService.isRunning)` branch. When the overlay isn't currently running, execution falls through to `return` without ever calling `result.success`/`result.error`, leaving the Dart-side `await FlutterOverlayWindow.closeOverlay()` pending forever.

  2. Fixes showOverlay() called while already active tears the whole service down moments later #184 — `onStartCommand`'s "already running" branch calls `stopSelf()` before falling through to recreate and re-add the view. `stopSelf()` only schedules a stop rather than returning immediately, so a new view gets added successfully, then Android processes the pending stop shortly after and tears the whole service down via `onDestroy()`. Calling `showOverlay()` a second time while already showing makes the overlay flash visible, then disappear for good.

Changes

  • `closeOverlay`: added an `else { result.success(false); }` branch so the method channel call always resolves.
  • `onStartCommand`: removed the stray `stopSelf()` call from the "recreate view" branch — recreating the view in place shouldn't stop the service.

Testing

Verified against a real device (Samsung Galaxy A36) for both fixes.

mtranchi added 2 commits July 4, 2026 13:51
result.success/error was never called in the branch where OverlayService
isn't currently running, leaving the Dart-side awaited Future pending
indefinitely. Adds an else branch so the method channel call always
resolves.

Fixes X-SLAYER#182
…active

onStartCommand's "already running, recreate view" branch called stopSelf()
before falling through to recreate and re-add the view. stopSelf() only
schedules a stop, it doesn't return immediately, so execution continued,
successfully re-added a new view, and then shortly after Android processed
the pending stop and destroyed the whole service (including the just-added
view) via onDestroy(). Net effect: calling showOverlay() a second time while
already showing makes the overlay flash briefly visible, then disappear for
good.

Removes the stray stopSelf() call — recreating the view in place shouldn't
stop the service at all.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant