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

exit touchbar implemented

This commit is contained in:
Serg 2018-04-10 17:50:34 +07:00
parent 1c45ca13a3
commit c0401ce83d
3 changed files with 5 additions and 9 deletions

View File

@ -39,6 +39,7 @@ class SupportedTypesHolder {
typealias ParametersDecoder = (Decoder) throws ->(item: ItemType, action: ActionType) typealias ParametersDecoder = (Decoder) throws ->(item: ItemType, action: ActionType)
private var supportedTypes: [String: ParametersDecoder] = [ private var supportedTypes: [String: ParametersDecoder] = [
"brightnessUp": { _ in return (item: .staticButton(title: "🔆"), action: .keyPress(keycode: 113)) }, "brightnessUp": { _ in return (item: .staticButton(title: "🔆"), action: .keyPress(keycode: 113)) },
"exitTouchbar": { _ in return (item: .staticButton(title: "exit"), action: .exitTouchbar) },
] ]
static let sharedInstance = SupportedTypesHolder() static let sharedInstance = SupportedTypesHolder()
@ -65,7 +66,7 @@ enum ItemType: Decodable {
case refreshInterval case refreshInterval
} }
private enum ItemTypeRaw: String, Decodable { enum ItemTypeRaw: String, Decodable {
case staticButton case staticButton
case appleScriptTitledButton case appleScriptTitledButton
} }
@ -90,6 +91,7 @@ enum ActionType: Decodable {
case hidKey(keycode: Int) case hidKey(keycode: Int)
case keyPress(keycode: Int) case keyPress(keycode: Int)
case appleSctipt(source: String) case appleSctipt(source: String)
case exitTouchbar
private enum CodingKeys: String, CodingKey { private enum CodingKeys: String, CodingKey {
case action case action

View File

@ -99,17 +99,11 @@ class TouchBarController: NSObject, NSTouchBarDelegate {
return CustomButtonTouchBarItem(identifier: identifier, title: title, onTap: action) return CustomButtonTouchBarItem(identifier: identifier, title: title, onTap: action)
case .appleScriptTitledButton(source: let source, refreshInterval: let interval): case .appleScriptTitledButton(source: let source, refreshInterval: let interval):
return AppleScriptTouchBarItem(identifier: identifier, appleScript: source, interval: interval) return AppleScriptTouchBarItem(identifier: identifier, appleScript: source, interval: interval)
case .exitTouchbar:
return CustomButtonTouchBarItem(identifier: identifier, title: "exit", onTap: action)
} }
switch identifier { switch identifier {
case .escButton: case .escButton:
return CustomButtonTouchBarItem(identifier: identifier, title: "esc", key: ESCKeyPress()) return CustomButtonTouchBarItem(identifier: identifier, title: "esc", key: ESCKeyPress())
case .dismissButton:
let item = NSCustomTouchBarItem(identifier: identifier)
item.view = NSButton(title: "exit", target: self, action: #selector(dismissTouchBar))
return item
case .brightUp: case .brightUp:
return CustomButtonTouchBarItem(identifier: identifier, title: "🔆", key: BrightnessUpPress()) return CustomButtonTouchBarItem(identifier: identifier, title: "🔆", key: BrightnessUpPress())

View File

@ -1,4 +1,4 @@
[ [
{ "type": "brightnessUp" } { "type": "brightnessUp" },
{ "type": "exitTouchbar" },
] ]