1
0
mirror of https://github.com/Toxblh/MTMR.git synced 2026-01-10 17:08:39 +00:00

Merge branch 'ReDetection-disable-haptic'

This commit is contained in:
Toxblh 2019-10-12 13:06:27 +01:00
commit d4b950ab64
7 changed files with 34 additions and 10 deletions

View File

@ -25,6 +25,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
AXIsProcessTrustedWithOptions([kAXTrustedCheckOptionPrompt.takeRetainedValue() as NSString: true] as NSDictionary) AXIsProcessTrustedWithOptions([kAXTrustedCheckOptionPrompt.takeRetainedValue() as NSString: true] as NSDictionary)
TouchBarController.shared.setupControlStripPresence() TouchBarController.shared.setupControlStripPresence()
HapticFeedbackUpdate()
if let button = statusItem.button { if let button = statusItem.button {
button.image = #imageLiteral(resourceName: "StatusImage") button.image = #imageLiteral(resourceName: "StatusImage")
@ -40,6 +41,10 @@ class AppDelegate: NSObject, NSApplicationDelegate {
func applicationWillTerminate(_: Notification) {} func applicationWillTerminate(_: Notification) {}
func HapticFeedbackUpdate() {
HapticFeedback.shared = TouchBarController.shared.hapticFeedbackState ? HapticFeedback() : nil
}
@objc func updateIsBlockedApp() { @objc func updateIsBlockedApp() {
var blacklistAppIdentifiers: [String] = [] var blacklistAppIdentifiers: [String] = []
if let blackListed = UserDefaults.standard.stringArray(forKey: "com.toxblh.mtmr.blackListedApps") { if let blackListed = UserDefaults.standard.stringArray(forKey: "com.toxblh.mtmr.blackListedApps") {
@ -90,6 +95,12 @@ class AppDelegate: NSObject, NSApplicationDelegate {
} }
} }
@objc func toggleHapticFeedback(_: Any?) {
TouchBarController.shared.hapticFeedbackState = !TouchBarController.shared.hapticFeedbackState
HapticFeedbackUpdate()
createMenu()
}
@objc func openPreset(_: Any?) { @objc func openPreset(_: Any?) {
let dialog = NSOpenPanel() let dialog = NSOpenPanel()
@ -124,6 +135,9 @@ class AppDelegate: NSObject, NSApplicationDelegate {
let hideControlStrip = NSMenuItem(title: "Hide Control Strip", action: #selector(toggleControlStrip(_:)), keyEquivalent: "T") let hideControlStrip = NSMenuItem(title: "Hide Control Strip", action: #selector(toggleControlStrip(_:)), keyEquivalent: "T")
hideControlStrip.state = TouchBarController.shared.showControlStripState ? .off : .on hideControlStrip.state = TouchBarController.shared.showControlStripState ? .off : .on
let hapticFeedback = NSMenuItem(title: "Haptic Feedback", action: #selector(toggleHapticFeedback(_:)), keyEquivalent: "H")
hapticFeedback.state = TouchBarController.shared.hapticFeedbackState ? .on : .off
let settingSeparator = NSMenuItem(title: "Settings", action: nil, keyEquivalent: "") let settingSeparator = NSMenuItem(title: "Settings", action: nil, keyEquivalent: "")
settingSeparator.isEnabled = false settingSeparator.isEnabled = false
@ -133,6 +147,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
menu.addItem(NSMenuItem.separator()) menu.addItem(NSMenuItem.separator())
menu.addItem(settingSeparator) menu.addItem(settingSeparator)
menu.addItem(hapticFeedback)
menu.addItem(hideControlStrip) menu.addItem(hideControlStrip)
menu.addItem(toggleBlackList) menu.addItem(toggleBlackList)
menu.addItem(startAtLogin) menu.addItem(startAtLogin)

View File

@ -176,12 +176,12 @@ class CustomButtonCell: NSButtonCell {
class HapticClickGestureRecognizer: NSClickGestureRecognizer { class HapticClickGestureRecognizer: NSClickGestureRecognizer {
override func touchesBegan(with event: NSEvent) { override func touchesBegan(with event: NSEvent) {
HapticFeedback.shared.tap(strong: 2) HapticFeedback.shared?.tap(strong: 2)
super.touchesBegan(with: event) super.touchesBegan(with: event)
} }
override func touchesEnded(with event: NSEvent) { override func touchesEnded(with event: NSEvent) {
HapticFeedback.shared.tap(strong: 1) HapticFeedback.shared?.tap(strong: 1)
super.touchesEnded(with: event) super.touchesEnded(with: event)
} }
} }
@ -226,7 +226,7 @@ class LongPressGestureRecognizer: NSPressGestureRecognizer {
@objc private func onTimer() { @objc private func onTimer() {
if let target = self.target, let action = self.action { if let target = self.target, let action = self.action {
target.performSelector(onMainThread: action, with: self, waitUntilDone: false) target.performSelector(onMainThread: action, with: self, waitUntilDone: false)
HapticFeedback.shared.tap(strong: 6) HapticFeedback.shared?.tap(strong: 6)
} }
} }

View File

@ -9,7 +9,7 @@
import IOKit import IOKit
class HapticFeedback { class HapticFeedback {
static let shared = HapticFeedback() static var shared: HapticFeedback?
// Here we have list of possible IDs for Haptic Generator Device. They are not constant // Here we have list of possible IDs for Haptic Generator Device. They are not constant
// To find deviceID, you will need IORegistryExplorer app from Additional Tools for Xcode dmg // To find deviceID, you will need IORegistryExplorer app from Additional Tools for Xcode dmg

View File

@ -19,7 +19,7 @@
<key>CFBundleShortVersionString</key> <key>CFBundleShortVersionString</key>
<string>0.23.1</string> <string>0.23.1</string>
<key>CFBundleVersion</key> <key>CFBundleVersion</key>
<string>278</string> <string>294</string>
<key>LSApplicationCategoryType</key> <key>LSApplicationCategoryType</key>
<string>public.app-category.utilities</string> <string>public.app-category.utilities</string>
<key>LSMinimumSystemVersion</key> <key>LSMinimumSystemVersion</key>

View File

@ -3,7 +3,7 @@ import Foundation
extension Data { extension Data {
func barItemDefinitions() -> [BarItemDefinition]? { func barItemDefinitions() -> [BarItemDefinition]? {
return try? JSONDecoder().decode([BarItemDefinition].self, from: utf8string!.stripComments().data(using: .utf8)!) return try? JSONDecoder().decode([BarItemDefinition].self, from: utf8string!.stripComments().data(using: .utf8)!)
} }
} }

View File

@ -89,6 +89,15 @@ class TouchBarController: NSObject, NSTouchBarDelegate {
UserDefaults.standard.set(newValue, forKey: "com.toxblh.mtmr.settings.showControlStrip") UserDefaults.standard.set(newValue, forKey: "com.toxblh.mtmr.settings.showControlStrip")
} }
} }
var hapticFeedbackState: Bool {
get {
return UserDefaults.standard.bool(forKey: "com.toxblh.mtmr.settings.hapticFeedback")
}
set {
UserDefaults.standard.set(newValue, forKey: "com.toxblh.mtmr.settings.hapticFeedback")
}
}
var blacklistAppIdentifiers: [String] = [] var blacklistAppIdentifiers: [String] = []
var frontmostApplicationIdentifier: String? { var frontmostApplicationIdentifier: String? {

View File

@ -146,12 +146,12 @@ class AppScrubberTouchBarItem: NSCustomTouchBarItem, NSScrubberDelegate, NSScrub
ticks += 1 ticks += 1
if ticks == minTicks { if ticks == minTicks {
HapticFeedback.shared.tap(strong: 2) HapticFeedback.shared?.tap(strong: 2)
} }
if ticks > maxTicks { if ticks > maxTicks {
stopTimer() stopTimer()
HapticFeedback.shared.tap(strong: 6) HapticFeedback.shared?.tap(strong: 6)
} }
} }
@ -182,7 +182,7 @@ class AppScrubberTouchBarItem: NSCustomTouchBarItem, NSScrubberDelegate, NSScrub
NSWorkspace.shared.openFile(bundleIdentifier!.replacingOccurrences(of: "file://", with: "")) NSWorkspace.shared.openFile(bundleIdentifier!.replacingOccurrences(of: "file://", with: ""))
} else { } else {
NSWorkspace.shared.launchApplication(withBundleIdentifier: bundleIdentifier!, options: [.default], additionalEventParamDescriptor: nil, launchIdentifier: nil) NSWorkspace.shared.launchApplication(withBundleIdentifier: bundleIdentifier!, options: [.default], additionalEventParamDescriptor: nil, launchIdentifier: nil)
HapticFeedback.shared.tap(strong: 6) HapticFeedback.shared?.tap(strong: 6)
} }
updateRunningApplication() updateRunningApplication()
@ -201,7 +201,7 @@ class AppScrubberTouchBarItem: NSCustomTouchBarItem, NSScrubberDelegate, NSScrub
} }
} }
} else { } else {
HapticFeedback.shared.tap(strong: 6) HapticFeedback.shared?.tap(strong: 6)
if let index = self.persistentAppIdentifiers.index(of: bundleIdentifier!) { if let index = self.persistentAppIdentifiers.index(of: bundleIdentifier!) {
persistentAppIdentifiers.remove(at: index) persistentAppIdentifiers.remove(at: index)
} else { } else {