|
@@ -56,7 +56,7 @@ public class FsWatcher: CAPPlugin, PollingWatcherDelegate {
|
|
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
|
|
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
|
|
self.notifyListeners("watcher", data: ["event": "unlink",
|
|
self.notifyListeners("watcher", data: ["event": "unlink",
|
|
"dir": baseUrl.description as Any,
|
|
"dir": baseUrl.description as Any,
|
|
- "path": url.description
|
|
|
|
|
|
+ "path": url.relativePath(from: baseUrl)?.precomposedStringWithCanonicalMapping as Any
|
|
])
|
|
])
|
|
}
|
|
}
|
|
case .Add, .Change:
|
|
case .Add, .Change:
|
|
@@ -173,11 +173,11 @@ public class PollingWatcher {
|
|
public init?(at: URL) {
|
|
public init?(at: URL) {
|
|
url = at
|
|
url = at
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
public func start() {
|
|
public func start() {
|
|
-
|
|
|
|
|
|
+
|
|
self.tick(notify: false)
|
|
self.tick(notify: false)
|
|
-
|
|
|
|
|
|
+
|
|
let queue = DispatchQueue(label: Bundle.main.bundleIdentifier! + ".timer")
|
|
let queue = DispatchQueue(label: Bundle.main.bundleIdentifier! + ".timer")
|
|
timer = DispatchSource.makeTimerSource(queue: queue)
|
|
timer = DispatchSource.makeTimerSource(queue: queue)
|
|
timer!.setEventHandler(qos: .background, flags: []) { [weak self] in
|
|
timer!.setEventHandler(qos: .background, flags: []) { [weak self] in
|
|
@@ -278,10 +278,18 @@ extension URL {
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ // NOTE: standardizedFileURL will remove `/private` prefix
|
|
|
|
+ // If the file is not exist, it won't remove the prefix.
|
|
|
|
+
|
|
// Remove/replace "." and "..", make paths absolute:
|
|
// Remove/replace "." and "..", make paths absolute:
|
|
- let destComponents = self.standardizedFileURL.pathComponents
|
|
|
|
|
|
+ var destComponents = self.standardizedFileURL.pathComponents
|
|
let baseComponents = base.standardizedFileURL.pathComponents
|
|
let baseComponents = base.standardizedFileURL.pathComponents
|
|
|
|
|
|
|
|
+ // replace "private" when needed
|
|
|
|
+ if destComponents.count > 1 && destComponents[1] == "private" && baseComponents.count > 1 && baseComponents[1] != "private" {
|
|
|
|
+ destComponents.remove(at: 1)
|
|
|
|
+ }
|
|
|
|
+
|
|
// Find number of common path components:
|
|
// Find number of common path components:
|
|
var i = 0
|
|
var i = 0
|
|
while i < destComponents.count && i < baseComponents.count
|
|
while i < destComponents.count && i < baseComponents.count
|