From f6a2f19a4aba45e1235fcce0015478bc2a617bd5 Mon Sep 17 00:00:00 2001 From: edde746 <86283021+edde746@users.noreply.github.com> Date: Tue, 27 Jan 2026 15:15:56 +0100 Subject: [PATCH] fix: keyboard shortcuts stop working close #342 --- .../video_controls/video_controls.dart | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/lib/widgets/video_controls/video_controls.dart b/lib/widgets/video_controls/video_controls.dart index 83933e46..3c552c11 100644 --- a/lib/widgets/video_controls/video_controls.dart +++ b/lib/widgets/video_controls/video_controls.dart @@ -562,6 +562,13 @@ class _PlexVideoControlsState extends State with WindowListen if (Platform.isMacOS) { _updateTrafficLightVisibility(); } + // Restore focus to the main node so keyboard shortcuts keep working + // after FocusScope(canRequestFocus: false) ejects child focus. + WidgetsBinding.instance.addPostFrameCallback((_) { + if (mounted && !_focusNode.hasFocus) { + _focusNode.requestFocus(); + } + }); } }); } @@ -1217,6 +1224,27 @@ class _PlexVideoControlsState extends State with WindowListen return true; // Event handled, stop propagation } + // Fallback: handle all other shortcuts when focus has drifted away + // (e.g. after controls auto-hide). The !hasFocus guard prevents + // double-handling when the Focus onKeyEvent already processes the event. + if (!_focusNode.hasFocus && _keyboardService != null) { + final result = _keyboardService!.handleVideoPlayerKeyEvent( + event, + widget.player, + _toggleFullscreen, + _toggleSubtitles, + _nextAudioTrack, + _nextSubtitleTrack, + _nextChapter, + _previousChapter, + onBack: widget.onBack ?? () => Navigator.of(context).pop(true), + ); + if (result == KeyEventResult.handled) { + _focusNode.requestFocus(); // self-heal focus + return true; + } + } + return false; // Let event continue to other handlers }