Skip to content

Commit

Permalink
feat: manually detect and define touch behavior #1763
Browse files Browse the repository at this point in the history
  • Loading branch information
KRTirtho committed Aug 18, 2024
1 parent 4111153 commit af60cfc
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
29 changes: 29 additions & 0 deletions lib/hooks/configurators/use_pointer_devices.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:spotube/utils/platform.dart';

Set<PointerDeviceKind> usePointerDevices() {
final devices = useState<Set<PointerDeviceKind>>({
if (kIsMobile) PointerDeviceKind.touch,
if (kIsDesktop || kIsWeb) PointerDeviceKind.mouse,
});

useEffect(() {
WidgetsBinding.instance.addPostFrameCallback((_) {
GestureBinding.instance.pointerRouter
.addGlobalRoute((PointerEvent event) {
if (devices.value.contains(event.kind)) return;
devices.value = {
...devices.value,
event.kind,
};
});
});

return null;
}, []);

return devices.value;
}
8 changes: 7 additions & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import 'package:spotube/hooks/configurators/use_deep_linking.dart';
import 'package:spotube/hooks/configurators/use_disable_battery_optimizations.dart';
import 'package:spotube/hooks/configurators/use_fix_window_stretching.dart';
import 'package:spotube/hooks/configurators/use_get_storage_perms.dart';
import 'package:spotube/hooks/configurators/use_pointer_devices.dart';
import 'package:spotube/models/database/database.dart';
import 'package:spotube/provider/audio_player/audio_player_streams.dart';
import 'package:spotube/provider/database/database.dart';
Expand Down Expand Up @@ -92,7 +93,7 @@ Future<void> main(List<String> rawArgs) async {
await FlutterDiscordRPC.initialize(Env.discordAppId);
}

if(kIsWindows){
if (kIsWindows) {
await SMTCWindows.initialize();
}

Expand Down Expand Up @@ -142,6 +143,7 @@ class Spotube extends HookConsumerWidget {
final paletteColor =
ref.watch(paletteProvider.select((s) => s?.dominantColor?.color));
final router = ref.watch(routerProvider);
final pointerDevices = usePointerDevices();

ref.listen(audioPlayerStreamListenersProvider, (_, __) {});
ref.listen(bonsoirProvider, (_, __) {});
Expand Down Expand Up @@ -179,6 +181,10 @@ class Spotube extends HookConsumerWidget {
);

return MaterialApp.router(
scrollBehavior: const MaterialScrollBehavior()
..copyWith(
dragDevices: pointerDevices,
),
supportedLocales: L10n.all,
locale: locale.languageCode == "system" ? null : locale,
localizationsDelegates: const [
Expand Down

0 comments on commit af60cfc

Please sign in to comment.