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

Fix warnings

This commit is contained in:
Sergey Ryazanov 2021-06-10 16:03:28 +04:00
parent 718e95e3c7
commit c832198cb9

View File

@ -16,9 +16,9 @@ class HapticFeedback {
// Open IORegistryExplorer app, search for AppleMultitouchDevice and get "Multitouch ID" // Open IORegistryExplorer app, search for AppleMultitouchDevice and get "Multitouch ID"
// There should be programmatic way to get it but I can't find, no docs for macOS :( // There should be programmatic way to get it but I can't find, no docs for macOS :(
private let possibleDeviceIDs: [UInt64] = [ private let possibleDeviceIDs: [UInt64] = [
0x200_0000_0100_0000, // MacBook Pro 2016/2017 0x200_0000_0100_0000, // MacBook Pro 2016/2017
0x300000080500000, // MacBook Pro 2019 (possibly 2018 as well) 0x300_0000_8050_0000, // MacBook Pro 2019/2018
0x200000000000024 // MacBook Pro (13-inch, M1, 2020) 0x200_0000_0000_0024, // MacBook Pro (13-inch, M1, 2020)
] ]
// you can get a plist `otool -s __TEXT __tpad_act_plist /System/Library/PrivateFrameworks/MultitouchSupport.framework/Versions/Current/MultitouchSupport|tail -n +3|awk -F'\t' '{print $2}'|xxd -r -p` // you can get a plist `otool -s __TEXT __tpad_act_plist /System/Library/PrivateFrameworks/MultitouchSupport.framework/Versions/Current/MultitouchSupport|tail -n +3|awk -F'\t' '{print $2}'|xxd -r -p`
@ -33,7 +33,6 @@ class HapticFeedback {
case reserved2 = 16 case reserved2 = 16
} }
private var correctDeviceID: UInt64?
private var actuatorRef: CFTypeRef? private var actuatorRef: CFTypeRef?
static var instance = HapticFeedback() static var instance = HapticFeedback()
@ -42,7 +41,6 @@ class HapticFeedback {
private init() { private init() {
self.recreateDevice() self.recreateDevice()
// HapticFeedback.shared = AppSettings.hapticFeedbackState ? HapticFeedback() : nil
} }
private func recreateDevice() { private func recreateDevice() {
@ -51,52 +49,47 @@ class HapticFeedback {
self.actuatorRef = nil // just in case %) self.actuatorRef = nil // just in case %)
} }
if let correctDeviceID = self.correctDeviceID { guard self.actuatorRef == nil else {
self.actuatorRef = MTActuatorCreateFromDeviceID(correctDeviceID).takeRetainedValue() return
} else { }
// Let's find our Haptic device
self.possibleDeviceIDs.forEach {(deviceID) in
guard self.correctDeviceID == nil else {return}
self.actuatorRef = MTActuatorCreateFromDeviceID(deviceID).takeRetainedValue()
if self.actuatorRef != nil { // Let's find our Haptic device
self.correctDeviceID = deviceID self.possibleDeviceIDs.forEach {(deviceID) in
} let actuatorRef = MTActuatorCreateFromDeviceID(deviceID).takeRetainedValue()
if actuatorRef != nil {
self.actuatorRef = actuatorRef
} }
} }
} }
// MARK: - Tap action // MARK: - Tap action
func tap(type: HapticType) { private func getActuatorIfPosible() -> CFTypeRef? {
guard AppSettings.hapticFeedbackState else { guard AppSettings.hapticFeedbackState else { return nil }
// Haptic feedback is disabled by user guard let actuatorRef = self.actuatorRef else {
return
}
guard self.correctDeviceID != nil, let actuatorRef = self.actuatorRef else {
print("guard actuatorRef == nil (no haptic device found?)") print("guard actuatorRef == nil (no haptic device found?)")
return return nil
} }
var result: IOReturn guard MTActuatorOpen(actuatorRef) == kIOReturnSuccess else {
result = MTActuatorOpen(actuatorRef)
guard result == kIOReturnSuccess else {
print("guard MTActuatorOpen") print("guard MTActuatorOpen")
self.recreateDevice() self.recreateDevice()
return return nil
} }
print("Try tap with: \(type.rawValue)") return actuatorRef
result = MTActuatorActuate(actuatorRef, type.rawValue, 0, 0, 0) }
guard result == kIOReturnSuccess else {
func tap(type: HapticType) {
guard let actuator = getActuatorIfPosible() else { return }
guard MTActuatorActuate(actuator, type.rawValue, 0, 0, 0) == kIOReturnSuccess else {
print("guard MTActuatorActuate") print("guard MTActuatorActuate")
return return
} }
result = MTActuatorClose(actuatorRef) guard MTActuatorClose(actuator) == kIOReturnSuccess else {
guard result == kIOReturnSuccess else {
print("guard MTActuatorClose") print("guard MTActuatorClose")
return return
} }