mirror of
https://github.com/KRTirtho/spotube.git
synced 2025-09-13 07:55:18 +00:00

PlayerControls slider & duration are now vertical hotkey init moved to Home Player & YoutubeExplode are provided through riverpod Playback handles all things Player used to do GoRoutes are seperated from main to individual model file usePaletteColor bugfix occuring for before initilizing mount
46 lines
1.4 KiB
Dart
46 lines
1.4 KiB
Dart
import 'package:flutter_hooks/flutter_hooks.dart';
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
import 'package:hotkey_manager/hotkey_manager.dart';
|
|
import 'package:spotube/hooks/playback.dart';
|
|
import 'package:spotube/models/GlobalKeyActions.dart';
|
|
import 'package:spotube/provider/Playback.dart';
|
|
import 'package:spotube/provider/UserPreferences.dart';
|
|
|
|
useHotKeys(WidgetRef ref) {
|
|
final playback = ref.watch(playbackProvider);
|
|
final preferences = ref.watch(userPreferencesProvider);
|
|
List<GlobalKeyActions> _hotKeys = [];
|
|
|
|
final onNext = useNextTrack(playback);
|
|
|
|
final onPrevious = usePreviousTrack(playback);
|
|
|
|
final _playOrPause = useTogglePlayPause(playback);
|
|
|
|
useEffect(() {
|
|
_hotKeys = [
|
|
GlobalKeyActions(
|
|
HotKey(KeyCode.space, scope: HotKeyScope.inapp),
|
|
_playOrPause,
|
|
),
|
|
if (preferences.nextTrackHotKey != null)
|
|
GlobalKeyActions(preferences.nextTrackHotKey!, (key) => onNext()),
|
|
if (preferences.prevTrackHotKey != null)
|
|
GlobalKeyActions(preferences.prevTrackHotKey!, (key) => onPrevious()),
|
|
if (preferences.playPauseHotKey != null)
|
|
GlobalKeyActions(preferences.playPauseHotKey!, _playOrPause)
|
|
];
|
|
Future.wait(
|
|
_hotKeys.map((e) {
|
|
return hotKeyManager.register(
|
|
e.hotKey,
|
|
keyDownHandler: e.onKeyDown,
|
|
);
|
|
}),
|
|
);
|
|
return () {
|
|
Future.wait(_hotKeys.map((e) => hotKeyManager.unregister(e.hotKey)));
|
|
};
|
|
});
|
|
}
|