Skip to content

Commit

Permalink
Fix #21 (keyboard long press) while addressing #9 (launching apps wit…
Browse files Browse the repository at this point in the history
…h mouse/touch)

* Modify FocusKeyboardListener according to the current needs
* Remove automatic release creation for now
  • Loading branch information
CocoCR300 committed Sep 13, 2024
1 parent 507ca85 commit 1c0131d
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 32 deletions.
12 changes: 1 addition & 11 deletions .github/workflows/continuous-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

17 changes: 1 addition & 16 deletions lib/widgets/app_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -97,22 +97,7 @@ class _AppCardState extends State<AppCard> 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(
Expand Down
10 changes: 6 additions & 4 deletions lib/widgets/focus_keyboard_listener.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,27 +43,29 @@ class _FocusKeyboardListenerState extends State<FocusKeyboardListener> {
@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),
);

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;
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down

0 comments on commit 1c0131d

Please sign in to comment.