From 651ddbef5c519315ff4e60816cb3ddcae8dcb872 Mon Sep 17 00:00:00 2001 From: Serg Date: Tue, 10 Apr 2018 17:57:51 +0700 Subject: [PATCH] escape button implemented --- MTMR/ItemsParsing.swift | 1 + MTMR/KeyPress.swift | 4 ---- MTMR/TouchBarController.swift | 5 +---- MTMR/defaultPreset.json | 1 + 4 files changed, 3 insertions(+), 8 deletions(-) diff --git a/MTMR/ItemsParsing.swift b/MTMR/ItemsParsing.swift index 4d021b6..7bc3e91 100644 --- a/MTMR/ItemsParsing.swift +++ b/MTMR/ItemsParsing.swift @@ -38,6 +38,7 @@ struct BarItemDefinition: Decodable { class SupportedTypesHolder { typealias ParametersDecoder = (Decoder) throws ->(item: ItemType, action: ActionType) private var supportedTypes: [String: ParametersDecoder] = [ + "escape": { _ in return (item: .staticButton(title: "esc"), action: .keyPress(keycode: 53)) }, "brightnessUp": { _ in return (item: .staticButton(title: "🔆"), action: .keyPress(keycode: 113)) }, "exitTouchbar": { _ in return (item: .staticButton(title: "exit"), action: .exitTouchbar) }, ] diff --git a/MTMR/KeyPress.swift b/MTMR/KeyPress.swift index 2e72323..f8bd4a1 100644 --- a/MTMR/KeyPress.swift +++ b/MTMR/KeyPress.swift @@ -29,10 +29,6 @@ extension KeyPress { } } -struct ESCKeyPress: KeyPress { - let keyCode: CGKeyCode = 53 -} - struct BrightnessUpPress: KeyPress { let keyCode: CGKeyCode = 113 } diff --git a/MTMR/TouchBarController.swift b/MTMR/TouchBarController.swift index 965fb8d..3df096e 100644 --- a/MTMR/TouchBarController.swift +++ b/MTMR/TouchBarController.swift @@ -40,7 +40,6 @@ class TouchBarController: NSObject, NSTouchBarDelegate { loadItems() touchBar.delegate = self - touchBar.defaultItemIdentifiers = Array(items.keys) self.presentTouchBar() } @@ -59,6 +58,7 @@ class TouchBarController: NSObject, NSTouchBarDelegate { let identifierString = item.type.identifierBase.appending(UUID().uuidString) let identifier = NSTouchBarItem.Identifier(identifierString) items[identifier] = item + touchBar.defaultItemIdentifiers += [identifier] } } @@ -103,9 +103,6 @@ class TouchBarController: NSObject, NSTouchBarDelegate { } switch identifier { - case .escButton: - return CustomButtonTouchBarItem(identifier: identifier, title: "esc", key: ESCKeyPress()) - case .brightUp: return CustomButtonTouchBarItem(identifier: identifier, title: "🔆", key: BrightnessUpPress()) case .brightDown: diff --git a/MTMR/defaultPreset.json b/MTMR/defaultPreset.json index 7b95cbe..23e8997 100644 --- a/MTMR/defaultPreset.json +++ b/MTMR/defaultPreset.json @@ -1,4 +1,5 @@ [ + { "type": "escape" }, { "type": "brightnessUp" }, { "type": "exitTouchbar" }, ]