diff --git a/MTMR/AppDelegate.swift b/MTMR/AppDelegate.swift index 4af19f7..4a9e721 100644 --- a/MTMR/AppDelegate.swift +++ b/MTMR/AppDelegate.swift @@ -83,6 +83,7 @@ class AppDelegate: NSObject, NSApplicationDelegate { let jsonData = path.fileData let jsonItems = jsonData?.barItemDefinitions() ?? [BarItemDefinition(type: .staticButton(title: "bad preset"), action: .none, longAction: .none, additionalParameters: [:])] + TouchBarController.shared.touchbarNeedRefresh = true; TouchBarController.shared.createAndUpdatePreset(newJsonItems: jsonItems) } } @@ -113,6 +114,7 @@ class AppDelegate: NSObject, NSApplicationDelegate { let jsonData = file.path.fileData let jsonItems = jsonData?.barItemDefinitions() ?? [BarItemDefinition(type: .staticButton(title: "bad preset"), action: .none, longAction: .none, additionalParameters: [:])] + TouchBarController.shared.touchbarNeedRefresh = true; TouchBarController.shared.createAndUpdatePreset(newJsonItems: jsonItems) } }) diff --git a/MTMR/TouchBarController.swift b/MTMR/TouchBarController.swift index 08f2b89..541536c 100644 --- a/MTMR/TouchBarController.swift +++ b/MTMR/TouchBarController.swift @@ -75,7 +75,7 @@ class TouchBarController: NSObject, NSTouchBarDelegate { } } - var touchbarHidden: Bool = true + var touchbarNeedRefresh: Bool = true var blacklistAppIdentifiers: [String] = [] var frontmostApplicationIdentifier: String? { @@ -90,7 +90,7 @@ class TouchBarController: NSObject, NSTouchBarDelegate { SupportedTypesHolder.sharedInstance.register(typename: "exitTouchbar", item: .staticButton(title: "exit"), action: .custom(closure: { [weak self] in self?.dismissTouchBar()}), longAction: .none) SupportedTypesHolder.sharedInstance.register(typename: "close") { _ in - return (item: .staticButton(title: ""), action: .custom(closure: { [weak self] in self?.touchbarHidden = true; self?.createAndUpdatePreset() }), longAction: .none, parameters: [.width: .width(30), .image: .image(source: (NSImage(named: .stopProgressFreestandingTemplate))!)]) + return (item: .staticButton(title: ""), action: .custom(closure: { [weak self] in self?.touchbarNeedRefresh = true; self?.createAndUpdatePreset() }), longAction: .none, parameters: [.width: .width(30), .image: .image(source: (NSImage(named: .stopProgressFreestandingTemplate))!)]) } if let blackListed = UserDefaults.standard.stringArray(forKey: "com.toxblh.mtmr.blackListedApps") { @@ -146,10 +146,10 @@ class TouchBarController: NSObject, NSTouchBarDelegate { func updateActiveApp() { if self.blacklistAppIdentifiers.index(of: self.frontmostApplicationIdentifier!) != nil { DFRElementSetControlStripPresenceForIdentifier(.controlStripItem, false) - self.touchbarHidden = true + self.touchbarNeedRefresh = true } else { presentTouchBar() - self.touchbarHidden = false + self.touchbarNeedRefresh = false } } @@ -206,7 +206,7 @@ class TouchBarController: NSObject, NSTouchBarDelegate { } @objc private func presentTouchBar() { - if touchbarHidden { + if touchbarNeedRefresh { if self.controlStripState { NSTouchBar.presentSystemModalFunctionBar(touchBar, systemTrayItemIdentifier: .controlStripItem) } else {