Fix cursor hidden and audio leak after closing media viewer#1357
Open
SnoElement wants to merge 2 commits intoovertake:masterfrom
Open
Fix cursor hidden and audio leak after closing media viewer#1357SnoElement wants to merge 2 commits intoovertake:masterfrom
SnoElement wants to merge 2 commits intoovertake:masterfrom
Conversation
Bug 1 — cursor stays hidden system-wide after media viewer closes (fixes overtake#1303): - SVideoController: track cursor visibility with isCursorHidden flag so every NSCursor.hide() is paired with exactly one NSCursor.unhide(). The idle timer and the fullscreen mouseDown path both called NSCursor.hide() independently, but viewDidDisappear only called NSCursor.unhide() once, leaving the macOS reference count unbalanced. - GalleryViewer.close(animated:false): call selectedItem?.disappear() before ordering the window out, so viewDidDisappear (and cursor restore) always runs. Bug 2 — audio continues playing after navigating away or closing viewer: - MediaPlayer.seekingCompleted: re-read the current playback action from self.state inside the async audioRenderer.flushBuffers completion closure instead of using the value captured at seek time. A pause() call made while the flush is in flight was being silently ignored because the closure held a stale .play action, causing audio to start even after the viewer was dismissed.
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.
Fixes #1303
Also fixes #269
Changes
Bug 1 - Cursor stays hidden system-wide after media viewer closes
Root cause: macOS cursor visibility uses a reference-counted system - NSCursor.hide() and NSCursor.unhide() must be balanced. Two separate code paths in SVideoController called NSCursor.hide():
But viewDidDisappear() only called NSCursor.unhide() once, leaving the reference count unbalanced when both paths had fired. Additionally, GalleryViewer.close(animated: false) ordered the window out without ever calling item.disappear(), so viewDidDisappear() (and its NSCursor.unhide()) never ran at all on non-animated closes (for example pressing Escape).
Fixes (SVideoController.swift, GalleryViewer.swift):
Bug 2 - Audio continues playing after navigating away or closing the viewer
Root cause: In MediaPlayerContext.seekingCompleted(), the current playback action (for example .play) is read from self.state and captured into the audioRenderer.flushBuffers(completion:) closure. While the flush is in flight, if pause() is called (for example the user navigates to the next item or closes the viewer), self.state's action is updated to .pause - but the completion closure uses the stale captured .play, sets state to .playing, and starts the audio renderer anyway.
This is particularly noticeable with large remote videos on slow connections, where buffering causes a long flush that outlasts viewer dismissal.
Fix (packages/TelegramMedia/Sources/MediaPlayer.swift):
Bug 3 - Full-screen media viewer behaves incorrectly across multiple monitors
Root cause: GalleryViewer always created its full-screen window on NSScreen.main and forcibly reclaimed key-window status on resign. When the app focus moved to another display, the viewer could close unexpectedly or leave Telegram in a bad state that required relaunch.
Fixes (GalleryViewer.swift, AppDelegate.swift):