fix: window disappears on command key (#2165)

This commit is contained in:
Tien Do Nam
2024-12-27 02:51:09 +01:00
committed by GitHub
parent 98253fe44a
commit 311ff64381
2 changed files with 30 additions and 0 deletions
+1
View File
@@ -3,6 +3,7 @@
- feat(windows): when pasting an image, automatically convert it to PNG (@BrianMwit)
- feat(android): add option to gallery when automatically saved (@Tienisto)
- fix: black screen when tapping on "Back" twice in "Share via link" (@Tienisto)
- fix(macos): window disappears on command key when minimize to tray is enabled (@Tienisto)
## 1.16.2 (2024-11-06)
@@ -47,6 +47,10 @@ class ShortcutWatcher extends StatelessWidget {
}),
_CloseWindowIntent: CallbackAction<_CloseWindowIntent>(
onInvoke: (_) async {
if (_isFakeMetaKey()) {
return null;
}
await WindowWatcher.closeWindow(context);
return null;
},
@@ -65,3 +69,28 @@ class _PopPageIntent extends Intent {}
class _PasteIntent extends Intent {}
class _CloseWindowIntent extends Intent {}
bool _ignoreMetaLast = false;
bool _isFakeMetaKey() {
// https://github.com/localsend/localsend/issues/2037
// We can detect the "fake" meta key by checking if the last key was a meta key
// because the real meta key should be the first key pressed.
if (_ignoreMetaLast) {
final lastKey = HardwareKeyboard.instance.logicalKeysPressed.lastOrNull;
if (lastKey?.isMeta ?? false) {
return true;
}
} else {
final firstKey = HardwareKeyboard.instance.logicalKeysPressed.firstOrNull;
if (firstKey?.isMeta ?? false) {
_ignoreMetaLast = true;
}
}
return false;
}
extension on LogicalKeyboardKey {
bool get isMeta => this == LogicalKeyboardKey.meta || this == LogicalKeyboardKey.metaLeft || this == LogicalKeyboardKey.metaRight;
}