mirror of
https://github.com/Toxblh/MTMR.git
synced 2026-01-10 17:08:39 +00:00
Remove "Reload Preset" and fix reloading preset
This commit is contained in:
parent
6674b5aef7
commit
42d3d29e0d
@ -28,7 +28,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
||||
|
||||
}
|
||||
|
||||
@objc func openPrefereces(_ sender: Any?) {
|
||||
@objc func openPreferences(_ sender: Any?) {
|
||||
let task = Process()
|
||||
let appSupportDirectory = NSSearchPathForDirectoriesInDomains(.applicationSupportDirectory, .userDomainMask, true).first!.appending("/MTMR")
|
||||
let presetPath = appSupportDirectory.appending("/items.json")
|
||||
@ -37,9 +37,9 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
||||
task.launch()
|
||||
}
|
||||
|
||||
@objc func updatePreset(_ sender: Any?) {
|
||||
TouchBarController.shared.createAndUpdatePreset()
|
||||
}
|
||||
// @objc func updatePreset(_ sender: Any?) {
|
||||
// TouchBarController.shared.createAndUpdatePreset()
|
||||
// }
|
||||
|
||||
@objc func toggleControlStrip(_ sender: Any?) {
|
||||
TouchBarController.shared.controlStripState = !TouchBarController.shared.controlStripState
|
||||
@ -83,15 +83,15 @@ 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.createAndUpdatePreset(jsonItems: jsonItems)
|
||||
TouchBarController.shared.createAndUpdatePreset(newJsonItems: jsonItems)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func createMenu() {
|
||||
let menu = NSMenu()
|
||||
menu.addItem(withTitle: "Preferences", action: #selector(openPrefereces(_:)), keyEquivalent: ",")
|
||||
menu.addItem(withTitle: "Reload Preset", action: #selector(updatePreset(_:)), keyEquivalent: "r")
|
||||
menu.addItem(withTitle: "Preferences", action: #selector(openPreferences(_:)), keyEquivalent: ",")
|
||||
// menu.addItem(withTitle: "Reload Preset", action: #selector(updatePreset(_:)), keyEquivalent: "r")
|
||||
menu.addItem(withTitle: "Open Preset", action: #selector(openPreset(_:)), keyEquivalent: "O")
|
||||
menu.addItem(withTitle: TouchBarController.shared.controlStripState ? "Hide Control Strip" : "Show Control Strip" , action: #selector(toggleControlStrip(_:)), keyEquivalent: "T")
|
||||
menu.addItem(withTitle: "Toggle blackList current app" , action: #selector(toggleBlackListedApp(_:)), keyEquivalent: "B")
|
||||
@ -110,7 +110,10 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
||||
self.fileSystemSource?.setEventHandler(handler: {
|
||||
print("Config changed, reloading...")
|
||||
DispatchQueue.main.async {
|
||||
TouchBarController.shared.createAndUpdatePreset()
|
||||
let jsonData = file.path.fileData
|
||||
let jsonItems = jsonData?.barItemDefinitions() ?? [BarItemDefinition(type: .staticButton(title: "bad preset"), action: .none, longAction: .none, additionalParameters: [:])]
|
||||
|
||||
TouchBarController.shared.createAndUpdatePreset(newJsonItems: jsonItems)
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
@ -54,6 +54,7 @@ class TouchBarController: NSObject, NSTouchBarDelegate {
|
||||
|
||||
var touchBar: NSTouchBar!
|
||||
|
||||
var jsonItems: [BarItemDefinition]?
|
||||
var itemDefinitions: [NSTouchBarItem.Identifier: BarItemDefinition] = [:]
|
||||
var items: [NSTouchBarItem.Identifier: NSTouchBarItem] = [:]
|
||||
var leftIdentifiers: [NSTouchBarItem.Identifier] = []
|
||||
@ -95,22 +96,25 @@ class TouchBarController: NSObject, NSTouchBarDelegate {
|
||||
createAndUpdatePreset()
|
||||
}
|
||||
|
||||
func createAndUpdatePreset(jsonItems: [BarItemDefinition]? = nil) {
|
||||
func createAndUpdatePreset(newJsonItems: [BarItemDefinition]? = nil) {
|
||||
if let oldBar = self.touchBar {
|
||||
NSTouchBar.minimizeSystemModalFunctionBar(oldBar)
|
||||
}
|
||||
self.touchBar = NSTouchBar()
|
||||
var jsonItems = jsonItems
|
||||
if (newJsonItems != nil) {
|
||||
self.jsonItems = newJsonItems
|
||||
}
|
||||
self.itemDefinitions = [:]
|
||||
self.items = [:]
|
||||
self.leftIdentifiers = []
|
||||
self.centerItems = []
|
||||
self.rightIdentifiers = []
|
||||
|
||||
if (jsonItems == nil) {
|
||||
jsonItems = readConfig()
|
||||
if (self.jsonItems == nil) {
|
||||
self.jsonItems = readConfig()
|
||||
}
|
||||
loadItemDefinitions(jsonItems: jsonItems!)
|
||||
|
||||
loadItemDefinitions(jsonItems: self.jsonItems!)
|
||||
createItems()
|
||||
|
||||
centerItems = centerIdentifiers.compactMap({ (identifier) -> NSTouchBarItem? in
|
||||
|
||||
Loading…
Reference in New Issue
Block a user