From 39de990fae487ca83bab5b441723956732657df0 Mon Sep 17 00:00:00 2001 From: Krille Date: Mon, 11 Nov 2024 16:03:52 +0100 Subject: [PATCH] refactor: Remove keyboard shortcuts This package right now makes the web app nearly unusable as it throws multiple errors on every key press. The package seems to be unmaintained. I tried two other packages and none of them worked. --- lib/pages/chat/chat_input_row.dart | 181 ++++++++---------- lib/pages/chat_list/chat_list_view.dart | 36 ++-- .../chat_list/client_chooser_button.dart | 114 +---------- lib/widgets/chat_settings_popup_menu.dart | 12 +- macos/Runner.xcodeproj/project.pbxproj | 2 +- .../xcshareddata/xcschemes/Runner.xcscheme | 2 +- macos/Runner/AppDelegate.swift | 2 +- pubspec.lock | 16 -- pubspec.yaml | 1 - 9 files changed, 101 insertions(+), 265 deletions(-) diff --git a/lib/pages/chat/chat_input_row.dart b/lib/pages/chat/chat_input_row.dart index cd41989d22..9d4fe4602d 100644 --- a/lib/pages/chat/chat_input_row.dart +++ b/lib/pages/chat/chat_input_row.dart @@ -1,10 +1,8 @@ import 'package:flutter/material.dart'; -import 'package:flutter/services.dart'; import 'package:animations/animations.dart'; import 'package:flutter_gen/gen_l10n/l10n.dart'; import 'package:matrix/matrix.dart'; -import 'package:new_keyboard_shortcuts/keyboard_shortcuts.dart'; import 'package:fluffychat/config/app_config.dart'; import 'package:fluffychat/utils/platform_infos.dart'; @@ -96,130 +94,113 @@ class ChatInputRow extends StatelessWidget { ] : [ const SizedBox(width: 4), - KeyBoardShortcuts( - keysToPress: { - LogicalKeyboardKey.altLeft, - LogicalKeyboardKey.keyA, - }, - onKeysPressed: () => - controller.onAddPopupMenuButtonSelected('file'), - helpLabel: L10n.of(context).sendFile, - child: AnimatedContainer( - duration: FluffyThemes.animationDuration, - curve: FluffyThemes.animationCurve, - height: height, - width: controller.sendController.text.isEmpty ? height : 0, - alignment: Alignment.center, - clipBehavior: Clip.hardEdge, - decoration: const BoxDecoration(), - child: PopupMenuButton( - icon: const Icon(Icons.add_outlined), - onSelected: controller.onAddPopupMenuButtonSelected, - itemBuilder: (BuildContext context) => - >[ + AnimatedContainer( + duration: FluffyThemes.animationDuration, + curve: FluffyThemes.animationCurve, + height: height, + width: controller.sendController.text.isEmpty ? height : 0, + alignment: Alignment.center, + clipBehavior: Clip.hardEdge, + decoration: const BoxDecoration(), + child: PopupMenuButton( + icon: const Icon(Icons.add_outlined), + onSelected: controller.onAddPopupMenuButtonSelected, + itemBuilder: (BuildContext context) => + >[ + PopupMenuItem( + value: 'file', + child: ListTile( + leading: const CircleAvatar( + backgroundColor: Colors.green, + foregroundColor: Colors.white, + child: Icon(Icons.attachment_outlined), + ), + title: Text(L10n.of(context).sendFile), + contentPadding: const EdgeInsets.all(0), + ), + ), + PopupMenuItem( + value: 'image', + child: ListTile( + leading: const CircleAvatar( + backgroundColor: Colors.blue, + foregroundColor: Colors.white, + child: Icon(Icons.image_outlined), + ), + title: Text(L10n.of(context).sendImage), + contentPadding: const EdgeInsets.all(0), + ), + ), + if (PlatformInfos.isMobile) PopupMenuItem( - value: 'file', + value: 'camera', child: ListTile( leading: const CircleAvatar( - backgroundColor: Colors.green, + backgroundColor: Colors.purple, foregroundColor: Colors.white, - child: Icon(Icons.attachment_outlined), + child: Icon(Icons.camera_alt_outlined), ), - title: Text(L10n.of(context).sendFile), + title: Text(L10n.of(context).openCamera), contentPadding: const EdgeInsets.all(0), ), ), + if (PlatformInfos.isMobile) PopupMenuItem( - value: 'image', + value: 'camera-video', child: ListTile( leading: const CircleAvatar( - backgroundColor: Colors.blue, + backgroundColor: Colors.red, foregroundColor: Colors.white, - child: Icon(Icons.image_outlined), + child: Icon(Icons.videocam_outlined), ), - title: Text(L10n.of(context).sendImage), + title: Text(L10n.of(context).openVideoCamera), contentPadding: const EdgeInsets.all(0), ), ), - if (PlatformInfos.isMobile) - PopupMenuItem( - value: 'camera', - child: ListTile( - leading: const CircleAvatar( - backgroundColor: Colors.purple, - foregroundColor: Colors.white, - child: Icon(Icons.camera_alt_outlined), - ), - title: Text(L10n.of(context).openCamera), - contentPadding: const EdgeInsets.all(0), - ), - ), - if (PlatformInfos.isMobile) - PopupMenuItem( - value: 'camera-video', - child: ListTile( - leading: const CircleAvatar( - backgroundColor: Colors.red, - foregroundColor: Colors.white, - child: Icon(Icons.videocam_outlined), - ), - title: Text(L10n.of(context).openVideoCamera), - contentPadding: const EdgeInsets.all(0), - ), - ), - if (PlatformInfos.isMobile) - PopupMenuItem( - value: 'location', - child: ListTile( - leading: const CircleAvatar( - backgroundColor: Colors.brown, - foregroundColor: Colors.white, - child: Icon(Icons.gps_fixed_outlined), - ), - title: Text(L10n.of(context).shareLocation), - contentPadding: const EdgeInsets.all(0), + if (PlatformInfos.isMobile) + PopupMenuItem( + value: 'location', + child: ListTile( + leading: const CircleAvatar( + backgroundColor: Colors.brown, + foregroundColor: Colors.white, + child: Icon(Icons.gps_fixed_outlined), ), + title: Text(L10n.of(context).shareLocation), + contentPadding: const EdgeInsets.all(0), ), - ], - ), + ), + ], ), ), Container( height: height, width: height, alignment: Alignment.center, - child: KeyBoardShortcuts( - keysToPress: { - LogicalKeyboardKey.altLeft, - LogicalKeyboardKey.keyE, - }, - onKeysPressed: controller.emojiPickerAction, - helpLabel: L10n.of(context).emojis, - child: IconButton( - tooltip: L10n.of(context).emojis, - icon: PageTransitionSwitcher( - transitionBuilder: ( - Widget child, - Animation primaryAnimation, - Animation secondaryAnimation, - ) { - return SharedAxisTransition( - animation: primaryAnimation, - secondaryAnimation: secondaryAnimation, - transitionType: SharedAxisTransitionType.scaled, - fillColor: Colors.transparent, - child: child, - ); - }, - child: Icon( - controller.showEmojiPicker - ? Icons.keyboard - : Icons.add_reaction_outlined, - key: ValueKey(controller.showEmojiPicker), - ), + child: IconButton( + tooltip: L10n.of(context).emojis, + icon: PageTransitionSwitcher( + transitionBuilder: ( + Widget child, + Animation primaryAnimation, + Animation secondaryAnimation, + ) { + return SharedAxisTransition( + animation: primaryAnimation, + secondaryAnimation: secondaryAnimation, + transitionType: SharedAxisTransitionType.scaled, + fillColor: Colors.transparent, + child: child, + ); + }, + child: Icon( + controller.showEmojiPicker + ? Icons.keyboard + : Icons.add_reaction_outlined, + key: ValueKey(controller.showEmojiPicker), ), - onPressed: controller.emojiPickerAction, ), + onPressed: controller.emojiPickerAction, ), ), if (Matrix.of(context).isMultiAccount && diff --git a/lib/pages/chat_list/chat_list_view.dart b/lib/pages/chat_list/chat_list_view.dart index 7a928c10fa..5d24948133 100644 --- a/lib/pages/chat_list/chat_list_view.dart +++ b/lib/pages/chat_list/chat_list_view.dart @@ -1,10 +1,8 @@ import 'package:flutter/material.dart'; -import 'package:flutter/services.dart'; import 'package:flutter_gen/gen_l10n/l10n.dart'; import 'package:go_router/go_router.dart'; import 'package:matrix/matrix.dart'; -import 'package:new_keyboard_shortcuts/keyboard_shortcuts.dart'; import 'package:fluffychat/config/app_config.dart'; import 'package:fluffychat/config/themes.dart'; @@ -138,27 +136,19 @@ class ChatListView extends StatelessWidget { behavior: HitTestBehavior.translucent, child: Scaffold( body: ChatListViewBody(controller), - floatingActionButton: KeyBoardShortcuts( - keysToPress: { - LogicalKeyboardKey.controlLeft, - LogicalKeyboardKey.keyN, - }, - onKeysPressed: () => context.go('/rooms/newprivatechat'), - helpLabel: L10n.of(context).newChat, - child: selectMode == SelectMode.normal && - !controller.isSearchMode && - controller.activeSpaceId == null - ? FloatingActionButton.extended( - onPressed: () => - context.go('/rooms/newprivatechat'), - icon: const Icon(Icons.add_outlined), - label: Text( - L10n.of(context).chat, - overflow: TextOverflow.fade, - ), - ) - : const SizedBox.shrink(), - ), + floatingActionButton: selectMode == SelectMode.normal && + !controller.isSearchMode && + controller.activeSpaceId == null + ? FloatingActionButton.extended( + onPressed: () => + context.go('/rooms/newprivatechat'), + icon: const Icon(Icons.add_outlined), + label: Text( + L10n.of(context).chat, + overflow: TextOverflow.fade, + ), + ) + : const SizedBox.shrink(), ), ), ), diff --git a/lib/pages/chat_list/client_chooser_button.dart b/lib/pages/chat_list/client_chooser_button.dart index 16de237321..5ec81bd5b6 100644 --- a/lib/pages/chat_list/client_chooser_button.dart +++ b/lib/pages/chat_list/client_chooser_button.dart @@ -1,11 +1,9 @@ import 'package:flutter/material.dart'; -import 'package:flutter/services.dart'; import 'package:adaptive_dialog/adaptive_dialog.dart'; import 'package:flutter_gen/gen_l10n/l10n.dart'; import 'package:go_router/go_router.dart'; import 'package:matrix/matrix.dart'; -import 'package:new_keyboard_shortcuts/keyboard_shortcuts.dart'; import 'package:fluffychat/widgets/avatar.dart'; import 'package:fluffychat/widgets/matrix.dart'; @@ -166,36 +164,10 @@ class ClientChooserButton extends StatelessWidget { children: [ ...List.generate( clientCount, - (index) => KeyBoardShortcuts( - keysToPress: _buildKeyboardShortcut(index + 1), - helpLabel: L10n.of(context).switchToAccount(index + 1), - onKeysPressed: () => _handleKeyboardShortcut( - matrix, - index, - context, - ), - child: const SizedBox.shrink(), - ), - ), - KeyBoardShortcuts( - keysToPress: { - LogicalKeyboardKey.controlLeft, - LogicalKeyboardKey.tab, - }, - helpLabel: L10n.of(context).nextAccount, - onKeysPressed: () => _nextAccount(matrix, context), - child: const SizedBox.shrink(), - ), - KeyBoardShortcuts( - keysToPress: { - LogicalKeyboardKey.controlLeft, - LogicalKeyboardKey.shiftLeft, - LogicalKeyboardKey.tab, - }, - helpLabel: L10n.of(context).previousAccount, - onKeysPressed: () => _previousAccount(matrix, context), - child: const SizedBox.shrink(), + (index) => const SizedBox.shrink(), ), + const SizedBox.shrink(), + const SizedBox.shrink(), PopupMenuButton( onSelected: (o) => _clientSelected(o, context), itemBuilder: _bundleMenuItems, @@ -215,17 +187,6 @@ class ClientChooserButton extends StatelessWidget { ); } - Set? _buildKeyboardShortcut(int index) { - if (index > 0 && index < 10) { - return { - LogicalKeyboardKey.altLeft, - LogicalKeyboardKey(0x00000000030 + index), - }; - } else { - return null; - } - } - void _clientSelected( Object object, BuildContext context, @@ -265,75 +226,6 @@ class ClientChooserButton extends StatelessWidget { } } } - - void _handleKeyboardShortcut( - MatrixState matrix, - int index, - BuildContext context, - ) { - final bundles = matrix.accountBundles.keys.toList() - ..sort( - (a, b) => a!.isValidMatrixId == b!.isValidMatrixId - ? 0 - : a.isValidMatrixId && !b.isValidMatrixId - ? -1 - : 1, - ); - // beginning from end if negative - if (index < 0) { - var clientCount = 0; - matrix.accountBundles - .forEach((key, value) => clientCount += value.length); - _handleKeyboardShortcut(matrix, clientCount, context); - } - for (final bundleName in bundles) { - final bundle = matrix.accountBundles[bundleName]; - if (bundle != null) { - if (index < bundle.length) { - return _clientSelected(bundle[index]!, context); - } else { - index -= bundle.length; - } - } - } - // if index too high, restarting from 0 - _handleKeyboardShortcut(matrix, 0, context); - } - - int? _shortcutIndexOfClient(MatrixState matrix, Client client) { - var index = 0; - - final bundles = matrix.accountBundles.keys.toList() - ..sort( - (a, b) => a!.isValidMatrixId == b!.isValidMatrixId - ? 0 - : a.isValidMatrixId && !b.isValidMatrixId - ? -1 - : 1, - ); - for (final bundleName in bundles) { - final bundle = matrix.accountBundles[bundleName]; - if (bundle == null) return null; - if (bundle.contains(client)) { - return index + bundle.indexOf(client); - } else { - index += bundle.length; - } - } - return null; - } - - void _nextAccount(MatrixState matrix, BuildContext context) { - final client = matrix.client; - final lastIndex = _shortcutIndexOfClient(matrix, client); - _handleKeyboardShortcut(matrix, lastIndex! + 1, context); - } - - void _previousAccount(MatrixState matrix, BuildContext context) { - final client = matrix.client; - final lastIndex = _shortcutIndexOfClient(matrix, client); - _handleKeyboardShortcut(matrix, lastIndex! - 1, context); - } } enum SettingsAction { diff --git a/lib/widgets/chat_settings_popup_menu.dart b/lib/widgets/chat_settings_popup_menu.dart index 7fc251a109..398d606dd3 100644 --- a/lib/widgets/chat_settings_popup_menu.dart +++ b/lib/widgets/chat_settings_popup_menu.dart @@ -1,13 +1,11 @@ import 'dart:async'; import 'package:flutter/material.dart'; -import 'package:flutter/services.dart'; import 'package:adaptive_dialog/adaptive_dialog.dart'; import 'package:flutter_gen/gen_l10n/l10n.dart'; import 'package:go_router/go_router.dart'; import 'package:matrix/matrix.dart'; -import 'package:new_keyboard_shortcuts/keyboard_shortcuts.dart'; import 'package:fluffychat/widgets/future_loading_dialog.dart'; import 'matrix.dart'; @@ -52,15 +50,7 @@ class ChatSettingsPopupMenuState extends State { return Stack( alignment: Alignment.center, children: [ - KeyBoardShortcuts( - keysToPress: { - LogicalKeyboardKey.controlLeft, - LogicalKeyboardKey.keyI, - }, - helpLabel: L10n.of(context).chatDetails, - onKeysPressed: _showChatDetails, - child: const SizedBox.shrink(), - ), + const SizedBox.shrink(), PopupMenuButton( onSelected: (choice) async { switch (choice) { diff --git a/macos/Runner.xcodeproj/project.pbxproj b/macos/Runner.xcodeproj/project.pbxproj index 304fc1636c..41d360c6f2 100644 --- a/macos/Runner.xcodeproj/project.pbxproj +++ b/macos/Runner.xcodeproj/project.pbxproj @@ -210,7 +210,7 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0920; - LastUpgradeCheck = 1430; + LastUpgradeCheck = 1510; ORGANIZATIONNAME = ""; TargetAttributes = { 33CC10EC2044A3C60003C045 = { diff --git a/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme b/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme index 4e6cd6256e..7275d672c7 100644 --- a/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme +++ b/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme @@ -1,6 +1,6 @@ Bool { return true diff --git a/pubspec.lock b/pubspec.lock index 09bc64138d..0eae4df538 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -1290,14 +1290,6 @@ packages: url: "https://pub.dev" source: hosted version: "1.0.0" - new_keyboard_shortcuts: - dependency: "direct main" - description: - name: new_keyboard_shortcuts - sha256: af1389c7450c29746addfb6da5fcc5e85a83340db02a987d2012ed26c73147e3 - url: "https://pub.dev" - source: hosted - version: "0.1.4" node_preamble: dependency: transitive description: @@ -2319,14 +2311,6 @@ packages: url: "https://pub.dev" source: hosted version: "2.3.2" - visibility_detector: - dependency: transitive - description: - name: visibility_detector - sha256: ec932527913f32f65aa01d3a393504240b9e9021ecc77123f017755605e48832 - url: "https://pub.dev" - source: hosted - version: "0.2.2" vm_service: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 77c0bab6e9..94d2c11401 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -67,7 +67,6 @@ dependencies: matrix: ^0.34.0 mime: ^1.0.6 native_imaging: ^0.1.1 - new_keyboard_shortcuts: ^0.1.4 opus_caf_converter_dart: ^1.0.1 package_info_plus: ^8.0.2 pasteboard: ^0.2.0