Skip to content

An open-source cross-platform alternative to AirDrop

fix(macos): handle Command+W through the Close menu (#3599)

Shlomocfd699125f2a
diff --git a/app/lib/widget/watcher/shortcut_watcher.dart b/app/lib/widget/watcher/shortcut_watcher.dart
index fdef6324..5eb64e72 100644
--- a/app/lib/widget/watcher/shortcut_watcher.dart
+++ b/app/lib/widget/watcher/shortcut_watcher.dart
@@ -6,7 +6,6 @@ import 'package:localsend_app/pages/home_page.dart';
import 'package:localsend_app/pages/home_page_controller.dart';
import 'package:localsend_app/util/native/file_picker.dart';
import 'package:localsend_app/util/native/platform_check.dart';
-import 'package:localsend_app/widget/watcher/window_watcher.dart';
import 'package:refena_flutter/refena_flutter.dart';
import 'package:routerino/routerino.dart';
@@ -27,8 +26,6 @@ class ShortcutWatcher extends StatelessWidget {
// Add Control+Q binding for Linux
// https://github.com/localsend/localsend/issues/194
if (checkPlatform([TargetPlatform.linux])) SingleActivator(LogicalKeyboardKey.keyQ, control: true): _ExitAppIntent(),
- // Add Command+W to close the window for macOS
- if (checkPlatform([TargetPlatform.macOS])) SingleActivator(LogicalKeyboardKey.keyW, meta: true): _CloseWindowIntent(),
// Add Control+, to open settings for macOS
if (checkPlatform([TargetPlatform.macOS])) SingleActivator(LogicalKeyboardKey.comma, meta: true): _OpenSettingsIntent(),
@@ -51,16 +48,6 @@ class ShortcutWatcher extends StatelessWidget {
return null;
},
),
- _CloseWindowIntent: CallbackAction<_CloseWindowIntent>(
- onInvoke: (_) async {
- if (_isFakeMetaKey()) {
- return null;
- }
-
- await WindowWatcher.closeWindow(context);
- return null;
- },
- ),
_OpenSettingsIntent: CallbackAction(
onInvoke: (_) async {
context.redux(homePageControllerProvider).dispatch(ChangeTabAction(HomeTab.settings));
@@ -80,31 +67,4 @@ class _PopPageIntent extends Intent {}
class _PasteIntent extends Intent {}
-class _CloseWindowIntent extends Intent {}
-
class _OpenSettingsIntent 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;
-}
diff --git a/app/macos/Runner/Base.lproj/MainMenu.xib b/app/macos/Runner/Base.lproj/MainMenu.xib
index 403eaa1a..a8bd8065 100644
--- a/app/macos/Runner/Base.lproj/MainMenu.xib
+++ b/app/macos/Runner/Base.lproj/MainMenu.xib
@@ -302,6 +302,11 @@
<modifierMask key="keyEquivalentModifierMask"/>
<menu key="submenu" title="Window" systemMenu="window" id="Td7-aD-5lo">
<items>
+ <menuItem title="Close" keyEquivalent="w" id="Vn6-Ju-Zv1">
+ <connections>
+ <action selector="performClose:" target="-1" id="H2e-sW-8BY"/>
+ </connections>
+ </menuItem>
<menuItem title="Minimize" keyEquivalent="m" id="OY7-WF-poV">
<connections>
<action selector="performMiniaturize:" target="-1" id="VwT-WD-YPe"/>