mirror of
https://github.com/Yubico/yubioath-flutter.git
synced 2024-11-25 23:14:18 +03:00
Fix focus issue for Ctrl+F, add Ctrl+W to close.
This commit is contained in:
parent
befaa85248
commit
9de315f472
@ -30,9 +30,8 @@ class YubicoAuthenticatorApp extends ConsumerWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
return LogWarningOverlay(
|
||||
child: Shortcuts(
|
||||
shortcuts: globalShortcuts,
|
||||
return registerGlobalShortcuts(
|
||||
LogWarningOverlay(
|
||||
child: MaterialApp(
|
||||
title: 'Yubico Authenticator',
|
||||
theme: AppTheme.lightTheme,
|
||||
|
@ -18,11 +18,18 @@ import 'dart:io';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:window_manager/window_manager.dart';
|
||||
|
||||
import '../oath/keys.dart';
|
||||
|
||||
class CopyIntent extends Intent {
|
||||
const CopyIntent();
|
||||
}
|
||||
|
||||
class CloseIntent extends Intent {
|
||||
const CloseIntent();
|
||||
}
|
||||
|
||||
class SearchIntent extends Intent {
|
||||
const SearchIntent();
|
||||
}
|
||||
@ -30,7 +37,35 @@ class SearchIntent extends Intent {
|
||||
final ctrlOrCmd =
|
||||
Platform.isMacOS ? LogicalKeyboardKey.meta : LogicalKeyboardKey.control;
|
||||
|
||||
final globalShortcuts = {
|
||||
final _globalShortcuts = {
|
||||
LogicalKeySet(ctrlOrCmd, LogicalKeyboardKey.keyC): const CopyIntent(),
|
||||
if (Platform.isMacOS)
|
||||
LogicalKeySet(ctrlOrCmd, LogicalKeyboardKey.keyQ): const CloseIntent(),
|
||||
LogicalKeySet(ctrlOrCmd, LogicalKeyboardKey.keyW): const CloseIntent(),
|
||||
LogicalKeySet(ctrlOrCmd, LogicalKeyboardKey.keyF): const SearchIntent(),
|
||||
};
|
||||
|
||||
final _globalActions = <Type, Action<Intent>>{
|
||||
CloseIntent: CallbackAction(onInvoke: (_) {
|
||||
windowManager.close();
|
||||
return null;
|
||||
}),
|
||||
SearchIntent: CallbackAction(onInvoke: (intent) {
|
||||
// If the OATH view doesn't have focus, but is shown, find and select the search bar.
|
||||
final searchContext = searchAccountsField.currentContext;
|
||||
if (searchContext != null) {
|
||||
if (!Navigator.of(searchContext).canPop()) {
|
||||
return Actions.maybeInvoke(searchContext, intent);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}),
|
||||
};
|
||||
|
||||
Widget registerGlobalShortcuts(Widget child) => Actions(
|
||||
actions: _globalActions,
|
||||
child: Shortcuts(
|
||||
shortcuts: _globalShortcuts,
|
||||
child: child,
|
||||
),
|
||||
);
|
||||
|
@ -24,7 +24,9 @@ const resetAction = Key('$_prefix.reset');
|
||||
|
||||
const noAccountsView = Key('$_prefix.no_accounts');
|
||||
|
||||
const searchAccountsField = Key('$_prefix.search_accounts');
|
||||
// This is global so we can access it from the global Ctrl+F shortcut.
|
||||
final searchAccountsField = GlobalKey();
|
||||
|
||||
const passwordField = Key('$_prefix.password');
|
||||
const currentPasswordField = Key('$_prefix.current_password');
|
||||
const newPasswordField = Key('$_prefix.new_password');
|
||||
|
Loading…
Reference in New Issue
Block a user