feat: Mapped photo viewer controls to new hotkeys

This commit is contained in:
PartyDonut 2025-09-01 21:52:47 +02:00
parent fbd1d762d3
commit a2684d1d0a
2 changed files with 52 additions and 41 deletions

View file

@ -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<PhotoViewerControls> 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<PhotoViewerControls> 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<PhotoViewerControls> 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<void> markAsFavourite() async {
final response =
await ref.read(userProvider.notifier).setAsFavorite(!widget.photo.userData.isFavourite, widget.photo.id);

View file

@ -77,7 +77,7 @@ class _DesktopControlsState extends ConsumerState<DesktopControls> {
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) {