Skip to content

Commit d4b950a

Browse files
committed
Merge branch 'ReDetection-disable-haptic'
2 parents f378de6 + 41a9544 commit d4b950a

File tree

7 files changed

+34
-10
lines changed

7 files changed

+34
-10
lines changed

MTMR/AppDelegate.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
2525
AXIsProcessTrustedWithOptions([kAXTrustedCheckOptionPrompt.takeRetainedValue() as NSString: true] as NSDictionary)
2626

2727
TouchBarController.shared.setupControlStripPresence()
28+
HapticFeedbackUpdate()
2829

2930
if let button = statusItem.button {
3031
button.image = #imageLiteral(resourceName: "StatusImage")
@@ -40,6 +41,10 @@ class AppDelegate: NSObject, NSApplicationDelegate {
4041

4142
func applicationWillTerminate(_: Notification) {}
4243

44+
func HapticFeedbackUpdate() {
45+
HapticFeedback.shared = TouchBarController.shared.hapticFeedbackState ? HapticFeedback() : nil
46+
}
47+
4348
@objc func updateIsBlockedApp() {
4449
var blacklistAppIdentifiers: [String] = []
4550
if let blackListed = UserDefaults.standard.stringArray(forKey: "com.toxblh.mtmr.blackListedApps") {
@@ -90,6 +95,12 @@ class AppDelegate: NSObject, NSApplicationDelegate {
9095
}
9196
}
9297

98+
@objc func toggleHapticFeedback(_: Any?) {
99+
TouchBarController.shared.hapticFeedbackState = !TouchBarController.shared.hapticFeedbackState
100+
HapticFeedbackUpdate()
101+
createMenu()
102+
}
103+
93104
@objc func openPreset(_: Any?) {
94105
let dialog = NSOpenPanel()
95106

@@ -124,6 +135,9 @@ class AppDelegate: NSObject, NSApplicationDelegate {
124135
let hideControlStrip = NSMenuItem(title: "Hide Control Strip", action: #selector(toggleControlStrip(_:)), keyEquivalent: "T")
125136
hideControlStrip.state = TouchBarController.shared.showControlStripState ? .off : .on
126137

138+
let hapticFeedback = NSMenuItem(title: "Haptic Feedback", action: #selector(toggleHapticFeedback(_:)), keyEquivalent: "H")
139+
hapticFeedback.state = TouchBarController.shared.hapticFeedbackState ? .on : .off
140+
127141
let settingSeparator = NSMenuItem(title: "Settings", action: nil, keyEquivalent: "")
128142
settingSeparator.isEnabled = false
129143

@@ -133,6 +147,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
133147

134148
menu.addItem(NSMenuItem.separator())
135149
menu.addItem(settingSeparator)
150+
menu.addItem(hapticFeedback)
136151
menu.addItem(hideControlStrip)
137152
menu.addItem(toggleBlackList)
138153
menu.addItem(startAtLogin)

MTMR/CustomButtonTouchBarItem.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,12 +176,12 @@ class CustomButtonCell: NSButtonCell {
176176

177177
class HapticClickGestureRecognizer: NSClickGestureRecognizer {
178178
override func touchesBegan(with event: NSEvent) {
179-
HapticFeedback.shared.tap(strong: 2)
179+
HapticFeedback.shared?.tap(strong: 2)
180180
super.touchesBegan(with: event)
181181
}
182182

183183
override func touchesEnded(with event: NSEvent) {
184-
HapticFeedback.shared.tap(strong: 1)
184+
HapticFeedback.shared?.tap(strong: 1)
185185
super.touchesEnded(with: event)
186186
}
187187
}
@@ -226,7 +226,7 @@ class LongPressGestureRecognizer: NSPressGestureRecognizer {
226226
@objc private func onTimer() {
227227
if let target = self.target, let action = self.action {
228228
target.performSelector(onMainThread: action, with: self, waitUntilDone: false)
229-
HapticFeedback.shared.tap(strong: 6)
229+
HapticFeedback.shared?.tap(strong: 6)
230230
}
231231
}
232232

MTMR/HapticFeedback.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import IOKit
1010

1111
class HapticFeedback {
12-
static let shared = HapticFeedback()
12+
static var shared: HapticFeedback?
1313

1414
// Here we have list of possible IDs for Haptic Generator Device. They are not constant
1515
// To find deviceID, you will need IORegistryExplorer app from Additional Tools for Xcode dmg

MTMR/Info.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<key>CFBundleShortVersionString</key>
2020
<string>0.23.1</string>
2121
<key>CFBundleVersion</key>
22-
<string>278</string>
22+
<string>294</string>
2323
<key>LSApplicationCategoryType</key>
2424
<string>public.app-category.utilities</string>
2525
<key>LSMinimumSystemVersion</key>

MTMR/ItemsParsing.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import Foundation
33

44
extension Data {
55
func barItemDefinitions() -> [BarItemDefinition]? {
6-
return try? JSONDecoder().decode([BarItemDefinition].self, from: utf8string!.stripComments().data(using: .utf8)!)
6+
return try? JSONDecoder().decode([BarItemDefinition].self, from: utf8string!.stripComments().data(using: .utf8)!)
77
}
88
}
99

MTMR/TouchBarController.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,15 @@ class TouchBarController: NSObject, NSTouchBarDelegate {
8989
UserDefaults.standard.set(newValue, forKey: "com.toxblh.mtmr.settings.showControlStrip")
9090
}
9191
}
92+
93+
var hapticFeedbackState: Bool {
94+
get {
95+
return UserDefaults.standard.bool(forKey: "com.toxblh.mtmr.settings.hapticFeedback")
96+
}
97+
set {
98+
UserDefaults.standard.set(newValue, forKey: "com.toxblh.mtmr.settings.hapticFeedback")
99+
}
100+
}
92101

93102
var blacklistAppIdentifiers: [String] = []
94103
var frontmostApplicationIdentifier: String? {

MTMR/Widgets/AppScrubberTouchBarItem.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,12 +146,12 @@ class AppScrubberTouchBarItem: NSCustomTouchBarItem, NSScrubberDelegate, NSScrub
146146
ticks += 1
147147

148148
if ticks == minTicks {
149-
HapticFeedback.shared.tap(strong: 2)
149+
HapticFeedback.shared?.tap(strong: 2)
150150
}
151151

152152
if ticks > maxTicks {
153153
stopTimer()
154-
HapticFeedback.shared.tap(strong: 6)
154+
HapticFeedback.shared?.tap(strong: 6)
155155
}
156156
}
157157

@@ -182,7 +182,7 @@ class AppScrubberTouchBarItem: NSCustomTouchBarItem, NSScrubberDelegate, NSScrub
182182
NSWorkspace.shared.openFile(bundleIdentifier!.replacingOccurrences(of: "file://", with: ""))
183183
} else {
184184
NSWorkspace.shared.launchApplication(withBundleIdentifier: bundleIdentifier!, options: [.default], additionalEventParamDescriptor: nil, launchIdentifier: nil)
185-
HapticFeedback.shared.tap(strong: 6)
185+
HapticFeedback.shared?.tap(strong: 6)
186186
}
187187
updateRunningApplication()
188188

@@ -201,7 +201,7 @@ class AppScrubberTouchBarItem: NSCustomTouchBarItem, NSScrubberDelegate, NSScrub
201201
}
202202
}
203203
} else {
204-
HapticFeedback.shared.tap(strong: 6)
204+
HapticFeedback.shared?.tap(strong: 6)
205205
if let index = self.persistentAppIdentifiers.index(of: bundleIdentifier!) {
206206
persistentAppIdentifiers.remove(at: index)
207207
} else {

0 commit comments

Comments
 (0)