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.
This commit is contained in:
Krille 2024-11-11 16:03:52 +01:00
commit 39de990fae
No known key found for this signature in database
GPG key ID: E067ECD60F1A0652
9 changed files with 101 additions and 265 deletions

View file

@ -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(),
),
),
),

View file

@ -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<Object>(
onSelected: (o) => _clientSelected(o, context),
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(
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 {