From a2684d1d0ac2874b06b7477914bfdb555af30f7c Mon Sep 17 00:00:00 2001 From: PartyDonut Date: Mon, 1 Sep 2025 21:52:47 +0200 Subject: [PATCH] feat: Mapped photo viewer controls to new hotkeys --- .../photo_viewer/photo_viewer_controls.dart | 91 +++++++++++-------- .../video_player/video_player_controls.dart | 2 +- 2 files changed, 52 insertions(+), 41 deletions(-) diff --git a/lib/screens/photo_viewer/photo_viewer_controls.dart b/lib/screens/photo_viewer/photo_viewer_controls.dart index f1ec2df..8f61473 100644 --- a/lib/screens/photo_viewer/photo_viewer_controls.dart +++ b/lib/screens/photo_viewer/photo_viewer_controls.dart @@ -1,5 +1,4 @@ import 'package:flutter/material.dart'; -import 'package:flutter/services.dart'; import 'package:dynamic_color/dynamic_color.dart'; import 'package:extended_image/extended_image.dart'; @@ -12,7 +11,9 @@ import 'package:wakelock_plus/wakelock_plus.dart'; import 'package:window_manager/window_manager.dart'; import 'package:fladder/models/items/photos_model.dart'; +import 'package:fladder/models/settings/video_player_settings.dart'; import 'package:fladder/providers/settings/photo_view_settings_provider.dart'; +import 'package:fladder/providers/settings/video_player_settings_provider.dart'; import 'package:fladder/providers/user_provider.dart'; import 'package:fladder/screens/shared/flat_button.dart'; import 'package:fladder/screens/shared/input_fields.dart'; @@ -74,43 +75,6 @@ class _PhotoViewerControllsState extends ConsumerState with } } - bool _onKey(KeyEvent value) { - if (value is KeyRepeatEvent) { - if (value.logicalKey == LogicalKeyboardKey.arrowLeft) { - throttler.run(() => - widget.pageController.previousPage(duration: const Duration(milliseconds: 125), curve: Curves.easeInOut)); - return true; - } - if (value.logicalKey == LogicalKeyboardKey.arrowRight) { - throttler.run( - () => widget.pageController.nextPage(duration: const Duration(milliseconds: 125), curve: Curves.easeInOut)); - return true; - } - } - if (value is KeyDownEvent) { - if (value.logicalKey == LogicalKeyboardKey.arrowLeft) { - throttler.run(() => - widget.pageController.previousPage(duration: const Duration(milliseconds: 125), curve: Curves.easeInOut)); - return true; - } - if (value.logicalKey == LogicalKeyboardKey.arrowRight) { - throttler.run( - () => widget.pageController.nextPage(duration: const Duration(milliseconds: 125), curve: Curves.easeInOut)); - return true; - } - - if (value.logicalKey == LogicalKeyboardKey.keyK) { - timerController.playPause(); - return true; - } - if (value.logicalKey == LogicalKeyboardKey.space) { - widget.toggleOverlay?.call(null); - return true; - } - } - return false; - } - @override void initState() { super.initState(); @@ -152,8 +116,9 @@ class _PhotoViewerControllsState extends ConsumerState with return PopScope( onPopInvokedWithResult: (didPop, result) async => await WakelockPlus.disable(), child: InputHandler( - autoFocus: false, - onKeyEvent: (node, event) => _onKey(event) ? KeyEventResult.handled : KeyEventResult.ignored, + autoFocus: true, + keyMap: ref.watch(videoPlayerSettingsProvider.select((value) => value.currentShortcuts)), + keyMapResult: _onKey, child: Stack( children: [ Align( @@ -349,6 +314,52 @@ class _PhotoViewerControllsState extends ConsumerState with ); } + bool _onKey(VideoHotKeys value) { + switch (value) { + case VideoHotKeys.playPause: + widget.toggleOverlay?.call(null); + return true; + case VideoHotKeys.fullScreen: + fullScreenHelper.toggleFullScreen(ref); + return true; + case VideoHotKeys.skipMediaSegment: + timerController.playPause(); + return true; + case VideoHotKeys.exit: + fullScreenHelper.closeFullScreen(ref); + return true; + case VideoHotKeys.mute: + ref.read(photoViewSettingsProvider.notifier).update((state) => state.copyWith(mute: !state.mute)); + return true; + case VideoHotKeys.seekForward: + throttler.run( + () => widget.pageController.nextPage(duration: const Duration(milliseconds: 125), curve: Curves.easeInOut)); + return true; + case VideoHotKeys.seekBack: + throttler.run(() => + widget.pageController.previousPage(duration: const Duration(milliseconds: 125), curve: Curves.easeInOut)); + return true; + case VideoHotKeys.nextVideo: + throttler.run( + () => widget.pageController.nextPage(duration: const Duration(milliseconds: 125), curve: Curves.easeInOut)); + return true; + case VideoHotKeys.prevVideo: + throttler.run(() => + widget.pageController.previousPage(duration: const Duration(milliseconds: 125), curve: Curves.easeInOut)); + return true; + case VideoHotKeys.nextChapter: + throttler.run( + () => widget.pageController.nextPage(duration: const Duration(milliseconds: 125), curve: Curves.easeInOut)); + return true; + case VideoHotKeys.prevChapter: + throttler.run(() => + widget.pageController.previousPage(duration: const Duration(milliseconds: 125), curve: Curves.easeInOut)); + return true; + default: + return false; + } + } + Future markAsFavourite() async { final response = await ref.read(userProvider.notifier).setAsFavorite(!widget.photo.userData.isFavourite, widget.photo.id); diff --git a/lib/screens/video_player/video_player_controls.dart b/lib/screens/video_player/video_player_controls.dart index 73302df..6639b57 100644 --- a/lib/screens/video_player/video_player_controls.dart +++ b/lib/screens/video_player/video_player_controls.dart @@ -77,7 +77,7 @@ class _DesktopControlsState extends ConsumerState { child: InputHandler( autoFocus: true, keyMap: ref.watch(videoPlayerSettingsProvider.select((value) => value.currentShortcuts)), - keyMapResult: (result) => _onKey(result), + keyMapResult: _onKey, child: PopScope( canPop: false, onPopInvokedWithResult: (didPop, result) {