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