From 818c32b0eda3618e0cd604b2978aecdf8ae00f9a Mon Sep 17 00:00:00 2001 From: Toxblh Date: Mon, 16 Apr 2018 00:53:40 +0100 Subject: [PATCH] Reload preset from menu --- MTMR/AppDelegate.swift | 9 +++++++-- MTMR/TouchBarController.swift | 12 +++++++++++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/MTMR/AppDelegate.swift b/MTMR/AppDelegate.swift index e5e7926..c2ded9b 100644 --- a/MTMR/AppDelegate.swift +++ b/MTMR/AppDelegate.swift @@ -26,7 +26,7 @@ class AppDelegate: NSObject, NSApplicationDelegate { // Insert code here to tear down your application } - @objc func testFn(_ sender: Any?) { + @objc func openPrefereces(_ sender: Any?) { let task = Process() let appSupportDirectory = NSSearchPathForDirectoriesInDomains(.applicationSupportDirectory, .userDomainMask, true).first!.appending("/MTMR") let presetPath = appSupportDirectory.appending("/items.json") @@ -35,9 +35,14 @@ class AppDelegate: NSObject, NSApplicationDelegate { task.launch() } + @objc func updatePreset(_ sender: Any?) { + TouchBarController.shared.createAndUpdatePreset() + } + func createMenu() { let menu = NSMenu() - menu.addItem(withTitle: "Preferences", action: #selector(testFn(_:)), keyEquivalent: ",") + menu.addItem(withTitle: "Preferences", action: #selector(openPrefereces(_:)), keyEquivalent: ",") + menu.addItem(withTitle: "Reload Preset", action: #selector(updatePreset(_:)), keyEquivalent: "r") menu.addItem(NSMenuItem.separator()) menu.addItem(withTitle: "Quit", action: #selector(NSApplication.terminate(_:)), keyEquivalent: "q") statusItem.menu = menu diff --git a/MTMR/TouchBarController.swift b/MTMR/TouchBarController.swift index 1647f52..7b9ea30 100644 --- a/MTMR/TouchBarController.swift +++ b/MTMR/TouchBarController.swift @@ -55,12 +55,22 @@ class TouchBarController: NSObject, NSTouchBarDelegate { self?.dismissTouchBar() })) + createAndUpdatePreset() + } + + func createAndUpdatePreset() { + self.itemDefinitions = [:] + self.items = [:] + self.leftIdentifiers = [] + self.centerItems = [] + self.rightIdentifiers = [] + loadItemDefinitions() createItems() centerItems = self.itemDefinitions.compactMap { (identifier, definition) -> NSTouchBarItem? in return definition.align == .center ? items[identifier] : nil } - + touchBar.delegate = self touchBar.defaultItemIdentifiers = self.leftIdentifiers + [.centerScrollArea] + self.rightIdentifiers self.presentTouchBar()