Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 10 additions & 18 deletions FinderSyncExt/FinderSyncExt.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,25 +71,17 @@ class FinderSyncExt: FIFinderSync, @unchecked Sendable {

// MARK: - Directory Observing

/// 设置监听目录
/// 设置监听目录(全盘监听)
///
/// Observing "/" covers every reachable folder — /Users, /Applications,
/// /opt, /tmp, external and network volumes (mounted under /Volumes) —
/// which is what the original per-path list intended but missed for
/// anything on the system volume outside /Users. FileProvider-backed
/// locations (iCloud Drive, synced Desktop & Documents) still get no
/// FinderSync menus; that is a macOS restriction on all FinderSync
/// extensions, not something an observation URL can change.
private func setupObservingDirectories() {
var directories: Set<URL> = []

// 添加 /Users/ 目录
if let usersDir = URL(string: "file:///Users/") {
directories.insert(usersDir)
}

// 添加外接磁盘目录
let volumns = FileManager.default.mountedVolumeURLs(
includingResourceValuesForKeys: nil,
options: .skipHiddenVolumes
) ?? []

for volume in volumns.dropFirst() { // dropFirst 跳过系统盘
directories.insert(volume)
}

let directories: Set<URL> = [URL(fileURLWithPath: "/")]
FIFinderSyncController.default().directoryURLs = directories
logger.info("Observing directories: \(directories.map { $0.path })")
}
Expand Down
25 changes: 13 additions & 12 deletions RClick/Shared/PermissionChecker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,16 @@ public class PermissionChecker {

/// 需要 FDA 才能访问的检测路径
/// 每个路径下的文件/子目录只有开启了 FDA 才能被读取
///
/// Deliberately NOT ~/Library/Mail, Messages or Safari: those are other
/// apps' data containers, and on macOS 15+ merely attempting to read them
/// fires the TCC "App Data" consent ("RClick" would like to access data
/// from other apps) every time the app launches. The TCC store below is
/// gated by Full Disk Access itself (kTCCServiceSystemPolicyAllFiles),
/// which macOS denies *silently* — an accurate FDA probe with no prompt.
private static let protectedTestPaths: [(path: String, description: String)] = [
("/Library/Application Support", "System Application Support"),
("/Library/Logs", "System Logs"),
(NSString(string: "~/Library/Mail").expandingTildeInPath, "User Mail"),
(NSString(string: "~/Library/Messages").expandingTildeInPath, "User Messages"),
(NSString(string: "~/Library/Safari").expandingTildeInPath, "User Safari"),
(NSString(string: "~/Library/Application Support/com.apple.TCC").expandingTildeInPath,
"User TCC store"),
]

/// 检测是否拥有完全磁盘访问权限
Expand All @@ -57,13 +61,10 @@ public class PermissionChecker {
return false
}

// 使用 POSIX access() 检测实际文件系统权限
let result = url.path.withCString { access($0, R_OK) }
if result == 0 {
return true
}

// access() 失败时,回退到 FileManager 方式(有些情况下 access 也会返回错误)
// No POSIX access() fast path here: the probe directory is owned by
// the current user, so access(R_OK) succeeds on POSIX permissions
// alone and would report FDA as granted when it is not. TCC is only
// enforced on the actual read attempt below.
do {
// 不用 .skipsHiddenFiles,避免空目录误判
let _ = try FileManager.default.contentsOfDirectory(
Expand Down
Loading