cocoabits / MASShortcut

Modern framework for managing global keyboard shortcuts compatible with Mac App Store. More details:
http://blog.shpakovski.com/2012/07/global-keyboard-shortcuts-in-cocoa.html
BSD 2-Clause "Simplified" License
1.52k stars 220 forks source link

Event deadlock in MASShortcutView.m #91

Open dsanghan opened 8 years ago

dsanghan commented 8 years ago

I'm using the MASShortcutView inside an NSTableView which is inside an NSPopover. The popover autoreleases its memory with a delay on closing it. What this causes is that the MASShortcutView inside the table cell gets deallocated with a delay thereby triggering [self activateEventMonitoring:NO]; with a delay as well. Since the dealloc happens after this delay, and if another NSPopover is opened in the mean time, the [self activateEventMonitoring:YES]; triggers before the dealloc causing the event monitor to be re-registered first and then removed (incorrectly) on the dealloc.

To be clear: Open popover -> Click on an MASShortcutView to trigger recording -> Set the new shortcut -> Close popover -> Open popover -> Click again on an MASShortcutView -> Can't set the new shortcut since the dealloc happens around this time for the old popover.

shpakovski commented 8 years ago

Thank you for the report! So it should be a counter and methods beginEventMonitoring / endEventMonitoring which stops monitoring when it reaches zero 🤔 Would this help?

dsanghan commented 8 years ago

Yup. I think that should work. Thanks!