|
| 1 | +import path from "path" |
| 2 | +import os from "os" |
| 3 | + |
| 4 | +const home = os.homedir() |
| 5 | + |
| 6 | +// macOS directories that trigger TCC (Transparency, Consent, and Control) |
| 7 | +// permission prompts when accessed by a non-sandboxed process. |
| 8 | +const DARWIN_HOME = [ |
| 9 | + // Media |
| 10 | + "Music", |
| 11 | + "Pictures", |
| 12 | + "Movies", |
| 13 | + // User-managed folders synced via iCloud / subject to TCC |
| 14 | + "Downloads", |
| 15 | + "Desktop", |
| 16 | + "Documents", |
| 17 | + // Other system-managed |
| 18 | + "Public", |
| 19 | + "Applications", |
| 20 | + "Library", |
| 21 | +] |
| 22 | + |
| 23 | +const DARWIN_LIBRARY = [ |
| 24 | + "Application Support/AddressBook", |
| 25 | + "Calendars", |
| 26 | + "Mail", |
| 27 | + "Messages", |
| 28 | + "Safari", |
| 29 | + "Cookies", |
| 30 | + "Application Support/com.apple.TCC", |
| 31 | + "PersonalizationPortrait", |
| 32 | + "Metadata/CoreSpotlight", |
| 33 | + "Suggestions", |
| 34 | +] |
| 35 | + |
| 36 | +const DARWIN_ROOT = ["/.DocumentRevisions-V100", "/.Spotlight-V100", "/.Trashes", "/.fseventsd"] |
| 37 | + |
| 38 | +const WIN32_HOME = ["AppData", "Downloads", "Desktop", "Documents", "Pictures", "Music", "Videos", "OneDrive"] |
| 39 | + |
| 40 | +export namespace Protected { |
| 41 | + /** Directory basenames to skip when scanning the home directory. */ |
| 42 | + export function names(): ReadonlySet<string> { |
| 43 | + if (process.platform === "darwin") return new Set(DARWIN_HOME) |
| 44 | + if (process.platform === "win32") return new Set(WIN32_HOME) |
| 45 | + return new Set() |
| 46 | + } |
| 47 | + |
| 48 | + /** Absolute paths that should never be watched, stated, or scanned. */ |
| 49 | + export function paths(): string[] { |
| 50 | + if (process.platform === "darwin") |
| 51 | + return [ |
| 52 | + ...DARWIN_HOME.map((n) => path.join(home, n)), |
| 53 | + ...DARWIN_LIBRARY.map((n) => path.join(home, "Library", n)), |
| 54 | + ...DARWIN_ROOT, |
| 55 | + ] |
| 56 | + if (process.platform === "win32") return WIN32_HOME.map((n) => path.join(home, n)) |
| 57 | + return [] |
| 58 | + } |
| 59 | +} |
0 commit comments