Files
sing-box-for-apple/Library/Shared/FilePath.swift
T
世界 81d6827334 Refactor to eliminate hardcoded identifiers
Read package identifier and app group ID from Info.plist at runtime
via AppConfiguration. This enables SFM.System to use TeamID-prefixed
app group format required by macOS Sequoia, fixing the privacy prompt
when accessing app group data.
2026-01-03 02:46:52 +08:00

54 lines
1.9 KiB
Swift

import Foundation
public enum FilePath {
public static let packageName = AppConfiguration.packageName
public static let groupName = AppConfiguration.appGroupID
private static let defaultSharedDirectory: URL! = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: groupName)
#if os(iOS)
public static let sharedDirectory = defaultSharedDirectory!
#elseif os(tvOS)
public static let sharedDirectory = defaultSharedDirectory
.appendingPathComponent("Library", isDirectory: true)
.appendingPathComponent("Caches", isDirectory: true)
#elseif os(macOS)
public static var sharedDirectory: URL! = defaultSharedDirectory
#endif
#if os(iOS)
public static let cacheDirectory = sharedDirectory
.appendingPathComponent("Library", isDirectory: true)
.appendingPathComponent("Caches", isDirectory: true)
#elseif os(tvOS)
public static let cacheDirectory = sharedDirectory
#elseif os(macOS)
public static var cacheDirectory: URL {
sharedDirectory
.appendingPathComponent("Library", isDirectory: true)
.appendingPathComponent("Caches", isDirectory: true)
}
#endif
#if os(macOS)
public static var workingDirectory: URL {
cacheDirectory.appendingPathComponent("Working", isDirectory: true)
}
#else
public static let workingDirectory = cacheDirectory.appendingPathComponent("Working", isDirectory: true)
#endif
public static var iCloudDirectory = FileManager.default.url(forUbiquityContainerIdentifier: nil)?.appendingPathComponent("Documents", isDirectory: true) ?? URL(string: "stub")!
}
public extension URL {
var fileName: String {
var path = relativePath
if let index = path.lastIndex(of: "/") {
path = String(path[path.index(index, offsetBy: 1)...])
}
return path
}
}