forked from gnachman/iTerm2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWorkingSet.swift
58 lines (50 loc) · 1.51 KB
/
WorkingSet.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
//
// WorkingSet.swift
// FileProvider
//
// Created by George Nachman on 6/9/22.
//
import Foundation
import FileProvider
import FileProviderService
actor WorkingSet {
private let remoteService: RemoteService
enum Kind {
case file // includes symlinks
case folder
}
struct Entry: Hashable {
let path: String
let kind: Kind
}
private(set) var entries = Set<Entry>()
init(remoteService: RemoteService) {
self.remoteService = remoteService
}
func addFile(_ path: String,
domain: NSFileProviderDomain) {
log("Add \(path) as file to working set")
entries.insert(Entry(path: path, kind: .file))
didChange(domain)
Task { await remoteService.subscribe([path]) }
}
func addFolder(_ path: String,
domain: NSFileProviderDomain) {
log("Add \(path) as folder to working set")
entries.insert(Entry(path: path, kind: .folder))
didChange(domain)
Task { await remoteService.subscribe([path]) }
}
private func didChange(_ domain: NSFileProviderDomain) {
Task {
await MainActor.run {
log("Signal working set enumerator")
NSFileProviderManager(for: domain)?.signalEnumerator(for: .workingSet) { error in
if let error = error {
log("Error when signaling enumerator for working set: \(error)")
}
}
}
}
}
}