fix: keyboard shortcuts stop working

close #342
This commit is contained in:
edde746
2026-01-27 15:20:26 +01:00
parent 6e2b3082d4
commit f6a2f19a4a
@@ -562,6 +562,13 @@ class _PlexVideoControlsState extends State<PlexVideoControls> 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<PlexVideoControls> 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
}