Skip to content

An open-source cross-platform alternative to AirDrop

fix: window disappears on command key (#2165)

Tien Do Nam311ff64381b9
diff --git a/app/assets/CHANGELOG.md b/app/assets/CHANGELOG.md
index ef595e1b..15f9cbbe 100644
--- a/app/assets/CHANGELOG.md
+++ b/app/assets/CHANGELOG.md
@@ -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)
diff --git a/app/lib/widget/watcher/shortcut_watcher.dart b/app/lib/widget/watcher/shortcut_watcher.dart
index 2c5da547..498a13ab 100644
--- a/app/lib/widget/watcher/shortcut_watcher.dart
+++ b/app/lib/widget/watcher/shortcut_watcher.dart
@@ -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;
+}