-
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add
Ctrl+Q
shortcut to quit the app
Follows Linux conventions.
- Loading branch information
Showing
14 changed files
with
133 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export 'hotkey_service.dart'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export 'global/global.dart'; | ||
export 'in_app/in_app.dart'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import 'dart:io'; | ||
|
||
import 'package:flutter/material.dart'; | ||
import 'package:flutter/services.dart'; | ||
|
||
import '../../logs/logging_manager.dart'; | ||
import 'shortcuts_manager.dart'; | ||
|
||
/// Shortcuts that are available everywhere in the app. | ||
/// | ||
/// This widget is to be wrapped around the widget intended as a route, | ||
/// or the entire MaterialApp. | ||
class AppShortcuts extends StatelessWidget { | ||
final Widget child; | ||
|
||
AppShortcuts({ | ||
super.key, | ||
required this.child, | ||
}); | ||
|
||
final _shortcuts = <ShortcutActivator, Intent>{ | ||
const SingleActivator( | ||
LogicalKeyboardKey.keyQ, | ||
control: true, | ||
): const QuitIntent(), | ||
}; | ||
|
||
final _actions = <Type, Action<Intent>>{ | ||
QuitIntent: QuitAction(), | ||
}; | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Shortcuts.manager( | ||
manager: LoggingShortcutManager(shortcuts: _shortcuts), | ||
child: Actions( | ||
dispatcher: LoggingActionDispatcher(), | ||
actions: _actions, | ||
child: child, | ||
), | ||
); | ||
} | ||
} | ||
|
||
/// An intent that is bound to QuitAction in order to quit this application. | ||
class QuitIntent extends Intent { | ||
const QuitIntent(); | ||
} | ||
|
||
/// An action that is bound to QuitIntent in order to quit this application. | ||
class QuitAction extends Action<QuitIntent> { | ||
@override | ||
Object? invoke(QuitIntent intent) { | ||
log.i('Quit requested, exiting.'); | ||
exit(0); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export 'app_shortcuts.dart'; | ||
export 'shortcuts_manager.dart'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import 'package:flutter/material.dart'; | ||
|
||
import '../../logs/logging_manager.dart'; | ||
|
||
/// A ShortcutManager that logs all keys that it handles. | ||
class LoggingShortcutManager extends ShortcutManager { | ||
LoggingShortcutManager({required super.shortcuts}); | ||
|
||
@override | ||
KeyEventResult handleKeypress(BuildContext context, RawKeyEvent event) { | ||
final KeyEventResult result = super.handleKeypress(context, event); | ||
|
||
if (result == KeyEventResult.handled) { | ||
log.i('''Handled shortcut | ||
Shortcut: $event | ||
Context: $context | ||
'''); | ||
} | ||
|
||
return result; | ||
} | ||
} | ||
|
||
/// An ActionDispatcher that logs all the actions that it invokes. | ||
class LoggingActionDispatcher extends ActionDispatcher { | ||
@override | ||
Object? invokeAction( | ||
covariant Action<Intent> action, | ||
covariant Intent intent, [ | ||
BuildContext? context, | ||
]) { | ||
log.i(''' | ||
Action invoked: | ||
Action: $action($intent) | ||
From: $context | ||
'''); | ||
|
||
super.invokeAction(action, intent, context); | ||
|
||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters