mirror of
https://github.com/Toxblh/MTMR.git
synced 2026-01-11 17:38:38 +00:00
+ reload if default config changed (write event fired)
This commit is contained in:
parent
2fc9dbccd8
commit
3375308386
@ -11,6 +11,7 @@ import Cocoa
|
|||||||
@NSApplicationMain
|
@NSApplicationMain
|
||||||
class AppDelegate: NSObject, NSApplicationDelegate {
|
class AppDelegate: NSObject, NSApplicationDelegate {
|
||||||
let statusItem = NSStatusBar.system.statusItem(withLength:NSStatusItem.squareLength)
|
let statusItem = NSStatusBar.system.statusItem(withLength:NSStatusItem.squareLength)
|
||||||
|
private var fileSystemSource: DispatchSourceFileSystemObject?
|
||||||
|
|
||||||
func applicationDidFinishLaunching(_ aNotification: Notification) {
|
func applicationDidFinishLaunching(_ aNotification: Notification) {
|
||||||
TouchBarController.shared.setupControlStripPresence()
|
TouchBarController.shared.setupControlStripPresence()
|
||||||
@ -19,6 +20,8 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
|||||||
button.image = #imageLiteral(resourceName: "StatusImage")
|
button.image = #imageLiteral(resourceName: "StatusImage")
|
||||||
}
|
}
|
||||||
createMenu()
|
createMenu()
|
||||||
|
|
||||||
|
reloadOnDefaultConfigChanged()
|
||||||
}
|
}
|
||||||
|
|
||||||
func applicationWillTerminate(_ aNotification: Notification) {
|
func applicationWillTerminate(_ aNotification: Notification) {
|
||||||
@ -73,5 +76,25 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
|||||||
statusItem.menu = menu
|
statusItem.menu = menu
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func reloadOnDefaultConfigChanged() {
|
||||||
|
let file = NSURL.fileURL(withPath: NSSearchPathForDirectoriesInDomains(.applicationSupportDirectory, .userDomainMask, true).first!.appending("/MTMR/items.json"))
|
||||||
|
|
||||||
|
let fd = open(file.path, O_EVTONLY)
|
||||||
|
|
||||||
|
self.fileSystemSource = DispatchSource.makeFileSystemObjectSource(fileDescriptor: fd, eventMask: .write, queue: DispatchQueue(label: "DefaultConfigChanged"))
|
||||||
|
|
||||||
|
self.fileSystemSource?.setEventHandler(handler: {
|
||||||
|
print("Config changed, reloading...")
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
TouchBarController.shared.createAndUpdatePreset()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
self.fileSystemSource?.setCancelHandler(handler: {
|
||||||
|
close(fd)
|
||||||
|
})
|
||||||
|
|
||||||
|
self.fileSystemSource?.resume()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user