From 1c0131dcf0f88ba2f437f2b7c23eb23aff0d10cb Mon Sep 17 00:00:00 2001 From: CocoCR300 <55771921+CocoCR300@users.noreply.github.com> Date: Thu, 12 Sep 2024 21:13:24 -0600 Subject: [PATCH] Fix #21 (keyboard long press) while addressing #9 (launching apps with mouse/touch) * Modify FocusKeyboardListener according to the current needs * Remove automatic release creation for now --- .github/workflows/continuous-release.yml | 12 +----------- lib/widgets/app_card.dart | 17 +---------------- lib/widgets/focus_keyboard_listener.dart | 10 ++++++---- pubspec.yaml | 2 +- 4 files changed, 9 insertions(+), 32 deletions(-) diff --git a/.github/workflows/continuous-release.yml b/.github/workflows/continuous-release.yml index 3d6afa9..fece620 100644 --- a/.github/workflows/continuous-release.yml +++ b/.github/workflows/continuous-release.yml @@ -45,16 +45,6 @@ jobs: - name: Upload APKs as artifact uses: actions/upload-artifact@v4 with: - name: flauncher-continuous-release + name: flauncher-release path: ${{ env.OUTPUT_DIR }}/flauncher-*.apk retention-days: 30 - - name: Delete last continuous release - continue-on-error: true - env: - GH_TOKEN: ${{ secrets.CI_ACCESS_TOKEN }} - run: gh release delete continuous --yes - - name: Create release - env: - GH_TOKEN: ${{ secrets.CI_ACCESS_TOKEN }} - run: gh release create continuous --title "Continuous release" --notes "" $OUTPUT_DIR/flauncher-*.apk - diff --git a/lib/widgets/app_card.dart b/lib/widgets/app_card.dart index 7a8c4ce..357e328 100644 --- a/lib/widgets/app_card.dart +++ b/lib/widgets/app_card.dart @@ -97,22 +97,7 @@ class _AppCardState extends State with SingleTickerProviderStateMixin { @override Widget build(BuildContext context) => FocusKeyboardListener( - onPressed: (key) { - // A duplicate press occurs on "app cards" if both the - // FocusKeyboardListener and another widget - // (InkWell or GestureDetector, see below) handle the onPress and onTap, - // respectively, causing an attempt to open applications twice, - // though this is only visible when opening the settings side panel on TVs. - // Still, both handlers are needed to open applications using a touch - // screen, TV remote, and keyboards, as well as being able to drag the - // card in the "dragging mode", this is why only the Enter key is ignored - // here. - if (key == LogicalKeyboardKey.enter) { - return KeyEventResult.ignored; - } - - return _onPressed(context, key); - }, + onPressed: (key) => _onPressed(context, key), onLongPress: (key) => _onLongPress(context, key), builder: (context) { return AspectRatio( diff --git a/lib/widgets/focus_keyboard_listener.dart b/lib/widgets/focus_keyboard_listener.dart index ab5ff7f..dc61743 100644 --- a/lib/widgets/focus_keyboard_listener.dart +++ b/lib/widgets/focus_keyboard_listener.dart @@ -43,6 +43,8 @@ class _FocusKeyboardListenerState extends State { @override Widget build(BuildContext context) => Focus( canRequestFocus: false, + // Using "onKeyEvent", in favor of the deprecated "onKey" + // seems to break the fix for issue #21 so, keep using the old property onKey: (_, rawKeyEvent) => _handleKey(context, rawKeyEvent), child: Builder(builder: widget.builder), ); @@ -50,20 +52,20 @@ class _FocusKeyboardListenerState extends State { KeyEventResult _handleKey(BuildContext context, RawKeyEvent rawKeyEvent) { switch (rawKeyEvent.runtimeType) { case RawKeyDownEvent: - return _keyDownEvent(context, rawKeyEvent.logicalKey, (rawKeyEvent.data as RawKeyEventDataAndroid)); + return _keyDownEvent(context, rawKeyEvent.logicalKey); case RawKeyUpEvent: return _keyUpEvent(context, rawKeyEvent.logicalKey); } return KeyEventResult.handled; } - KeyEventResult _keyDownEvent(BuildContext context, LogicalKeyboardKey key, RawKeyEventDataAndroid data) { + KeyEventResult _keyDownEvent(BuildContext context, LogicalKeyboardKey key) { if (!longPressableKeys.contains(key)) { return widget.onPressed?.call(key) ?? KeyEventResult.ignored; } - if (data.repeatCount == 0) { + if (_keyDownAt == null) { _keyDownAt = DateTime.now().millisecondsSinceEpoch; - return KeyEventResult.ignored; + return KeyEventResult.handled; } else if (_longPress()) { _keyDownAt = null; return widget.onLongPress?.call(key) ?? KeyEventResult.ignored; diff --git a/pubspec.yaml b/pubspec.yaml index ae7c039..ea40323 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,7 +1,7 @@ name: flauncher description: Flutter-based Android TV launcher. -version: 0.0.1 +version: 2024.09.002+13 environment: sdk: ">=3.4.3"