mirror of
https://github.com/KRTirtho/spotube.git
synced 2025-09-12 23:45:18 +00:00
feat(keyboard-shortcuts): home sidebar tab navigation and close app
This commit is contained in:
parent
2734454717
commit
8f258e709a
@ -37,6 +37,8 @@ List<String> spotifyScopes = [
|
||||
"playlist-read-collaborative"
|
||||
];
|
||||
|
||||
final selectedIndexState = StateProvider((ref) => 0);
|
||||
|
||||
class Home extends HookConsumerWidget {
|
||||
Home({Key? key}) : super(key: key);
|
||||
final logger = getLogger(Home);
|
||||
@ -51,8 +53,9 @@ class Home extends HookConsumerWidget {
|
||||
xxl: 256.0,
|
||||
);
|
||||
final extended = ref.watch(sidebarExtendedStateProvider);
|
||||
final _selectedIndex = useState(0);
|
||||
_onSelectedIndexChanged(int index) => _selectedIndex.value = index;
|
||||
final selectedIndex = ref.watch(selectedIndexState);
|
||||
onSelectedIndexChanged(int index) =>
|
||||
ref.read(selectedIndexState.notifier).state = index;
|
||||
|
||||
final downloader = ref.watch(downloaderProvider);
|
||||
final isMounted = useIsMounted();
|
||||
@ -115,12 +118,12 @@ class Home extends HookConsumerWidget {
|
||||
|
||||
return Scaffold(
|
||||
bottomNavigationBar: SpotubeNavigationBar(
|
||||
selectedIndex: _selectedIndex.value,
|
||||
onSelectedIndexChanged: _onSelectedIndexChanged,
|
||||
selectedIndex: selectedIndex,
|
||||
onSelectedIndexChanged: onSelectedIndexChanged,
|
||||
),
|
||||
body: Column(
|
||||
children: [
|
||||
if (_selectedIndex.value != 3)
|
||||
if (selectedIndex != 3)
|
||||
kIsMobile
|
||||
? titleBarContents
|
||||
: WindowTitleBarBox(child: titleBarContents),
|
||||
@ -128,11 +131,11 @@ class Home extends HookConsumerWidget {
|
||||
child: Row(
|
||||
children: [
|
||||
Sidebar(
|
||||
selectedIndex: _selectedIndex.value,
|
||||
onSelectedIndexChanged: _onSelectedIndexChanged,
|
||||
selectedIndex: selectedIndex,
|
||||
onSelectedIndexChanged: onSelectedIndexChanged,
|
||||
),
|
||||
// contents of the spotify
|
||||
if (_selectedIndex.value == 0)
|
||||
if (selectedIndex == 0)
|
||||
Expanded(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(
|
||||
@ -177,9 +180,9 @@ class Home extends HookConsumerWidget {
|
||||
}),
|
||||
),
|
||||
),
|
||||
if (_selectedIndex.value == 1) const Search(),
|
||||
if (_selectedIndex.value == 2) const UserLibrary(),
|
||||
if (_selectedIndex.value == 3) const SyncedLyrics(),
|
||||
if (selectedIndex == 1) const Search(),
|
||||
if (selectedIndex == 2) const UserLibrary(),
|
||||
if (selectedIndex == 3) const SyncedLyrics(),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
@ -211,12 +211,39 @@ class _SpotubeState extends ConsumerState<Spotube> with WidgetsBindingObserver {
|
||||
...WidgetsApp.defaultShortcuts,
|
||||
const SingleActivator(LogicalKeyboardKey.space): PlayPauseIntent(ref),
|
||||
const SingleActivator(LogicalKeyboardKey.comma, control: true):
|
||||
OpenSettingsIntent(_router),
|
||||
NavigationIntent(_router, "/settings"),
|
||||
const SingleActivator(
|
||||
LogicalKeyboardKey.keyB,
|
||||
control: true,
|
||||
shift: true,
|
||||
): HomeTabIntent(ref, tab: HomeTabs.browse),
|
||||
const SingleActivator(
|
||||
LogicalKeyboardKey.keyS,
|
||||
control: true,
|
||||
shift: true,
|
||||
): HomeTabIntent(ref, tab: HomeTabs.search),
|
||||
const SingleActivator(
|
||||
LogicalKeyboardKey.keyL,
|
||||
control: true,
|
||||
shift: true,
|
||||
): HomeTabIntent(ref, tab: HomeTabs.library),
|
||||
const SingleActivator(
|
||||
LogicalKeyboardKey.keyY,
|
||||
control: true,
|
||||
shift: true,
|
||||
): HomeTabIntent(ref, tab: HomeTabs.lyrics),
|
||||
const SingleActivator(
|
||||
LogicalKeyboardKey.keyW,
|
||||
control: true,
|
||||
shift: true,
|
||||
): CloseAppIntent(),
|
||||
},
|
||||
actions: {
|
||||
...WidgetsApp.defaultActions,
|
||||
PlayPauseIntent: PlayPauseAction(),
|
||||
OpenSettingsIntent: OpenSettingsAction(),
|
||||
NavigationIntent: NavigationAction(),
|
||||
HomeTabIntent: HomeTabAction(),
|
||||
CloseAppIntent: CloseAppAction(),
|
||||
},
|
||||
);
|
||||
}
|
||||
|
@ -1,10 +1,14 @@
|
||||
import 'package:bitsdojo_window/bitsdojo_window.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:spotify/spotify.dart';
|
||||
import 'package:spotube/components/Home/Home.dart';
|
||||
import 'package:spotube/components/Player/PlayerControls.dart';
|
||||
import 'package:spotube/models/Logger.dart';
|
||||
import 'package:spotube/provider/Playback.dart';
|
||||
import 'package:spotube/utils/platform.dart';
|
||||
|
||||
class PlayPauseIntent extends Intent {
|
||||
final WidgetRef ref;
|
||||
@ -40,16 +44,51 @@ class PlayPauseAction extends Action<PlayPauseIntent> {
|
||||
}
|
||||
}
|
||||
|
||||
class OpenSettingsIntent extends Intent {
|
||||
class NavigationIntent extends Intent {
|
||||
final GoRouter router;
|
||||
const OpenSettingsIntent(this.router);
|
||||
final String path;
|
||||
const NavigationIntent(this.router, this.path);
|
||||
}
|
||||
|
||||
class OpenSettingsAction extends Action<OpenSettingsIntent> {
|
||||
class NavigationAction extends Action<NavigationIntent> {
|
||||
@override
|
||||
invoke(intent) async {
|
||||
intent.router.push("/settings");
|
||||
FocusManager.instance.primaryFocus?.unfocus();
|
||||
invoke(intent) {
|
||||
intent.router.go(intent.path);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
enum HomeTabs {
|
||||
browse,
|
||||
search,
|
||||
library,
|
||||
lyrics,
|
||||
}
|
||||
|
||||
class HomeTabIntent extends Intent {
|
||||
final WidgetRef ref;
|
||||
final HomeTabs tab;
|
||||
const HomeTabIntent(this.ref, {required this.tab});
|
||||
}
|
||||
|
||||
class HomeTabAction extends Action<HomeTabIntent> {
|
||||
@override
|
||||
invoke(intent) {
|
||||
final notifier = intent.ref.read(selectedIndexState.notifier);
|
||||
switch (intent.tab) {
|
||||
case HomeTabs.browse:
|
||||
notifier.state = 0;
|
||||
break;
|
||||
case HomeTabs.search:
|
||||
notifier.state = 1;
|
||||
break;
|
||||
case HomeTabs.library:
|
||||
notifier.state = 2;
|
||||
break;
|
||||
case HomeTabs.lyrics:
|
||||
notifier.state = 3;
|
||||
break;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -83,3 +122,17 @@ class SeekAction extends Action<SeekIntent> {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
class CloseAppIntent extends Intent {}
|
||||
|
||||
class CloseAppAction extends Action<CloseAppIntent> {
|
||||
@override
|
||||
invoke(intent) {
|
||||
if (kIsDesktop) {
|
||||
appWindow.close();
|
||||
} else {
|
||||
SystemNavigator.pop();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user