Uninstall Mac apps with every file they leave behind, and see why each belongs. Free up space, fine-tune macOS, and set up Terminal.
Swift cache-cleanercleanerclideveloper-toolsdisk-cleanupdisk-spaceduplicate-finderhomebrewliquid-glassmac-cleanermacosmacos-appmacos-golden-gatemacos-tahoemacos-tweaksswiftswiftuiterminal-themesuninstalluninstaller
Stop reading the private privacy database on macOS 26 too
Țugui Dragoș28ac34d65fcb
diff --git a/Packages/PeelCore/Sources/PeelCore/Home/Access.swift b/Packages/PeelCore/Sources/PeelCore/Home/Access.swiftindex bc517b39..c3dafe6f 100644--- a/Packages/PeelCore/Sources/PeelCore/Home/Access.swift+++ b/Packages/PeelCore/Sources/PeelCore/Home/Access.swift@@ -120,19 +120,9 @@ public enum CommandLineTool {}}+/// App Management has no API, so only a removal shows whether Peel has it.public enum AppManagement {public static let settingsURL = URL(string: "x-apple.systempreferences:com.apple.preference.security?Privacy_AppBundles")!- static let service = "kTCCServiceSystemPolicyAppBundles"-- /// Reads the App Management decision from the TCC database, since macOS has no API for it. On macOS 27 and- /// later it returns unknown, because "Apps can no longer access the local TCC database directly" (Apple,- /// macOS 27 release notes, TCC deprecations). There, only a removal shows the answer.- @concurrent- public static func state(of client: String = Bundle.main.bundleIdentifier ?? "") async -> AccessState {- guard !client.isEmpty else { return .unknown }- if #available(macOS 27, *) { return .unknown }- return PrivacyDatabase.decision(on: service, for: client)- }/// What a removal shows about App Management, or nil when it shows nothing. An app bundle Peel moved means/// granted. A bundle macOS refused to move from a folder the user can write to, when nothing locks it, meansdiff --git a/Packages/PeelCore/Sources/PeelCore/Home/PrivacyDatabase.swift b/Packages/PeelCore/Sources/PeelCore/Home/PrivacyDatabase.swiftdeleted file mode 100644index 39032a6d..00000000--- a/Packages/PeelCore/Sources/PeelCore/Home/PrivacyDatabase.swift+++ /dev/null@@ -1,40 +0,0 @@-import Foundation-import SQLite3--/// Reads the user's TCC database, where macOS records privacy decisions. Only a process with Full Disk Access-/// can open it, so anything unreadable is unknown. It is opened read-only and never written. Its location and-/// table are not API, so its answer is only a hint: what a real removal shows takes precedence (`HomeModel`).-/// Rows are matched by bundle identifier alone, while macOS also checks the signature a permission was given to.-enum PrivacyDatabase {- static var userDatabase: String {- NSHomeDirectory() + "/Library/Application Support/com.apple.TCC/TCC.db"- }-- /// Returns the decision for `client` on `service`. An `auth_value` of 0 means denied and 2 means allowed.- /// Any other value, such as partial access, is unknown.- static func decision(on service: String, for client: String, in database: String = userDatabase) -> AccessState {- var handle: OpaquePointer?- guard sqlite3_open_v2(database, &handle, SQLITE_OPEN_READONLY, nil) == SQLITE_OK else {- sqlite3_close(handle)- return .unknown- }- defer { sqlite3_close(handle) }-- var statement: OpaquePointer?- let query = "SELECT auth_value FROM access WHERE service = ? AND client = ? AND client_type = 0"- guard sqlite3_prepare_v2(handle, query, -1, &statement, nil) == SQLITE_OK else { return .unknown }- defer { sqlite3_finalize(statement) }-- // `SQLITE_TRANSIENT`, which Swift can't import. SQLite copies the text, since the C strings Swift- // passes last only for the call.- let copied = unsafeBitCast(-1, to: (@convention(c) (UnsafeMutableRawPointer?) -> Void).self)- sqlite3_bind_text(statement, 1, service, -1, copied)- sqlite3_bind_text(statement, 2, client, -1, copied)- guard sqlite3_step(statement) == SQLITE_ROW else { return .unknown }- return switch sqlite3_column_int(statement, 0) {- case 0: .missing- case 2: .granted- default: .unknown- }- }-}diff --git a/Packages/PeelCore/Tests/PeelCoreTests/HomeTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/HomeTests.swiftindex ce9617d9..7022dc5d 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/HomeTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/HomeTests.swift@@ -1,5 +1,4 @@import Foundation-import SQLite3@testable import PeelCoreimport Testing@@ -184,59 +183,7 @@ struct AccessTests {}}-struct PrivacyDatabaseTests {- private func database(at url: URL, rows: [(service: String, client: String, type: Int32, auth: Int32)]) throws {- var handle: OpaquePointer?- try #require(- sqlite3_open_v2(url.path(percentEncoded: false), &handle, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, nil)- == SQLITE_OK- )- defer { sqlite3_close(handle) }- try #require(sqlite3_exec(handle, "CREATE TABLE access (service TEXT, client TEXT, client_type INTEGER, auth_value INTEGER)", nil, nil, nil) == SQLITE_OK)- for row in rows {- let insert = "INSERT INTO access VALUES ('\(row.service)', '\(row.client)', \(row.type), \(row.auth))"- try #require(sqlite3_exec(handle, insert, nil, nil, nil) == SQLITE_OK)- }- }-- private func decision(_ rows: [(service: String, client: String, type: Int32, auth: Int32)]) throws -> AccessState {- let directory = try TemporaryDirectory()- let url = directory.url.appending(path: "TCC.db")- try database(at: url, rows: rows)- return PrivacyDatabase.decision(on: AppManagement.service, for: "com.example.App", in: url.path(percentEncoded: false))- }-- @Test func readsTheDecisionMacOSWroteDown() throws {- #expect(try decision([(AppManagement.service, "com.example.App", 0, 2)]) == .granted)- #expect(try decision([(AppManagement.service, "com.example.App", 0, 0)]) == .missing)- }-- @Test func treatsPartialAccessAsNoAnswer() throws {- #expect(try decision([(AppManagement.service, "com.example.App", 0, 5)]) == .unknown)- }-- @Test func ignoresRowsThatAreAboutSomethingElse() throws {- #expect(try decision([]) == .unknown)- #expect(try decision([(AppManagement.service, "com.other.App", 0, 2)]) == .unknown)- #expect(try decision([("kTCCServiceSystemPolicyAllFiles", "com.example.App", 0, 2)]) == .unknown)- #expect(try decision([(AppManagement.service, "com.example.App", 1, 2)]) == .unknown)- }-- @Test func staysUnknownWhenTheDatabaseIsOutOfReach() throws {- let directory = try TemporaryDirectory()- let missing = directory.url.appending(path: "TCC.db").path(percentEncoded: false)- #expect(PrivacyDatabase.decision(on: AppManagement.service, for: "com.example.App", in: missing) == .unknown)-- let notADatabase = try directory.file("other.db", contents: Data("not a database".utf8))- #expect(- PrivacyDatabase.decision(- on: AppManagement.service,- for: "com.example.App",- in: notADatabase.path(percentEncoded: false)- ) == .unknown- )- }-+struct AppManagementTests {/// The root helper needs no permission of Peel's, so a bundle it moved proves nothing about App Management.@Test func aBundleTheHelperMovedProvesNothing() {let bundle = URL(filePath: "/Applications/Example.app", directoryHint: .isDirectory)diff --git a/Packages/PeelCore/Tests/PeelCoreTests/PrivateDatabaseTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/PrivateDatabaseTests.swiftnew file mode 100644index 00000000..8d305c04--- /dev/null+++ b/Packages/PeelCore/Tests/PeelCoreTests/PrivateDatabaseTests.swift@@ -0,0 +1,14 @@+import Foundation+import Testing++struct PrivateDatabaseTests {+ /// What macOS records about privacy is not API, and from macOS 27 apps can't read it: App Management is learned+ /// from what a removal shows, on every macOS.+ @Test func noCodeReadsThePrivacyDatabase() throws {+ let name = "com.apple." + "TCC"+ let readers = try LineLengthTests.swiftFiles().filter {+ try String(contentsOf: $0, encoding: .utf8).contains(name)+ }+ #expect(readers.isEmpty, "\(readers.map(\.lastPathComponent))")+ }+}diff --git a/Peel/Model/HomeModel.swift b/Peel/Model/HomeModel.swiftindex b5990dbf..14ef1c8e 100644--- a/Peel/Model/HomeModel.swift+++ b/Peel/Model/HomeModel.swift@@ -145,7 +145,6 @@ final class HomeModel {}}async let access = FullDiskAccess.state()- async let bundles = AppManagement.state()await helper.checkConnection()helperStanding = helper.standing@@ -158,14 +157,11 @@ final class HomeModel {let fullDisk = await accessneedsRelaunchForFullDiskAccess = fullDisk == .missing && hasOpenedFullDiskAccessSettings- let appBundles = await bundleslet opensAtLogin = await Self.opensAtLogin()states = [.fullDiskAccess: state(for: fullDisk),.helper: helperState,- .appManagement: state(- for: appManagementSeenThisLaunch ?? (appBundles == .unknown ? appManagement : appBundles)- ),+ .appManagement: state(for: appManagementSeenThisLaunch ?? appManagement),.notifications: notificationStatus == .authorized ? .on : .off,.finderExtension: isFinderExtensionEnabled ? .on : .off,.openAtLogin: opensAtLogin ? .on : .off,@@ -215,9 +211,8 @@ final class HomeModel {NSWorkspace.shared.open(FullDiskAccess.settingsURL)}- /// Opens the App Management settings and forgets the stored state. macOS has no API for this permission- /// and closes its database to apps from macOS 27, so a stored "off" that only a removal updates would- /// keep Home red after the user turns it on.+ /// Opens the App Management settings and forgets the stored state. macOS has no API for this permission, so a+ /// stored "off" that only a removal updates would keep Home red after the user turns it on.func openAppManagementSettings() {appManagementSeenThisLaunch = nilappManagement = .unknown