From 63e3de7313f9327750b7f178a05a437579c48f59 Mon Sep 17 00:00:00 2001 From: bobrosoft Date: Tue, 6 Aug 2019 15:03:01 +0200 Subject: [PATCH] CustomButtonTouchBarItem: try to fix strange app hanging (attempt 2) --- MTMR/CustomButtonTouchBarItem.swift | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/MTMR/CustomButtonTouchBarItem.swift b/MTMR/CustomButtonTouchBarItem.swift index c9d4306..428ca05 100644 --- a/MTMR/CustomButtonTouchBarItem.swift +++ b/MTMR/CustomButtonTouchBarItem.swift @@ -190,12 +190,7 @@ 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) { [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) - } - } + timer = Timer.scheduledTimer(timeInterval: 0.25, target: self, selector: #selector(self.onTimer), userInfo: nil, repeats: false) } super.touchesBegan(with: event) @@ -223,6 +218,13 @@ class LongPressGestureRecognizer: NSPressGestureRecognizer { } } + @objc private func onTimer() { + if let target = self.target, let action = self.action { + target.performSelector(onMainThread: action, with: self, waitUntilDone: false) + HapticFeedback.shared.tap(strong: 6) + } + } + deinit { timerInvalidate() }