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.
pull/1483/head
Krille 9 months ago
parent cb153ad032
commit 39de990fae
No known key found for this signature in database
GPG Key ID: E067ECD60F1A0652

@ -1,10 +1,8 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:animations/animations.dart'; import 'package:animations/animations.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart'; import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:matrix/matrix.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/app_config.dart';
import 'package:fluffychat/utils/platform_infos.dart'; import 'package:fluffychat/utils/platform_infos.dart';
@ -96,130 +94,113 @@ class ChatInputRow extends StatelessWidget {
] ]
: <Widget>[ : <Widget>[
const SizedBox(width: 4), const SizedBox(width: 4),
KeyBoardShortcuts( AnimatedContainer(
keysToPress: { duration: FluffyThemes.animationDuration,
LogicalKeyboardKey.altLeft, curve: FluffyThemes.animationCurve,
LogicalKeyboardKey.keyA, height: height,
}, width: controller.sendController.text.isEmpty ? height : 0,
onKeysPressed: () => alignment: Alignment.center,
controller.onAddPopupMenuButtonSelected('file'), clipBehavior: Clip.hardEdge,
helpLabel: L10n.of(context).sendFile, decoration: const BoxDecoration(),
child: AnimatedContainer( child: PopupMenuButton<String>(
duration: FluffyThemes.animationDuration, icon: const Icon(Icons.add_outlined),
curve: FluffyThemes.animationCurve, onSelected: controller.onAddPopupMenuButtonSelected,
height: height, itemBuilder: (BuildContext context) =>
width: controller.sendController.text.isEmpty ? height : 0, <PopupMenuEntry<String>>[
alignment: Alignment.center, PopupMenuItem<String>(
clipBehavior: Clip.hardEdge, value: 'file',
decoration: const BoxDecoration(), child: ListTile(
child: PopupMenuButton<String>( leading: const CircleAvatar(
icon: const Icon(Icons.add_outlined), backgroundColor: Colors.green,
onSelected: controller.onAddPopupMenuButtonSelected, foregroundColor: Colors.white,
itemBuilder: (BuildContext context) => child: Icon(Icons.attachment_outlined),
<PopupMenuEntry<String>>[ ),
title: Text(L10n.of(context).sendFile),
contentPadding: const EdgeInsets.all(0),
),
),
PopupMenuItem<String>(
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<String>( PopupMenuItem<String>(
value: 'file', value: 'camera',
child: ListTile( child: ListTile(
leading: const CircleAvatar( leading: const CircleAvatar(
backgroundColor: Colors.green, backgroundColor: Colors.purple,
foregroundColor: Colors.white, 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), contentPadding: const EdgeInsets.all(0),
), ),
), ),
if (PlatformInfos.isMobile)
PopupMenuItem<String>( PopupMenuItem<String>(
value: 'image', value: 'camera-video',
child: ListTile( child: ListTile(
leading: const CircleAvatar( leading: const CircleAvatar(
backgroundColor: Colors.blue, backgroundColor: Colors.red,
foregroundColor: Colors.white, 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), contentPadding: const EdgeInsets.all(0),
), ),
), ),
if (PlatformInfos.isMobile) if (PlatformInfos.isMobile)
PopupMenuItem<String>( PopupMenuItem<String>(
value: 'camera', value: 'location',
child: ListTile( child: ListTile(
leading: const CircleAvatar( leading: const CircleAvatar(
backgroundColor: Colors.purple, backgroundColor: Colors.brown,
foregroundColor: Colors.white, foregroundColor: Colors.white,
child: Icon(Icons.camera_alt_outlined), child: Icon(Icons.gps_fixed_outlined),
),
title: Text(L10n.of(context).openCamera),
contentPadding: const EdgeInsets.all(0),
),
),
if (PlatformInfos.isMobile)
PopupMenuItem<String>(
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<String>(
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),
), ),
title: Text(L10n.of(context).shareLocation),
contentPadding: const EdgeInsets.all(0),
), ),
], ),
), ],
), ),
), ),
Container( Container(
height: height, height: height,
width: height, width: height,
alignment: Alignment.center, alignment: Alignment.center,
child: KeyBoardShortcuts( child: IconButton(
keysToPress: { tooltip: L10n.of(context).emojis,
LogicalKeyboardKey.altLeft, icon: PageTransitionSwitcher(
LogicalKeyboardKey.keyE, transitionBuilder: (
}, Widget child,
onKeysPressed: controller.emojiPickerAction, Animation<double> primaryAnimation,
helpLabel: L10n.of(context).emojis, Animation<double> secondaryAnimation,
child: IconButton( ) {
tooltip: L10n.of(context).emojis, return SharedAxisTransition(
icon: PageTransitionSwitcher( animation: primaryAnimation,
transitionBuilder: ( secondaryAnimation: secondaryAnimation,
Widget child, transitionType: SharedAxisTransitionType.scaled,
Animation<double> primaryAnimation, fillColor: Colors.transparent,
Animation<double> secondaryAnimation, child: child,
) { );
return SharedAxisTransition( },
animation: primaryAnimation, child: Icon(
secondaryAnimation: secondaryAnimation, controller.showEmojiPicker
transitionType: SharedAxisTransitionType.scaled, ? Icons.keyboard
fillColor: Colors.transparent, : Icons.add_reaction_outlined,
child: child, key: ValueKey(controller.showEmojiPicker),
);
},
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 && if (Matrix.of(context).isMultiAccount &&

@ -1,10 +1,8 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart'; import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:go_router/go_router.dart'; import 'package:go_router/go_router.dart';
import 'package:matrix/matrix.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/app_config.dart';
import 'package:fluffychat/config/themes.dart'; import 'package:fluffychat/config/themes.dart';
@ -138,27 +136,19 @@ class ChatListView extends StatelessWidget {
behavior: HitTestBehavior.translucent, behavior: HitTestBehavior.translucent,
child: Scaffold( child: Scaffold(
body: ChatListViewBody(controller), body: ChatListViewBody(controller),
floatingActionButton: KeyBoardShortcuts( floatingActionButton: selectMode == SelectMode.normal &&
keysToPress: { !controller.isSearchMode &&
LogicalKeyboardKey.controlLeft, controller.activeSpaceId == null
LogicalKeyboardKey.keyN, ? FloatingActionButton.extended(
}, onPressed: () =>
onKeysPressed: () => context.go('/rooms/newprivatechat'), context.go('/rooms/newprivatechat'),
helpLabel: L10n.of(context).newChat, icon: const Icon(Icons.add_outlined),
child: selectMode == SelectMode.normal && label: Text(
!controller.isSearchMode && L10n.of(context).chat,
controller.activeSpaceId == null overflow: TextOverflow.fade,
? FloatingActionButton.extended( ),
onPressed: () => )
context.go('/rooms/newprivatechat'), : const SizedBox.shrink(),
icon: const Icon(Icons.add_outlined),
label: Text(
L10n.of(context).chat,
overflow: TextOverflow.fade,
),
)
: const SizedBox.shrink(),
),
), ),
), ),
), ),

@ -1,11 +1,9 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:adaptive_dialog/adaptive_dialog.dart'; import 'package:adaptive_dialog/adaptive_dialog.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart'; import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:go_router/go_router.dart'; import 'package:go_router/go_router.dart';
import 'package:matrix/matrix.dart'; import 'package:matrix/matrix.dart';
import 'package:new_keyboard_shortcuts/keyboard_shortcuts.dart';
import 'package:fluffychat/widgets/avatar.dart'; import 'package:fluffychat/widgets/avatar.dart';
import 'package:fluffychat/widgets/matrix.dart'; import 'package:fluffychat/widgets/matrix.dart';
@ -166,36 +164,10 @@ class ClientChooserButton extends StatelessWidget {
children: [ children: [
...List.generate( ...List.generate(
clientCount, clientCount,
(index) => KeyBoardShortcuts( (index) => const SizedBox.shrink(),
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(),
), ),
const SizedBox.shrink(),
const SizedBox.shrink(),
PopupMenuButton<Object>( PopupMenuButton<Object>(
onSelected: (o) => _clientSelected(o, context), onSelected: (o) => _clientSelected(o, context),
itemBuilder: _bundleMenuItems, itemBuilder: _bundleMenuItems,
@ -215,17 +187,6 @@ class ClientChooserButton extends StatelessWidget {
); );
} }
Set<LogicalKeyboardKey>? _buildKeyboardShortcut(int index) {
if (index > 0 && index < 10) {
return {
LogicalKeyboardKey.altLeft,
LogicalKeyboardKey(0x00000000030 + index),
};
} else {
return null;
}
}
void _clientSelected( void _clientSelected(
Object object, Object object,
BuildContext context, 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 { enum SettingsAction {

@ -1,13 +1,11 @@
import 'dart:async'; import 'dart:async';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:adaptive_dialog/adaptive_dialog.dart'; import 'package:adaptive_dialog/adaptive_dialog.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart'; import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:go_router/go_router.dart'; import 'package:go_router/go_router.dart';
import 'package:matrix/matrix.dart'; import 'package:matrix/matrix.dart';
import 'package:new_keyboard_shortcuts/keyboard_shortcuts.dart';
import 'package:fluffychat/widgets/future_loading_dialog.dart'; import 'package:fluffychat/widgets/future_loading_dialog.dart';
import 'matrix.dart'; import 'matrix.dart';
@ -52,15 +50,7 @@ class ChatSettingsPopupMenuState extends State<ChatSettingsPopupMenu> {
return Stack( return Stack(
alignment: Alignment.center, alignment: Alignment.center,
children: [ children: [
KeyBoardShortcuts( const SizedBox.shrink(),
keysToPress: {
LogicalKeyboardKey.controlLeft,
LogicalKeyboardKey.keyI,
},
helpLabel: L10n.of(context).chatDetails,
onKeysPressed: _showChatDetails,
child: const SizedBox.shrink(),
),
PopupMenuButton<ChatPopupMenuActions>( PopupMenuButton<ChatPopupMenuActions>(
onSelected: (choice) async { onSelected: (choice) async {
switch (choice) { switch (choice) {

@ -210,7 +210,7 @@
isa = PBXProject; isa = PBXProject;
attributes = { attributes = {
LastSwiftUpdateCheck = 0920; LastSwiftUpdateCheck = 0920;
LastUpgradeCheck = 1430; LastUpgradeCheck = 1510;
ORGANIZATIONNAME = ""; ORGANIZATIONNAME = "";
TargetAttributes = { TargetAttributes = {
33CC10EC2044A3C60003C045 = { 33CC10EC2044A3C60003C045 = {

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<Scheme <Scheme
LastUpgradeVersion = "1430" LastUpgradeVersion = "1510"
version = "1.3"> version = "1.3">
<BuildAction <BuildAction
parallelizeBuildables = "YES" parallelizeBuildables = "YES"

@ -1,7 +1,7 @@
import Cocoa import Cocoa
import FlutterMacOS import FlutterMacOS
@NSApplicationMain @main
class AppDelegate: FlutterAppDelegate { class AppDelegate: FlutterAppDelegate {
override func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool { override func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool {
return true return true

@ -1290,14 +1290,6 @@ packages:
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "1.0.0" 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: node_preamble:
dependency: transitive dependency: transitive
description: description:
@ -2319,14 +2311,6 @@ packages:
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "2.3.2" 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: vm_service:
dependency: transitive dependency: transitive
description: description:

@ -67,7 +67,6 @@ dependencies:
matrix: ^0.34.0 matrix: ^0.34.0
mime: ^1.0.6 mime: ^1.0.6
native_imaging: ^0.1.1 native_imaging: ^0.1.1
new_keyboard_shortcuts: ^0.1.4
opus_caf_converter_dart: ^1.0.1 opus_caf_converter_dart: ^1.0.1
package_info_plus: ^8.0.2 package_info_plus: ^8.0.2
pasteboard: ^0.2.0 pasteboard: ^0.2.0

Loading…
Cancel
Save