Filesystem monitor and refactor.

This commit is contained in:
2025-02-06 17:03:16 -08:00
parent 6557993214
commit 5ed67e0cef
15 changed files with 777 additions and 481 deletions

View File

@@ -6,9 +6,12 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate {
let fileManager = FileManager.default
let window = PopoverPanel(viewController: SearchViewController())
let aboutWindow = MenulessWindow(viewController: AboutViewController())
func applicationDidFinishLaunching(_ notification: Notification) {
PathManager.shared.rebuildIndex()
aboutWindow.level = .statusBar
PathManager.shared.updateIndex()
window.delegate = self
@@ -30,19 +33,15 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate {
}
HotKeyManager.shared.enable()
if let code =
UserDefaults.standard.object(forKey: "keyCode") as? Int,
let mods =
UserDefaults.standard.object(forKey: "keyModifiers") as? Int
if let code = UserDefaults.standard.object(forKey: "keyCode") as? Int,
let mods = UserDefaults.standard.object(forKey: "keyModifiers") as? Int
{
HotKeyManager.shared.registerHotKey(key: code,
modifiers: mods)
HotKeyManager.shared.registerHotKey(key: code, modifiers: mods)
} else {
// NOTE: This is the default shortcut. If you want to change
// it, do not forget to change it in other files
// (SettingsViewController).
HotKeyManager.shared.registerHotKey(key: kVK_Space,
modifiers: optionKey)
HotKeyManager.shared.registerHotKey(key: kVK_Space, modifiers: optionKey)
}
}
@@ -52,9 +51,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate {
}
}
func applicationShouldHandleReopen(_ sender: NSApplication,
hasVisibleWindows: Bool) -> Bool
{
func applicationShouldHandleReopen(_ sender: NSApplication, hasVisibleWindows: Bool) -> Bool {
if !window.isKeyWindow {
window.makeKeyAndOrderFront(nil)
}
@@ -79,4 +76,49 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate {
return false
}
}
public func showAboutWindow() {
NSApplication.shared.activate(ignoringOtherApps: true)
aboutWindow.makeKeyAndOrderFront(nil)
}
// NOTE: This function is triggered by DirMonitor.
public func fsEventTriggered(_ path: String, _ flags: Int) {
var shouldReload = false
print("PATH: \(path)")
// if containsFlags(key: kFSEventStreamEventFlagNone, in: flags) {
// }
// if containsFlags(key: kFSEventStreamEventFlagRootChanged, in: flags) {
// }
// if containsFlags(key: kFSEventStreamEventFlagMustScanSubDirs, in: flags) {
// }
// if containsFlags(key: kFSEventStreamEventFlagItemInodeMetaMod, in: flags) {
// }
if containsFlags(key: kFSEventStreamEventFlagItemCreated, in: flags) {
print(" CREATED")
shouldReload = true
}
if containsFlags(key: kFSEventStreamEventFlagItemRemoved, in: flags) {
print(" REMOVED")
shouldReload = true
}
if containsFlags(key: kFSEventStreamEventFlagItemCloned, in: flags) {
print(" CLONED")
shouldReload = true
}
if containsFlags(key: kFSEventStreamEventFlagItemRenamed, in: flags) {
print(" RENAMED")
shouldReload = true
}
// TODO: This should also trigger SearchViewController's search re-index.
if shouldReload {
for dir in PathManager.shared.paths {
if path.hasPrefix(dir.key) {
PathManager.shared.rebuildIndex(at: dir.key)
}
}
PathManager.shared.refreshFilesystemWatchers()
}
}
}