Skip to content

Commit 59a8bb6

Browse files
committed
patch. work on macos version >=10.12.2
1 parent 2dc1148 commit 59a8bb6

File tree

4 files changed

+36
-30
lines changed

4 files changed

+36
-30
lines changed

MTMR.xcodeproj/project.pbxproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@
404404
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
405405
GCC_WARN_UNUSED_FUNCTION = YES;
406406
GCC_WARN_UNUSED_VARIABLE = YES;
407-
MACOSX_DEPLOYMENT_TARGET = 10.13;
407+
MACOSX_DEPLOYMENT_TARGET = 10.12;
408408
MTL_ENABLE_DEBUG_INFO = YES;
409409
ONLY_ACTIVE_ARCH = YES;
410410
SDKROOT = macosx;
@@ -457,7 +457,7 @@
457457
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
458458
GCC_WARN_UNUSED_FUNCTION = YES;
459459
GCC_WARN_UNUSED_VARIABLE = YES;
460-
MACOSX_DEPLOYMENT_TARGET = 10.13;
460+
MACOSX_DEPLOYMENT_TARGET = 10.12;
461461
MTL_ENABLE_DEBUG_INFO = NO;
462462
SDKROOT = macosx;
463463
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";

MTMR/AppDelegate.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@ class AppDelegate: NSObject, NSApplicationDelegate {
1414

1515

1616
func applicationDidFinishLaunching(_ aNotification: Notification) {
17-
TouchBarController.shared.setupControlStripPresence()
17+
if #available(OSX 10.12.2, *) {
18+
TouchBarController.shared.setupControlStripPresence()
19+
} else {
20+
// Fallback on earlier versions
21+
}
1822
// Insert code here to initialize your application
1923
}
2024

MTMR/TouchBarController.swift

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,32 +8,33 @@
88

99
import Cocoa
1010

11+
@available(OSX 10.12.2, *)
1112
class TouchBarController: NSObject, NSTouchBarDelegate {
1213

1314
static let shared = TouchBarController()
14-
15+
1516
let touchBar = NSTouchBar()
16-
17+
1718
var timer = Timer()
1819
var timeButton: NSButton = NSButton()
19-
20+
2021
private override init() {
2122
super.init()
2223
touchBar.delegate = self
2324
touchBar.defaultItemIdentifiers = [
2425
.escButton,
2526
.dismissButton,
26-
27+
2728
.brightDown,
2829
.brightUp,
29-
30+
3031
.prev,
3132
.play,
3233
.next,
33-
34+
3435
.sleep,
3536
.weather,
36-
37+
3738
.volumeDown,
3839
.volumeUp,
3940
.battery,
@@ -50,19 +51,19 @@ class TouchBarController: NSObject, NSTouchBarDelegate {
5051
DFRElementSetControlStripPresenceForIdentifier(.controlStripItem, true)
5152
timer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(self.updateTime), userInfo: nil, repeats: true)
5253
}
53-
54+
5455
func updateControlStripPresence() {
5556
DFRElementSetControlStripPresenceForIdentifier(.controlStripItem, true)
5657
}
57-
58+
5859
@objc private func presentTouchBar() {
5960
NSTouchBar.presentSystemModalFunctionBar(touchBar, placement: 1, systemTrayItemIdentifier: .controlStripItem)
6061
}
61-
62+
6263
@objc private func dismissTouchBar() {
6364
NSTouchBar.minimizeSystemModalFunctionBar(touchBar)
6465
}
65-
66+
6667
func touchBar(_ touchBar: NSTouchBar, makeItemForIdentifier identifier: NSTouchBarItem.Identifier) -> NSTouchBarItem? {
6768
switch identifier {
6869
case .escButton:
@@ -73,7 +74,7 @@ class TouchBarController: NSObject, NSTouchBarDelegate {
7374
let item = NSCustomTouchBarItem(identifier: identifier)
7475
item.view = NSButton(title: "exit", target: self, action: #selector(dismissTouchBar))
7576
return item
76-
77+
7778
case .brightUp:
7879
let item = NSCustomTouchBarItem(identifier: identifier)
7980
item.view = NSButton(title: "🔆", target: self, action: #selector(handleBrightUp))
@@ -91,7 +92,7 @@ class TouchBarController: NSObject, NSTouchBarDelegate {
9192
let item = NSCustomTouchBarItem(identifier: identifier)
9293
item.view = NSButton(title: "🔊", target: self, action: #selector(handleVolumeUp))
9394
return item
94-
95+
9596
case .prev:
9697
let item = NSCustomTouchBarItem(identifier: identifier)
9798
item.view = NSButton(title: "", target: self, action: #selector(handlePrev))
@@ -104,69 +105,69 @@ class TouchBarController: NSObject, NSTouchBarDelegate {
104105
let item = NSCustomTouchBarItem(identifier: identifier)
105106
item.view = NSButton(title: "", target: self, action: #selector(handleNext))
106107
return item
107-
108+
108109
case .time:
109110
let item = NSCustomTouchBarItem(identifier: identifier)
110111
timeButton = NSButton(title: self.getCurrentTime(), target: self, action: nil)
111112
item.view = timeButton
112113
return item
113-
114+
114115
default:
115116
return nil
116117
}
117118
}
118-
119+
119120
func getCurrentTime() -> String {
120121
let date = Date()
121122
let dateFormatter = DateFormatter()
122123
dateFormatter.setLocalizedDateFormatFromTemplate("HH:mm")
123124
let timestamp = dateFormatter.string(from: date)
124125
return timestamp
125126
}
126-
127+
127128
@objc func updateTime() {
128129
timeButton.title = getCurrentTime()
129130
}
130-
131+
131132
@objc func handleEsc() {
132133
let sender = ESCKeyPress()
133134
sender.send()
134135
}
135-
136+
136137
@objc func handleVolumeUp() {
137138
HIDPostAuxKey(Int(NX_KEYTYPE_SOUND_UP))
138139
}
139-
140+
140141
@objc func handleVolumeDown() {
141142
HIDPostAuxKey(Int(NX_KEYTYPE_SOUND_DOWN))
142143
}
143-
144+
144145
@objc func handleBrightDown() {
145146
// HIDPostAuxKey(Int(NX_KEYTYPE_BRIGHTNESS_DOWN))
146-
147+
147148
let sender = BrightnessUpPress()
148149
sender.send()
149150
}
150-
151+
151152
@objc func handleBrightUp() {
152153
// HIDPostAuxKey(Int(NX_KEYTYPE_BRIGHTNESS_UP))
153154

154155
let sender = BrightnessDownPress()
155156
sender.send()
156157
}
157-
158+
158159
@objc func handlePrev() {
159160
HIDPostAuxKey(Int(NX_KEYTYPE_PREVIOUS))
160161
}
161-
162+
162163
@objc func handlePlay() {
163164
HIDPostAuxKey(Int(NX_KEYTYPE_PLAY))
164165
}
165-
166+
166167
@objc func handleNext() {
167168
HIDPostAuxKey(Int(NX_KEYTYPE_NEXT))
168169
}
169-
170+
170171
// func getBattery() {
171172
// var error: NSDictionary?
172173
// if let scriptObject = NSAppleScript(source: <#T##String#>) {

MTMR/TouchBarItems.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import Cocoa
1010

11+
@available(OSX 10.12.2, *)
1112
extension NSTouchBarItem.Identifier {
1213
static let escButton = NSTouchBarItem.Identifier("com.toxblh.mtmr.escButton")
1314
static let dismissButton = NSTouchBarItem.Identifier("com.toxblh.mtmr.dismissButton")

0 commit comments

Comments
 (0)