From 7f241ea02d1fcd4b257bc028d8f02403cdd03e1e Mon Sep 17 00:00:00 2001 From: Sharker <1548742234@qq.com> Date: Tue, 26 Dec 2023 21:43:08 +0800 Subject: [PATCH 1/9] feat: add double click modifier as shortcut --- Podfile | 4 +- Podfile.lock | 17 +++- Pods/Local Podspecs/MASShortcut.podspec.json | 32 +++++++ .../MASShortcut/Framework/Model/MASShortcut.h | 3 + .../MASShortcut/Framework/Model/MASShortcut.m | 24 ++++- .../Framework/Monitoring/MASShortcutMonitor.m | 89 ++++++++++++++++++- .../Framework/UI/MASShortcutView.m | 15 +++- Pods/Manifest.lock | 17 +++- 8 files changed, 184 insertions(+), 17 deletions(-) create mode 100644 Pods/Local Podspecs/MASShortcut.podspec.json diff --git a/Podfile b/Podfile index f91b37ba0..d2d99968b 100644 --- a/Podfile +++ b/Podfile @@ -10,7 +10,7 @@ target 'Easydict' do pod 'MJExtension', '~> 3.2.1' pod 'Masonry', '~> 1.1.0' pod 'ReactiveObjC', '~> 3.1.1' - pod 'MASShortcut', '~> 2.4.0' + pod 'MASShortcut', :git => 'git@github.com:AkaShark/MASShortcut.git', :branch => 'double_click_modifier' pod 'MASPreferences', '~> 1.4.1' pod 'CocoaLumberjack/Swift', '~> 3.6.0' pod 'SSZipArchive', '~> 2.2.2' @@ -34,7 +34,7 @@ target 'EasydictTests' do pod 'MJExtension', '~> 3.2.1' pod 'Masonry', '~> 1.1.0' pod 'ReactiveObjC', '~> 3.1.1' - pod 'MASShortcut', '~> 2.4.0' + pod 'MASShortcut', :git => 'git@github.com:AkaShark/MASShortcut.git', :branch => 'double_click_modifier' pod 'MASPreferences', '~> 1.4.1' pod 'CocoaLumberjack/Swift', '~> 3.6.0' pod 'SSZipArchive', '~> 2.2.2' diff --git a/Podfile.lock b/Podfile.lock index c5d605edf..55028505a 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -117,7 +117,7 @@ DEPENDENCIES: - KVOController (~> 1.2.0) - Masonry (~> 1.1.0) - MASPreferences (~> 1.4.1) - - MASShortcut (~> 2.4.0) + - "MASShortcut (from `git@github.com:AkaShark/MASShortcut.git`, branch `double_click_modifier`)" - MJExtension (~> 3.2.1) - ReactiveObjC (~> 3.1.1) - Sparkle (~> 2.5.1) @@ -139,7 +139,6 @@ SPEC REPOS: - KVOController - Masonry - MASPreferences - - MASShortcut - MJExtension - nanopb - PromisesObjC @@ -148,6 +147,16 @@ SPEC REPOS: - SSZipArchive - SwiftFormat +EXTERNAL SOURCES: + MASShortcut: + :branch: double_click_modifier + :git: "git@github.com:AkaShark/MASShortcut.git" + +CHECKOUT OPTIONS: + MASShortcut: + :commit: 694922e088bc91eb70eff42ddaf7602c5b87f1f1 + :git: "git@github.com:AkaShark/MASShortcut.git" + SPEC CHECKSUMS: AFNetworking: cb604b1c2bded0871f5f61f5d53653739e841d6b AppCenter: 85c92db0759d2792a65eb61d6842d2e86611a49a @@ -171,6 +180,6 @@ SPEC CHECKSUMS: SSZipArchive: 62d4947b08730e4cda640473b0066d209ff033c9 SwiftFormat: 2ca3d0b75754193f0f3ba532291f25ae08dd1e42 -PODFILE CHECKSUM: a35287f08d36ebe90dd9f3362e15bf7aaeeaf0f5 +PODFILE CHECKSUM: 597cd2d7aa9ead11dfe63d03ada0bdffc6ee7ad8 -COCOAPODS: 1.14.2 +COCOAPODS: 1.13.0 diff --git a/Pods/Local Podspecs/MASShortcut.podspec.json b/Pods/Local Podspecs/MASShortcut.podspec.json new file mode 100644 index 000000000..f0f1aa602 --- /dev/null +++ b/Pods/Local Podspecs/MASShortcut.podspec.json @@ -0,0 +1,32 @@ +{ + "name": "MASShortcut", + "version": "2.4.0", + "summary": "Modern framework for managing global keyboard shortcuts compatible with Mac App Store", + "homepage": "https://github.com/shpakovski/MASShortcut", + "license": "BSD 2-clause", + "authors": { + "Vadim Shpakovski": "vadim@shpakovski.com", + "Tomáš Znamenáček": "tomas.znamenacek@gmail.com" + }, + "platforms": { + "osx": "10.10" + }, + "source": { + "git": "https://github.com/shpakovski/MASShortcut.git", + "tag": "2.4.0" + }, + "source_files": "Framework/**/*.{h,m}", + "exclude_files": "Framework/**/*Tests.m", + "osx": { + "frameworks": [ + "Carbon", + "AppKit" + ], + "resource_bundles": { + "MASShortcut": [ + "Resources/*.lproj" + ] + } + }, + "requires_arc": true +} diff --git a/Pods/MASShortcut/Framework/Model/MASShortcut.h b/Pods/MASShortcut/Framework/Model/MASShortcut.h index 1b7d76bed..e750d56dd 100644 --- a/Pods/MASShortcut/Framework/Model/MASShortcut.h +++ b/Pods/MASShortcut/Framework/Model/MASShortcut.h @@ -71,6 +71,9 @@ - (instancetype)initWithKeyCode:(NSInteger)code modifierFlags:(NSEventModifierFlags)flags; + (instancetype)shortcutWithKeyCode:(NSInteger)code modifierFlags:(NSEventModifierFlags)flags; +- (nonnull instancetype)initDoubleModifierKeyWithCode:(NSInteger)code modifierFlags:(NSEventModifierFlags)flags; ++ (nonnull instancetype)shortcutDoubleModifierKeyWithCode:(NSInteger)code modifierFlags:(NSEventModifierFlags)flags; + /** Creates a new shortcut from an `NSEvent` object. diff --git a/Pods/MASShortcut/Framework/Model/MASShortcut.m b/Pods/MASShortcut/Framework/Model/MASShortcut.m index 1a029a90b..536eda2a7 100644 --- a/Pods/MASShortcut/Framework/Model/MASShortcut.m +++ b/Pods/MASShortcut/Framework/Model/MASShortcut.m @@ -3,7 +3,7 @@ static NSString *const MASShortcutKeyCode = @"KeyCode"; static NSString *const MASShortcutModifierFlags = @"ModifierFlags"; - +static NSUInteger MAShortcutDoubleModifierCode = 100000; @implementation MASShortcut #pragma mark Initialization @@ -23,6 +23,19 @@ + (instancetype)shortcutWithKeyCode:(NSInteger)code modifierFlags:(NSEventModifi return [[self alloc] initWithKeyCode:code modifierFlags:flags]; } +- (nonnull instancetype)initDoubleModifierKeyWithCode:(NSInteger)code modifierFlags:(NSEventModifierFlags)flags { + if (self = [super init]) { + // hard code special key + _keyCode = 100000; + _modifierFlags = MASPickCocoaModifiers(flags); + } + return self; +} + ++ (nonnull instancetype)shortcutDoubleModifierKeyWithCode:(NSInteger)code modifierFlags:(NSEventModifierFlags)flags { + return [[self alloc] initDoubleModifierKeyWithCode:code modifierFlags:flags]; +} + + (instancetype)shortcutWithEvent:(NSEvent *)event { return [[self alloc] initWithKeyCode:event.keyCode modifierFlags:event.modifierFlags]; @@ -32,6 +45,9 @@ + (instancetype)shortcutWithEvent:(NSEvent *)event - (UInt32)carbonKeyCode { + if (self.keyCode == MAShortcutDoubleModifierCode) { + return (UInt32)MAShortcutDoubleModifierCode; + } return (self.keyCode == NSNotFound ? 0 : (UInt32)self.keyCode); } @@ -80,6 +96,9 @@ - (NSString *)keyCodeStringForKeyEquivalent - (NSString *)keyCodeString { + if (self.keyCode == MAShortcutDoubleModifierCode) { + return self.modifierFlagsString; + } // Some key codes don't have an equivalent switch (self.keyCode) { case NSNotFound: return @""; @@ -202,8 +221,7 @@ - (BOOL) isEqual: (MASShortcut*) object && (object.modifierFlags == self.modifierFlags); } -- (NSUInteger) hash -{ +- (NSUInteger) hash { return self.keyCode + self.modifierFlags; } diff --git a/Pods/MASShortcut/Framework/Monitoring/MASShortcutMonitor.m b/Pods/MASShortcut/Framework/Monitoring/MASShortcutMonitor.m index fce802265..7aa7d8506 100644 --- a/Pods/MASShortcut/Framework/Monitoring/MASShortcutMonitor.m +++ b/Pods/MASShortcut/Framework/Monitoring/MASShortcutMonitor.m @@ -7,7 +7,7 @@ @interface MASShortcutMonitor () @end static OSStatus MASCarbonEventCallback(EventHandlerCallRef, EventRef, void*); - +static NSUInteger MAShortcutDoubleModifierCode = 100000; @implementation MASShortcutMonitor #pragma mark Initialization @@ -22,6 +22,8 @@ - (instancetype) init if (status != noErr) { return nil; } + + [self addModifierDoubleClickListener]; return self; } @@ -74,10 +76,91 @@ - (BOOL) isShortcutRegistered: (MASShortcut*) shortcut return !![_hotKeys objectForKey:shortcut]; } +- (void)addModifierDoubleClickListener { + __block NSUInteger preFlag = -1; + __weak typeof(self) weakSelf = self; + // event Monitor + [NSEvent addLocalMonitorForEventsMatchingMask:NSEventMaskFlagsChanged handler:^NSEvent * _Nullable(NSEvent * event) { + __strong typeof(weakSelf) strongSelf = weakSelf; + NSUInteger flags = [event modifierFlags] & NSEventModifierFlagDeviceIndependentFlagsMask; + if (flags == NSEventModifierFlagCommand || + flags == NSEventModifierFlagOption || + flags == NSEventModifierFlagShift || + flags == NSEventModifierFlagControl) { + if (preFlag != -1 && flags == preFlag) { + NSUInteger modifierFlag = MASPickCocoaModifiers(flags); +// NSString *eventKey = [strongSelf modifierFlagsString:modifierFlag]; + [strongSelf doubleClickHandleEventWithModifier:modifierFlag]; + preFlag = -1; + } else { + preFlag = flags; + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ + preFlag = -1; + }); + } + } + return event; + }]; + + [NSEvent addGlobalMonitorForEventsMatchingMask:NSEventMaskFlagsChanged handler:^(NSEvent *event) { + __strong typeof(weakSelf) strongSelf = weakSelf; + NSUInteger flags = [event modifierFlags] & NSEventModifierFlagDeviceIndependentFlagsMask; + if (flags == NSEventModifierFlagCommand || + flags == NSEventModifierFlagOption || + flags == NSEventModifierFlagShift || + flags == NSEventModifierFlagControl) { + if (preFlag != -1 && flags == preFlag) { + NSUInteger modifierFlag = MASPickCocoaModifiers(flags); +// NSString *eventKey = [strongSelf modifierFlagsString:modifierFlag]; + [strongSelf doubleClickHandleEventWithModifier:modifierFlag]; + preFlag = -1; + + } else { + preFlag = flags; + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ + preFlag = -1; + }); + } + } + }]; + +} + #pragma mark Event Handling +- (void)doubleClickHandleEventWithModifier:(NSUInteger)modifierFlag { + __block BOOL flag = NO; + [_hotKeys enumerateKeysAndObjectsUsingBlock:^(MASShortcut *shortcut, MASHotKey *hotKey, BOOL *stop) { + if (shortcut.modifierFlags == modifierFlag && shortcut.keyCode == MAShortcutDoubleModifierCode) { + flag = YES; + *stop = YES; + } else if (shortcut.modifierFlags == modifierFlag && shortcut.keyCode == MAShortcutDoubleModifierCode) { + flag = YES; + *stop = YES; + } else if (shortcut.modifierFlags == modifierFlag && shortcut.keyCode == MAShortcutDoubleModifierCode) { + flag = YES; + *stop = YES; + } else if (shortcut.modifierFlags == modifierFlag && shortcut.keyCode == MAShortcutDoubleModifierCode) { + flag = YES; + *stop = YES; + } + if (flag && [hotKey action]) { + dispatch_async(dispatch_get_main_queue(), [hotKey action]); + } + }]; +} -- (void) handleEvent: (EventRef) event -{ +- (NSString *)modifierFlagsString:(NSUInteger)modifierFlags { + unichar chars[4]; + NSUInteger count = 0; + // These are in the same order as the menu manager shows them + if (modifierFlags & NSEventModifierFlagControl) chars[count++] = kControlUnicode; + if (modifierFlags & NSEventModifierFlagOption) chars[count++] = kOptionUnicode; + if (modifierFlags & NSEventModifierFlagShift) chars[count++] = kShiftUnicode; + if (modifierFlags & NSEventModifierFlagCommand) chars[count++] = kCommandUnicode; + return (count ? [NSString stringWithCharacters:chars length:count] : @""); +} + +- (void) handleEvent: (EventRef) event { if (GetEventClass(event) != kEventClassKeyboard) { return; } diff --git a/Pods/MASShortcut/Framework/UI/MASShortcutView.m b/Pods/MASShortcut/Framework/UI/MASShortcutView.m index 3a44df42e..b91bc6df6 100644 --- a/Pods/MASShortcut/Framework/UI/MASShortcutView.m +++ b/Pods/MASShortcut/Framework/UI/MASShortcutView.m @@ -430,7 +430,7 @@ - (void)activateEventMonitoring:(BOOL)shouldActivate static BOOL isActive = NO; if (isActive == shouldActivate) return; isActive = shouldActivate; - + __block MASShortcut *preModifierFlags; static id eventMonitor = nil; if (shouldActivate) { __unsafe_unretained MASShortcutView *weakSelf = self; @@ -462,6 +462,16 @@ - (void)activateEventMonitoring:(BOOL)shouldActivate else if ((shortcut.modifierFlags == NSCommandKeyMask) && (shortcut.keyCode == kVK_ANSI_W || shortcut.keyCode == kVK_ANSI_Q)) { weakSelf.recording = NO; } + else if ((shortcut.modifierFlags == NSEventModifierFlagCommand || + shortcut.modifierFlags == NSEventModifierFlagOption || + shortcut.modifierFlags == NSEventModifierFlagControl || + shortcut.modifierFlags == NSEventModifierFlagShift) && + preModifierFlags.keyCode == shortcut.keyCode) { + weakSelf.shortcutPlaceholder = shortcut.modifierFlagsString; + MASShortcut *doubleModifierKey = [MASShortcut shortcutDoubleModifierKeyWithCode:shortcut.keyCode modifierFlags:shortcut.modifierFlags]; + weakSelf.shortcutValue = doubleModifierKey; + weakSelf.recording = NO; + } else { // Verify possible shortcut @@ -499,6 +509,9 @@ - (void)activateEventMonitoring:(BOOL)shouldActivate else { // User is playing with modifier keys weakSelf.shortcutPlaceholder = shortcut.modifierFlagsString; + if (shortcut.modifierFlags != 0) { + preModifierFlags = shortcut; + } } event = nil; } diff --git a/Pods/Manifest.lock b/Pods/Manifest.lock index c5d605edf..55028505a 100644 --- a/Pods/Manifest.lock +++ b/Pods/Manifest.lock @@ -117,7 +117,7 @@ DEPENDENCIES: - KVOController (~> 1.2.0) - Masonry (~> 1.1.0) - MASPreferences (~> 1.4.1) - - MASShortcut (~> 2.4.0) + - "MASShortcut (from `git@github.com:AkaShark/MASShortcut.git`, branch `double_click_modifier`)" - MJExtension (~> 3.2.1) - ReactiveObjC (~> 3.1.1) - Sparkle (~> 2.5.1) @@ -139,7 +139,6 @@ SPEC REPOS: - KVOController - Masonry - MASPreferences - - MASShortcut - MJExtension - nanopb - PromisesObjC @@ -148,6 +147,16 @@ SPEC REPOS: - SSZipArchive - SwiftFormat +EXTERNAL SOURCES: + MASShortcut: + :branch: double_click_modifier + :git: "git@github.com:AkaShark/MASShortcut.git" + +CHECKOUT OPTIONS: + MASShortcut: + :commit: 694922e088bc91eb70eff42ddaf7602c5b87f1f1 + :git: "git@github.com:AkaShark/MASShortcut.git" + SPEC CHECKSUMS: AFNetworking: cb604b1c2bded0871f5f61f5d53653739e841d6b AppCenter: 85c92db0759d2792a65eb61d6842d2e86611a49a @@ -171,6 +180,6 @@ SPEC CHECKSUMS: SSZipArchive: 62d4947b08730e4cda640473b0066d209ff033c9 SwiftFormat: 2ca3d0b75754193f0f3ba532291f25ae08dd1e42 -PODFILE CHECKSUM: a35287f08d36ebe90dd9f3362e15bf7aaeeaf0f5 +PODFILE CHECKSUM: 597cd2d7aa9ead11dfe63d03ada0bdffc6ee7ad8 -COCOAPODS: 1.14.2 +COCOAPODS: 1.13.0 From 8be5cabc943c9976520815fcffc962a66567040e Mon Sep 17 00:00:00 2001 From: Sharker <1548742234@qq.com> Date: Tue, 26 Dec 2023 22:45:00 +0800 Subject: [PATCH 2/9] feat: add gemfile --- Gemfile | 3 ++ Gemfile.lock | 107 +++++++++++++++++++++++++++++++++++++++++++++ Podfile.lock | 2 +- Pods/Manifest.lock | 2 +- 4 files changed, 112 insertions(+), 2 deletions(-) create mode 100644 Gemfile create mode 100644 Gemfile.lock diff --git a/Gemfile b/Gemfile new file mode 100644 index 000000000..8dd492b78 --- /dev/null +++ b/Gemfile @@ -0,0 +1,3 @@ +source 'https://rubygems.org' do + gem 'cocoapods', '1.14.2' +end diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 000000000..a018860a2 --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,107 @@ +GEM + remote: https://rubygems.org/ + specs: + CFPropertyList (3.0.6) + rexml + activesupport (7.1.2) + base64 + bigdecimal + concurrent-ruby (~> 1.0, >= 1.0.2) + connection_pool (>= 2.2.5) + drb + i18n (>= 1.6, < 2) + minitest (>= 5.1) + mutex_m + tzinfo (~> 2.0) + addressable (2.8.6) + public_suffix (>= 2.0.2, < 6.0) + algoliasearch (1.27.5) + httpclient (~> 2.8, >= 2.8.3) + json (>= 1.5.1) + atomos (0.1.3) + base64 (0.2.0) + bigdecimal (3.1.5) + claide (1.1.0) + cocoapods (1.14.2) + addressable (~> 2.8) + claide (>= 1.0.2, < 2.0) + cocoapods-core (= 1.14.2) + cocoapods-deintegrate (>= 1.0.3, < 2.0) + cocoapods-downloader (>= 2.0) + cocoapods-plugins (>= 1.0.0, < 2.0) + cocoapods-search (>= 1.0.0, < 2.0) + cocoapods-trunk (>= 1.6.0, < 2.0) + cocoapods-try (>= 1.1.0, < 2.0) + colored2 (~> 3.1) + escape (~> 0.0.4) + fourflusher (>= 2.3.0, < 3.0) + gh_inspector (~> 1.0) + molinillo (~> 0.8.0) + nap (~> 1.0) + ruby-macho (>= 2.3.0, < 3.0) + xcodeproj (>= 1.23.0, < 2.0) + cocoapods-core (1.14.2) + activesupport (>= 5.0, < 8) + addressable (~> 2.8) + algoliasearch (~> 1.0) + concurrent-ruby (~> 1.1) + fuzzy_match (~> 2.0.4) + nap (~> 1.0) + netrc (~> 0.11) + public_suffix (~> 4.0) + typhoeus (~> 1.0) + cocoapods-deintegrate (1.0.5) + cocoapods-downloader (2.1) + cocoapods-plugins (1.0.0) + nap + cocoapods-search (1.0.1) + cocoapods-trunk (1.6.0) + nap (>= 0.8, < 2.0) + netrc (~> 0.11) + cocoapods-try (1.2.0) + colored2 (3.1.2) + concurrent-ruby (1.2.2) + connection_pool (2.4.1) + drb (2.2.0) + ruby2_keywords + escape (0.0.4) + ethon (0.16.0) + ffi (>= 1.15.0) + ffi (1.16.3) + fourflusher (2.3.1) + fuzzy_match (2.0.4) + gh_inspector (1.1.3) + httpclient (2.8.3) + i18n (1.14.1) + concurrent-ruby (~> 1.0) + json (2.7.1) + minitest (5.20.0) + molinillo (0.8.0) + mutex_m (0.2.0) + nanaimo (0.3.0) + nap (1.1.0) + netrc (0.11.0) + public_suffix (4.0.7) + rexml (3.2.6) + ruby-macho (2.5.1) + ruby2_keywords (0.0.5) + typhoeus (1.4.1) + ethon (>= 0.9.0) + tzinfo (2.0.6) + concurrent-ruby (~> 1.0) + xcodeproj (1.23.0) + CFPropertyList (>= 2.3.3, < 4.0) + atomos (~> 0.1.3) + claide (>= 1.0.2, < 2.0) + colored2 (~> 3.1) + nanaimo (~> 0.3.0) + rexml (~> 3.2.4) + +PLATFORMS + arm64-darwin-22 + +DEPENDENCIES + cocoapods (= 1.14.2)! + +BUNDLED WITH + 2.2.3 diff --git a/Podfile.lock b/Podfile.lock index 55028505a..e4a14fc0a 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -182,4 +182,4 @@ SPEC CHECKSUMS: PODFILE CHECKSUM: 597cd2d7aa9ead11dfe63d03ada0bdffc6ee7ad8 -COCOAPODS: 1.13.0 +COCOAPODS: 1.14.2 diff --git a/Pods/Manifest.lock b/Pods/Manifest.lock index 55028505a..e4a14fc0a 100644 --- a/Pods/Manifest.lock +++ b/Pods/Manifest.lock @@ -182,4 +182,4 @@ SPEC CHECKSUMS: PODFILE CHECKSUM: 597cd2d7aa9ead11dfe63d03ada0bdffc6ee7ad8 -COCOAPODS: 1.13.0 +COCOAPODS: 1.14.2 From 47f417cabc50bc32b8b15ccd2a48af5729448518 Mon Sep 17 00:00:00 2001 From: Sharker <1548742234@qq.com> Date: Wed, 27 Dec 2023 11:08:34 +0800 Subject: [PATCH 3/9] chore: clean up code for double click --- .../ViewController/Window/WindowManager/EZWindowManager.m | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Easydict/Feature/ViewController/Window/WindowManager/EZWindowManager.m b/Easydict/Feature/ViewController/Window/WindowManager/EZWindowManager.m index d0e847786..f329f9ad8 100644 --- a/Easydict/Feature/ViewController/Window/WindowManager/EZWindowManager.m +++ b/Easydict/Feature/ViewController/Window/WindowManager/EZWindowManager.m @@ -149,7 +149,8 @@ - (void)setupEventMonitor { // TODO: Let users customize double-click shortcuts later on #if DEBUG mm_strongify(self); - [self showMiniFloatingWindow]; + // add double click as shortcuts feat in MAShortCut +// [self showMiniFloatingWindow]; #endif }]; } From 26e4e996c526d9ee51c07562edc8034241592e8c Mon Sep 17 00:00:00 2001 From: tisfeng Date: Wed, 27 Dec 2023 22:25:05 +0800 Subject: [PATCH 4/9] perf: resolve warning --- .../Window/WindowManager/EZWindowManager.m | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/Easydict/Feature/ViewController/Window/WindowManager/EZWindowManager.m b/Easydict/Feature/ViewController/Window/WindowManager/EZWindowManager.m index f329f9ad8..24204c5e4 100644 --- a/Easydict/Feature/ViewController/Window/WindowManager/EZWindowManager.m +++ b/Easydict/Feature/ViewController/Window/WindowManager/EZWindowManager.m @@ -144,14 +144,7 @@ - (void)setupEventMonitor { }]; [self.eventMonitor setDoubleCommandBlock:^{ - NSLog(@"double command"); - - // TODO: Let users customize double-click shortcuts later on -#if DEBUG - mm_strongify(self); - // add double click as shortcuts feat in MAShortCut -// [self showMiniFloatingWindow]; -#endif + NSLog(@"double command block"); }]; } From 363b8798003eb72af9de86853c35a8d48e6fffad Mon Sep 17 00:00:00 2001 From: Sharker <1548742234@qq.com> Date: Thu, 28 Dec 2023 00:00:46 +0800 Subject: [PATCH 5/9] fix: hidden pop button when user playing shortcut --- Easydict/Feature/Shortcut/EZShortcut.m | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Easydict/Feature/Shortcut/EZShortcut.m b/Easydict/Feature/Shortcut/EZShortcut.m index 69becdc1c..f49ed9047 100644 --- a/Easydict/Feature/Shortcut/EZShortcut.m +++ b/Easydict/Feature/Shortcut/EZShortcut.m @@ -48,23 +48,29 @@ + (void)setup { [[MASShortcutBinder sharedBinder] setBindingOptions:@{NSValueTransformerNameBindingOption: NSSecureUnarchiveFromDataTransformerName}]; */ + // hidden pop button when user playing shortcut [[MASShortcutBinder sharedBinder] bindShortcutWithDefaultsKey:EZSelectionShortcutKey toAction:^{ + [windowManager.popButtonWindow close]; [windowManager selectTextTranslate]; }]; [[MASShortcutBinder sharedBinder] bindShortcutWithDefaultsKey:EZSnipShortcutKey toAction:^{ + [windowManager.popButtonWindow close]; [windowManager snipTranslate]; }]; [[MASShortcutBinder sharedBinder] bindShortcutWithDefaultsKey:EZInputShortcutKey toAction:^{ + [windowManager.popButtonWindow close]; [windowManager inputTranslate]; }]; [[MASShortcutBinder sharedBinder] bindShortcutWithDefaultsKey:EZShowMiniShortcutKey toAction:^{ + [windowManager.popButtonWindow close]; [windowManager showMiniFloatingWindow]; }]; [[MASShortcutBinder sharedBinder] bindShortcutWithDefaultsKey:EZScreenshotOCRShortcutKey toAction:^{ + [windowManager.popButtonWindow close]; [windowManager screenshotOCR]; }]; From 6eea2f6dc47ebeb71be4f0a9c53ee8c8cd95484a Mon Sep 17 00:00:00 2001 From: Sharker <1548742234@qq.com> Date: Sat, 30 Dec 2023 16:22:59 +0800 Subject: [PATCH 6/9] fix: hidden pop button when user playing shortcut --- Easydict.xcodeproj/project.pbxproj | 6 ++++++ Easydict/Feature/Shortcut/EZShortcut.m | 19 +++++++------------ .../MASShortcutBinder+EZMASShortcutBinder.h | 18 ++++++++++++++++++ .../MASShortcutBinder+EZMASShortcutBinder.m | 18 ++++++++++++++++++ 4 files changed, 49 insertions(+), 12 deletions(-) create mode 100644 Easydict/Feature/Shortcut/MASShortcutBinder+EZMASShortcutBinder.h create mode 100644 Easydict/Feature/Shortcut/MASShortcutBinder+EZMASShortcutBinder.m diff --git a/Easydict.xcodeproj/project.pbxproj b/Easydict.xcodeproj/project.pbxproj index 0d3b2c8e5..ab519311d 100644 --- a/Easydict.xcodeproj/project.pbxproj +++ b/Easydict.xcodeproj/project.pbxproj @@ -227,6 +227,7 @@ 6295DE342A84EF76006145F4 /* EZBingLookupModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 6295DE332A84EF76006145F4 /* EZBingLookupModel.m */; }; 62A2D03F2A82967F007EEB01 /* EZBingRequest.m in Sources */ = {isa = PBXBuildFile; fileRef = 62A2D03E2A82967F007EEB01 /* EZBingRequest.m */; }; 62ED29A22B15F1F500901F51 /* EZWrapView.m in Sources */ = {isa = PBXBuildFile; fileRef = 62ED29A12B15F1F500901F51 /* EZWrapView.m */; }; + 9672D7D22B4008B40023B8FB /* MASShortcutBinder+EZMASShortcutBinder.m in Sources */ = {isa = PBXBuildFile; fileRef = 9672D7D12B4008B40023B8FB /* MASShortcutBinder+EZMASShortcutBinder.m */; }; A0B65CA0F31AC8ECFB8347CC /* Pods_EasydictTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 378E73A7EA8FC8FB9C975A63 /* Pods_EasydictTests.framework */; }; B87AC7E36367075BA5D13234 /* Pods_Easydict.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6372B33DFF803C7096A82250 /* Pods_Easydict.framework */; }; C4DD01E92B12B3C80025EE8E /* TencentService.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4DD01E82B12B3C80025EE8E /* TencentService.swift */; }; @@ -685,6 +686,8 @@ 62ED29A12B15F1F500901F51 /* EZWrapView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = EZWrapView.m; sourceTree = ""; }; 6372B33DFF803C7096A82250 /* Pods_Easydict.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Easydict.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 91E3E579C6DB88658B4BB102 /* Pods-Easydict.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Easydict.release.xcconfig"; path = "Target Support Files/Pods-Easydict/Pods-Easydict.release.xcconfig"; sourceTree = ""; }; + 9672D7D02B4008B40023B8FB /* MASShortcutBinder+EZMASShortcutBinder.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "MASShortcutBinder+EZMASShortcutBinder.h"; sourceTree = ""; }; + 9672D7D12B4008B40023B8FB /* MASShortcutBinder+EZMASShortcutBinder.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "MASShortcutBinder+EZMASShortcutBinder.m"; sourceTree = ""; }; A230E9A2358C7FBC7FB26189 /* Pods-EasydictTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-EasydictTests.debug.xcconfig"; path = "Target Support Files/Pods-EasydictTests/Pods-EasydictTests.debug.xcconfig"; sourceTree = ""; }; C4DD01E82B12B3C80025EE8E /* TencentService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TencentService.swift; sourceTree = ""; }; C4DD01EA2B12BA250025EE8E /* TencentResponse.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TencentResponse.swift; sourceTree = ""; }; @@ -1194,6 +1197,8 @@ children = ( 03F25CB129327BC200E66A12 /* EZShortcut.h */, 03F25CB229327BC200E66A12 /* EZShortcut.m */, + 9672D7D02B4008B40023B8FB /* MASShortcutBinder+EZMASShortcutBinder.h */, + 9672D7D12B4008B40023B8FB /* MASShortcutBinder+EZMASShortcutBinder.m */, ); path = Shortcut; sourceTree = ""; @@ -2404,6 +2409,7 @@ 03B0230129231FA6001C7E63 /* EZQueryView.m in Sources */, 03542A3D2937AF4F00C34C33 /* EZQueryResult.m in Sources */, 03262C1F29EF8EE500EFECA0 /* EZPrivacyViewController.m in Sources */, + 9672D7D22B4008B40023B8FB /* MASShortcutBinder+EZMASShortcutBinder.m in Sources */, 03BDA7BF2A26DA280079D04F /* NSScanner+EscapedScanning.m in Sources */, 03542A4C2937B5F100C34C33 /* EZYoudaoTranslate.m in Sources */, 037852B329583F5200D0E2CF /* EZServiceCell.m in Sources */, diff --git a/Easydict/Feature/Shortcut/EZShortcut.m b/Easydict/Feature/Shortcut/EZShortcut.m index f49ed9047..97889ce6f 100644 --- a/Easydict/Feature/Shortcut/EZShortcut.m +++ b/Easydict/Feature/Shortcut/EZShortcut.m @@ -8,6 +8,7 @@ #import "EZShortcut.h" #import "EZWindowManager.h" +#import "MASShortcutBinder+EZMASShortcutBinder.h" @implementation EZShortcut @@ -48,29 +49,23 @@ + (void)setup { [[MASShortcutBinder sharedBinder] setBindingOptions:@{NSValueTransformerNameBindingOption: NSSecureUnarchiveFromDataTransformerName}]; */ - // hidden pop button when user playing shortcut - [[MASShortcutBinder sharedBinder] bindShortcutWithDefaultsKey:EZSelectionShortcutKey toAction:^{ - [windowManager.popButtonWindow close]; + [[MASShortcutBinder sharedBinder] ez_bindShortcutWithDefaultsKey:EZSelectionShortcutKey toAction:^{ [windowManager selectTextTranslate]; }]; - [[MASShortcutBinder sharedBinder] bindShortcutWithDefaultsKey:EZSnipShortcutKey toAction:^{ - [windowManager.popButtonWindow close]; + [[MASShortcutBinder sharedBinder] ez_bindShortcutWithDefaultsKey:EZSelectionShortcutKey toAction:^{ [windowManager snipTranslate]; }]; - - [[MASShortcutBinder sharedBinder] bindShortcutWithDefaultsKey:EZInputShortcutKey toAction:^{ - [windowManager.popButtonWindow close]; + + [[MASShortcutBinder sharedBinder] ez_bindShortcutWithDefaultsKey:EZSelectionShortcutKey toAction:^{ [windowManager inputTranslate]; }]; - [[MASShortcutBinder sharedBinder] bindShortcutWithDefaultsKey:EZShowMiniShortcutKey toAction:^{ - [windowManager.popButtonWindow close]; + [[MASShortcutBinder sharedBinder] ez_bindShortcutWithDefaultsKey:EZShowMiniShortcutKey toAction:^{ [windowManager showMiniFloatingWindow]; }]; - [[MASShortcutBinder sharedBinder] bindShortcutWithDefaultsKey:EZScreenshotOCRShortcutKey toAction:^{ - [windowManager.popButtonWindow close]; + [[MASShortcutBinder sharedBinder] ez_bindShortcutWithDefaultsKey:EZScreenshotOCRShortcutKey toAction:^{ [windowManager screenshotOCR]; }]; diff --git a/Easydict/Feature/Shortcut/MASShortcutBinder+EZMASShortcutBinder.h b/Easydict/Feature/Shortcut/MASShortcutBinder+EZMASShortcutBinder.h new file mode 100644 index 000000000..1f2779e69 --- /dev/null +++ b/Easydict/Feature/Shortcut/MASShortcutBinder+EZMASShortcutBinder.h @@ -0,0 +1,18 @@ +// +// MASShortcutBinder+EZMASShortcutBinder.h +// Easydict +// +// Created by Sharker on 2023/12/30. +// Copyright © 2023 izual. All rights reserved. +// + +@import MASShortcut; + +NS_ASSUME_NONNULL_BEGIN + +@interface MASShortcutBinder (EZMASShortcutBinder) +// hidden pop button when user playing shortcut +- (void)ez_bindShortcutWithDefaultsKey: (NSString*) defaultsKeyName toAction: (dispatch_block_t) action; +@end + +NS_ASSUME_NONNULL_END diff --git a/Easydict/Feature/Shortcut/MASShortcutBinder+EZMASShortcutBinder.m b/Easydict/Feature/Shortcut/MASShortcutBinder+EZMASShortcutBinder.m new file mode 100644 index 000000000..6910d0dca --- /dev/null +++ b/Easydict/Feature/Shortcut/MASShortcutBinder+EZMASShortcutBinder.m @@ -0,0 +1,18 @@ +// +// MASShortcutBinder+EZMASShortcutBinder.m +// Easydict +// +// Created by Sharker on 2023/12/30. +// Copyright © 2023 izual. All rights reserved. +// + +#import "MASShortcutBinder+EZMASShortcutBinder.h" +#import "EZWindowManager.h" + +@implementation MASShortcutBinder (EZMASShortcutBinder) +- (void)ez_bindShortcutWithDefaultsKey:(NSString *)defaultsKeyName toAction:(dispatch_block_t)action { + EZWindowManager *windowManager = [EZWindowManager shared]; + [windowManager.popButtonWindow close]; + [self bindShortcutWithDefaultsKey:defaultsKeyName toAction:action]; +} +@end From 1a849eb2634c5f73fb32f9234092061d8cabc0bf Mon Sep 17 00:00:00 2001 From: Sharker <1548742234@qq.com> Date: Sat, 30 Dec 2023 20:31:19 +0800 Subject: [PATCH 7/9] fix: close main window --- Easydict/Feature/Shortcut/EZShortcut.m | 6 +++--- .../ViewController/Window/WindowManager/EZWindowManager.m | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Easydict/Feature/Shortcut/EZShortcut.m b/Easydict/Feature/Shortcut/EZShortcut.m index 97889ce6f..55d891f4c 100644 --- a/Easydict/Feature/Shortcut/EZShortcut.m +++ b/Easydict/Feature/Shortcut/EZShortcut.m @@ -53,11 +53,11 @@ + (void)setup { [windowManager selectTextTranslate]; }]; - [[MASShortcutBinder sharedBinder] ez_bindShortcutWithDefaultsKey:EZSelectionShortcutKey toAction:^{ + [[MASShortcutBinder sharedBinder] ez_bindShortcutWithDefaultsKey:EZSnipShortcutKey toAction:^{ [windowManager snipTranslate]; }]; - - [[MASShortcutBinder sharedBinder] ez_bindShortcutWithDefaultsKey:EZSelectionShortcutKey toAction:^{ + + [[MASShortcutBinder sharedBinder] ez_bindShortcutWithDefaultsKey:EZInputShortcutKey toAction:^{ [windowManager inputTranslate]; }]; diff --git a/Easydict/Feature/ViewController/Window/WindowManager/EZWindowManager.m b/Easydict/Feature/ViewController/Window/WindowManager/EZWindowManager.m index 24204c5e4..639b6abec 100644 --- a/Easydict/Feature/ViewController/Window/WindowManager/EZWindowManager.m +++ b/Easydict/Feature/ViewController/Window/WindowManager/EZWindowManager.m @@ -906,6 +906,7 @@ - (void)closeFloatingWindow { if ([EZMainQueryWindow isAlive]) { [self.mainWindow orderBack:nil]; + [self.mainWindow close]; } // Move floating window type to second. From 4c93a3aa8a8249ed79e4b3bc8384a862bd0cd11e Mon Sep 17 00:00:00 2001 From: Sharker <1548742234@qq.com> Date: Sat, 30 Dec 2023 21:45:34 +0800 Subject: [PATCH 8/9] fix: close main window --- .../ViewController/Window/WindowManager/EZWindowManager.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Easydict/Feature/ViewController/Window/WindowManager/EZWindowManager.m b/Easydict/Feature/ViewController/Window/WindowManager/EZWindowManager.m index 639b6abec..d11e00058 100644 --- a/Easydict/Feature/ViewController/Window/WindowManager/EZWindowManager.m +++ b/Easydict/Feature/ViewController/Window/WindowManager/EZWindowManager.m @@ -438,6 +438,7 @@ - (void)showFloatingWindow:(EZBaseQueryWindow *)window atPoint:(CGPoint)point { // mainWindow has been ordered out before, so we need to order back. if ([EZMainQueryWindow isAlive]) { [self.mainWindow orderBack:nil]; + [self.mainWindow close]; } } @@ -906,7 +907,6 @@ - (void)closeFloatingWindow { if ([EZMainQueryWindow isAlive]) { [self.mainWindow orderBack:nil]; - [self.mainWindow close]; } // Move floating window type to second. From 28d3b226152e00e5a891a6429d6d0b1684072bde Mon Sep 17 00:00:00 2001 From: Sharker <1548742234@qq.com> Date: Sat, 30 Dec 2023 21:54:59 +0800 Subject: [PATCH 9/9] fix: revert self.mainWindow close commit --- .../ViewController/Window/WindowManager/EZWindowManager.m | 1 - 1 file changed, 1 deletion(-) diff --git a/Easydict/Feature/ViewController/Window/WindowManager/EZWindowManager.m b/Easydict/Feature/ViewController/Window/WindowManager/EZWindowManager.m index d11e00058..24204c5e4 100644 --- a/Easydict/Feature/ViewController/Window/WindowManager/EZWindowManager.m +++ b/Easydict/Feature/ViewController/Window/WindowManager/EZWindowManager.m @@ -438,7 +438,6 @@ - (void)showFloatingWindow:(EZBaseQueryWindow *)window atPoint:(CGPoint)point { // mainWindow has been ordered out before, so we need to order back. if ([EZMainQueryWindow isAlive]) { [self.mainWindow orderBack:nil]; - [self.mainWindow close]; } }