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

patch. work on macos version >=10.12.2

This commit is contained in:
Toxblh 2018-04-09 11:35:39 +01:00
parent 2dc1148a2a
commit 59a8bb6430
4 changed files with 36 additions and 30 deletions

View File

@ -404,7 +404,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES; GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 10.13; MACOSX_DEPLOYMENT_TARGET = 10.12;
MTL_ENABLE_DEBUG_INFO = YES; MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES; ONLY_ACTIVE_ARCH = YES;
SDKROOT = macosx; SDKROOT = macosx;
@ -457,7 +457,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES; GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 10.13; MACOSX_DEPLOYMENT_TARGET = 10.12;
MTL_ENABLE_DEBUG_INFO = NO; MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = macosx; SDKROOT = macosx;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";

View File

@ -14,7 +14,11 @@ class AppDelegate: NSObject, NSApplicationDelegate {
func applicationDidFinishLaunching(_ aNotification: Notification) { func applicationDidFinishLaunching(_ aNotification: Notification) {
TouchBarController.shared.setupControlStripPresence() if #available(OSX 10.12.2, *) {
TouchBarController.shared.setupControlStripPresence()
} else {
// Fallback on earlier versions
}
// Insert code here to initialize your application // Insert code here to initialize your application
} }

View File

@ -8,32 +8,33 @@
import Cocoa import Cocoa
@available(OSX 10.12.2, *)
class TouchBarController: NSObject, NSTouchBarDelegate { class TouchBarController: NSObject, NSTouchBarDelegate {
static let shared = TouchBarController() static let shared = TouchBarController()
let touchBar = NSTouchBar() let touchBar = NSTouchBar()
var timer = Timer() var timer = Timer()
var timeButton: NSButton = NSButton() var timeButton: NSButton = NSButton()
private override init() { private override init() {
super.init() super.init()
touchBar.delegate = self touchBar.delegate = self
touchBar.defaultItemIdentifiers = [ touchBar.defaultItemIdentifiers = [
.escButton, .escButton,
.dismissButton, .dismissButton,
.brightDown, .brightDown,
.brightUp, .brightUp,
.prev, .prev,
.play, .play,
.next, .next,
.sleep, .sleep,
.weather, .weather,
.volumeDown, .volumeDown,
.volumeUp, .volumeUp,
.battery, .battery,
@ -50,19 +51,19 @@ class TouchBarController: NSObject, NSTouchBarDelegate {
DFRElementSetControlStripPresenceForIdentifier(.controlStripItem, true) DFRElementSetControlStripPresenceForIdentifier(.controlStripItem, true)
timer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(self.updateTime), userInfo: nil, repeats: true) timer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(self.updateTime), userInfo: nil, repeats: true)
} }
func updateControlStripPresence() { func updateControlStripPresence() {
DFRElementSetControlStripPresenceForIdentifier(.controlStripItem, true) DFRElementSetControlStripPresenceForIdentifier(.controlStripItem, true)
} }
@objc private func presentTouchBar() { @objc private func presentTouchBar() {
NSTouchBar.presentSystemModalFunctionBar(touchBar, placement: 1, systemTrayItemIdentifier: .controlStripItem) NSTouchBar.presentSystemModalFunctionBar(touchBar, placement: 1, systemTrayItemIdentifier: .controlStripItem)
} }
@objc private func dismissTouchBar() { @objc private func dismissTouchBar() {
NSTouchBar.minimizeSystemModalFunctionBar(touchBar) NSTouchBar.minimizeSystemModalFunctionBar(touchBar)
} }
func touchBar(_ touchBar: NSTouchBar, makeItemForIdentifier identifier: NSTouchBarItem.Identifier) -> NSTouchBarItem? { func touchBar(_ touchBar: NSTouchBar, makeItemForIdentifier identifier: NSTouchBarItem.Identifier) -> NSTouchBarItem? {
switch identifier { switch identifier {
case .escButton: case .escButton:
@ -73,7 +74,7 @@ class TouchBarController: NSObject, NSTouchBarDelegate {
let item = NSCustomTouchBarItem(identifier: identifier) let item = NSCustomTouchBarItem(identifier: identifier)
item.view = NSButton(title: "exit", target: self, action: #selector(dismissTouchBar)) item.view = NSButton(title: "exit", target: self, action: #selector(dismissTouchBar))
return item return item
case .brightUp: case .brightUp:
let item = NSCustomTouchBarItem(identifier: identifier) let item = NSCustomTouchBarItem(identifier: identifier)
item.view = NSButton(title: "🔆", target: self, action: #selector(handleBrightUp)) item.view = NSButton(title: "🔆", target: self, action: #selector(handleBrightUp))
@ -91,7 +92,7 @@ class TouchBarController: NSObject, NSTouchBarDelegate {
let item = NSCustomTouchBarItem(identifier: identifier) let item = NSCustomTouchBarItem(identifier: identifier)
item.view = NSButton(title: "🔊", target: self, action: #selector(handleVolumeUp)) item.view = NSButton(title: "🔊", target: self, action: #selector(handleVolumeUp))
return item return item
case .prev: case .prev:
let item = NSCustomTouchBarItem(identifier: identifier) let item = NSCustomTouchBarItem(identifier: identifier)
item.view = NSButton(title: "", target: self, action: #selector(handlePrev)) item.view = NSButton(title: "", target: self, action: #selector(handlePrev))
@ -104,18 +105,18 @@ class TouchBarController: NSObject, NSTouchBarDelegate {
let item = NSCustomTouchBarItem(identifier: identifier) let item = NSCustomTouchBarItem(identifier: identifier)
item.view = NSButton(title: "", target: self, action: #selector(handleNext)) item.view = NSButton(title: "", target: self, action: #selector(handleNext))
return item return item
case .time: case .time:
let item = NSCustomTouchBarItem(identifier: identifier) let item = NSCustomTouchBarItem(identifier: identifier)
timeButton = NSButton(title: self.getCurrentTime(), target: self, action: nil) timeButton = NSButton(title: self.getCurrentTime(), target: self, action: nil)
item.view = timeButton item.view = timeButton
return item return item
default: default:
return nil return nil
} }
} }
func getCurrentTime() -> String { func getCurrentTime() -> String {
let date = Date() let date = Date()
let dateFormatter = DateFormatter() let dateFormatter = DateFormatter()
@ -123,50 +124,50 @@ class TouchBarController: NSObject, NSTouchBarDelegate {
let timestamp = dateFormatter.string(from: date) let timestamp = dateFormatter.string(from: date)
return timestamp return timestamp
} }
@objc func updateTime() { @objc func updateTime() {
timeButton.title = getCurrentTime() timeButton.title = getCurrentTime()
} }
@objc func handleEsc() { @objc func handleEsc() {
let sender = ESCKeyPress() let sender = ESCKeyPress()
sender.send() sender.send()
} }
@objc func handleVolumeUp() { @objc func handleVolumeUp() {
HIDPostAuxKey(Int(NX_KEYTYPE_SOUND_UP)) HIDPostAuxKey(Int(NX_KEYTYPE_SOUND_UP))
} }
@objc func handleVolumeDown() { @objc func handleVolumeDown() {
HIDPostAuxKey(Int(NX_KEYTYPE_SOUND_DOWN)) HIDPostAuxKey(Int(NX_KEYTYPE_SOUND_DOWN))
} }
@objc func handleBrightDown() { @objc func handleBrightDown() {
// HIDPostAuxKey(Int(NX_KEYTYPE_BRIGHTNESS_DOWN)) // HIDPostAuxKey(Int(NX_KEYTYPE_BRIGHTNESS_DOWN))
let sender = BrightnessUpPress() let sender = BrightnessUpPress()
sender.send() sender.send()
} }
@objc func handleBrightUp() { @objc func handleBrightUp() {
// HIDPostAuxKey(Int(NX_KEYTYPE_BRIGHTNESS_UP)) // HIDPostAuxKey(Int(NX_KEYTYPE_BRIGHTNESS_UP))
let sender = BrightnessDownPress() let sender = BrightnessDownPress()
sender.send() sender.send()
} }
@objc func handlePrev() { @objc func handlePrev() {
HIDPostAuxKey(Int(NX_KEYTYPE_PREVIOUS)) HIDPostAuxKey(Int(NX_KEYTYPE_PREVIOUS))
} }
@objc func handlePlay() { @objc func handlePlay() {
HIDPostAuxKey(Int(NX_KEYTYPE_PLAY)) HIDPostAuxKey(Int(NX_KEYTYPE_PLAY))
} }
@objc func handleNext() { @objc func handleNext() {
HIDPostAuxKey(Int(NX_KEYTYPE_NEXT)) HIDPostAuxKey(Int(NX_KEYTYPE_NEXT))
} }
// func getBattery() { // func getBattery() {
// var error: NSDictionary? // var error: NSDictionary?
// if let scriptObject = NSAppleScript(source: <#T##String#>) { // if let scriptObject = NSAppleScript(source: <#T##String#>) {

View File

@ -8,6 +8,7 @@
import Cocoa import Cocoa
@available(OSX 10.12.2, *)
extension NSTouchBarItem.Identifier { extension NSTouchBarItem.Identifier {
static let escButton = NSTouchBarItem.Identifier("com.toxblh.mtmr.escButton") static let escButton = NSTouchBarItem.Identifier("com.toxblh.mtmr.escButton")
static let dismissButton = NSTouchBarItem.Identifier("com.toxblh.mtmr.dismissButton") static let dismissButton = NSTouchBarItem.Identifier("com.toxblh.mtmr.dismissButton")