Skip to content

armgit / peel

Public Imported from GitHub
0

Uninstall Mac apps with every file they leave behind, and see why each belongs. Free up space, fine-tune macOS, and set up Terminal.

Wait for Premiere, After Effects and Media Encoder before Adobe's cache

Țugui Dragoș0001f4d186f5
diff --git a/Packages/PeelCore/Sources/PeelCore/Developer/DeveloperCaches.swift b/Packages/PeelCore/Sources/PeelCore/Developer/DeveloperCaches.swift
index 852743e3..67f516eb 100644
--- a/Packages/PeelCore/Sources/PeelCore/Developer/DeveloperCaches.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Developer/DeveloperCaches.swift
@@ -91,6 +91,8 @@ public struct DeveloperEnvironment: Sendable, Hashable, Identifiable {
/// The apps that use these locations. The Developer page moves nothing while one of them is running.
public let appBundleIdentifiers: [String]
public let locations: [Location]
+ /// The beginnings of the identifiers of more apps that use these locations, each carrying its version after them.
+ public var appIdentifierPrefixes: [String] = []
public var total: SizeTotal {
SizeTotal(locations.map(\.size))
@@ -108,10 +110,15 @@ public struct DeveloperEnvironment: Sendable, Hashable, Identifiable {
/// when none runs. Nothing of the environment moves while one runs, from the app or `peel`: it writes in these
/// folders. Asked each time, since an app can be opened at any moment.
public var runningApp: String? {
- appBundleIdentifiers.lazy.compactMap { identifier in
+ let named = appBundleIdentifiers.lazy.compactMap { identifier in
NSRunningApplication.runningApplications(withBundleIdentifier: identifier)
.lazy.compactMap(\.localizedName).first
}.first
+ guard named == nil, !appIdentifierPrefixes.isEmpty else { return named }
+ return NSWorkspace.shared.runningApplications.first { running in
+ running.bundleIdentifier.map { identifier in appIdentifierPrefixes.contains(where: identifier.hasPrefix) }
+ ?? false
+ }?.localizedName
}
}
@@ -125,6 +132,8 @@ public enum DeveloperCaches {
/// The tool's own folder inside a folder its vendor shares with other products, such as
/// `Library/Caches/Google/AndroidStudio*`. Space leaves only that part of the vendor's folder to Developer.
var ownFolders: [String] = []
+ /// The beginnings of the identifiers of apps that carry their version in it (`com.adobe.PremierePro.25`).
+ var appIdentifierPrefixes: [String] = []
}
/// A folder a tool keeps, relative to the home folder or to the user's cache folder, and what it holds.
@@ -1127,10 +1136,13 @@ public enum DeveloperCaches {
Definition(id: "blender", name: "Blender", systemImage: "cube.transparent", appBundleIdentifiers: ["org.blenderfoundation.blender"], folders: [
Folder("Library/Caches/Blender", .cache, source: "https://projects.blender.org/blender/blender/src/commit/703834468bfa0464da39634f3cf346a078d5236c/source/blender/blenkernel/intern/appdir.cc#L228"),
]),
- Definition(id: "adobe", name: "Adobe Media Cache", systemImage: "play.rectangle", appBundleIdentifiers: [], folders: [
+ // Adobe's page asks to quit Premiere first, and Premiere, After Effects and Media Encoder share the cache. Two
+ // of them carry their version in their identifier, as their Info.plists give it (`com.adobe.PremierePro.25`,
+ // `com.adobe.ame.application.22`), so they are named by its beginning.
+ Definition(id: "adobe", name: "Adobe Media Cache", systemImage: "play.rectangle", appBundleIdentifiers: ["com.adobe.AfterEffects"], folders: [
Folder("Library/Application Support/Adobe/Common/Media Cache Files", .cache, source: "https://helpx.adobe.com/premiere/desktop/troubleshooting/media-issues/delete-media-cache-files-manually.html"),
Folder("Library/Application Support/Adobe/Common/Media Cache", .cache, source: "https://helpx.adobe.com/premiere/desktop/troubleshooting/media-issues/delete-media-cache-files-manually.html"),
- ]),
+ ], appIdentifierPrefixes: ["com.adobe.PremierePro.", "com.adobe.ame.application."]),
// Quantum computing. Everything else these SDKs write in the home folder is settings or an account
// token, so only these three folders are listed.
Definition(id: "dwave", name: "D-Wave Ocean", systemImage: "atom", appBundleIdentifiers: [], folders: [
@@ -1426,7 +1438,8 @@ public enum DeveloperCaches {
guard !folders.isEmpty else { return nil }
return Definition(
id: definition.id, name: definition.name, systemImage: definition.systemImage,
- appBundleIdentifiers: definition.appBundleIdentifiers, folders: folders
+ appBundleIdentifiers: definition.appBundleIdentifiers, folders: folders,
+ appIdentifierPrefixes: definition.appIdentifierPrefixes
)
}
return await scan(
@@ -1615,7 +1628,8 @@ public enum DeveloperCaches {
name: definition.name,
systemImage: definition.systemImage,
appBundleIdentifiers: definition.appBundleIdentifiers,
- locations: locations.sorted { SizeTotal([$0.size]) > SizeTotal([$1.size]) }
+ locations: locations.sorted { SizeTotal([$0.size]) > SizeTotal([$1.size]) },
+ appIdentifierPrefixes: definition.appIdentifierPrefixes
)
}
}
diff --git a/Packages/PeelCore/Sources/PeelCore/Leftovers/LeftoverMatcher.swift b/Packages/PeelCore/Sources/PeelCore/Leftovers/LeftoverMatcher.swift
index b1670d8a..c4e718c6 100644
--- a/Packages/PeelCore/Sources/PeelCore/Leftovers/LeftoverMatcher.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Leftovers/LeftoverMatcher.swift
@@ -43,7 +43,10 @@ struct LeftoverMatcher: Sendable {
let owners = others.filter { !$0.isACopy(of: target) }
return DeveloperCaches.definitions.flatMap { definition -> [(place: String, app: String)] in
let apps = Set(definition.appBundleIdentifiers.map { $0.lowercased() })
- guard let owner = owners.first(where: { $0.identifier.map(apps.contains) ?? false }) else { return [] }
+ let prefixes = definition.appIdentifierPrefixes.map { $0.lowercased() }
+ guard let owner = owners.first(where: { owner in
+ owner.identifier.map { apps.contains($0) || prefixes.contains(where: $0.hasPrefix) } ?? false
+ }) else { return [] }
return definition.folders.filter { $0.base == .home }.flatMap { folder in
PathPattern.expand(folder.path, home: home, from: .peel).map {
(PathPattern.comparablePath(of: $0), owner.reference)
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/DeveloperCachesTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/DeveloperCachesTests.swift
index 0a51391f..621e17a6 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/DeveloperCachesTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/DeveloperCachesTests.swift
@@ -78,6 +78,16 @@ struct DeveloperCachesTests {
#expect(environment(["org.example.closed"]).runningApp == nil)
}
+ @Test func namesAnAppThatCarriesItsVersionInItsIdentifier() throws {
+ var tools = DeveloperEnvironment(id: "tools", name: "Tools", systemImage: "hammer", appBundleIdentifiers: [], locations: [])
+ tools.appIdentifierPrefixes = ["com.apple.find"]
+ #expect(tools.runningApp == "Finder")
+ tools.appIdentifierPrefixes = ["org.example."]
+ #expect(tools.runningApp == nil)
+ let adobe = try #require(DeveloperCaches.definitions.first { $0.id == "adobe" })
+ #expect(adobe.appIdentifierPrefixes == ["com.adobe.PremierePro.", "com.adobe.ame.application."])
+ }
+
@Test func everyIntelliJIDEKeepsItsCachesWhileItRuns() throws {
let jetbrains = try #require(DeveloperCaches.definitions.first { $0.id == "jetbrains" })
let androidStudio = try #require(DeveloperCaches.definitions.first { $0.id == "androidstudio" })
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/LeftoverMatcherTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/LeftoverMatcherTests.swift
index ab2ae804..f42a3bcc 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/LeftoverMatcherTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/LeftoverMatcherTests.swift
@@ -723,4 +723,18 @@ struct LeftoverMatcherTests {
#expect(match("Cookies.binarycookies", in: .cookies, for: cookies) == nil)
#expect(match("Databases", in: .caches, for: databases)?.isRecommended == true)
}
+
+ @Test func anAppNamedByItsIdentifiersBeginningKeepsWhatDeveloperNamesForIt() throws {
+ let directory = try TemporaryDirectory()
+ try directory.directory("Library/Application Support/Adobe/Common/Media Cache Files")
+ let effects = app("com.adobe.AfterEffects", name: "After Effects")
+ let premiere = InstalledApp(
+ url: URL(filePath: "/Applications/Premiere.app"), bundleIdentifier: "com.adobe.PremierePro.25", name: "Premiere"
+ )
+ let matcher = LeftoverMatcher(app: effects, installedApps: [effects, premiere])
+
+ let places = matcher.placesOthersKeep(home: directory.url)
+
+ #expect(places.contains { $0.place.hasSuffix("Adobe/Common/Media Cache Files") && $0.app == "com.adobe.PremierePro.25" })
+ }
}