diff --git a/MTMR/CustomButtonTouchBarItem.swift b/MTMR/CustomButtonTouchBarItem.swift index d218451..c9d4306 100644 --- a/MTMR/CustomButtonTouchBarItem.swift +++ b/MTMR/CustomButtonTouchBarItem.swift @@ -190,9 +190,9 @@ class LongPressGestureRecognizer: NSPressGestureRecognizer { let touches = event.touches(for: self.view!) if touches.count == 1 { // to prevent it for built-in two/three-finger gestures - timer = Timer.scheduledTimer(withTimeInterval: recognizeTimeout, repeats: false) { _ in - if let target = self.target, let action = self.action { - target.performSelector(inBackground: action, with: self) + timer = Timer.scheduledTimer(withTimeInterval: recognizeTimeout, repeats: false) { [weak self] _ in + if let _self = self, let target = self?.target, let action = self?.action { + target.performSelector(onMainThread: action, with: _self, waitUntilDone: false) HapticFeedback.shared.tap(strong: 6) } } @@ -222,6 +222,10 @@ class LongPressGestureRecognizer: NSPressGestureRecognizer { self.timer = nil } } + + deinit { + timerInvalidate() + } } extension String {