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.

Make one Developer tool of every copy of an Electron app

Țugui Dragoș85aa630f1e95
diff --git a/Packages/PeelCore/Sources/PeelCore/Developer/DeveloperCaches.swift b/Packages/PeelCore/Sources/PeelCore/Developer/DeveloperCaches.swift
index e2be0de1..003ed100 100644
--- a/Packages/PeelCore/Sources/PeelCore/Developer/DeveloperCaches.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Developer/DeveloperCaches.swift
@@ -1469,16 +1469,27 @@ public enum DeveloperCaches {
let chromium = "https://github.com/chromium/chromium/blob/54cc36437b23cee8aaffa1289c8bc31bf2f520b9/"
let codeCache = chromium + "content/browser/storage_partition_impl.cc#L1587-L1595"
let exists = { (url: URL) in FileManager.default.fileExists(atPath: url.path(percentEncoded: false)) }
- return apps.compactMap { app in
+ // One tool for each folder of data, which waits for every copy of an app and every app keeping its data there.
+ var made: [(folder: String, definition: Definition)] = []
+ for app in apps {
guard let identifier = app.bundleIdentifier, let bundleName = app.bundleName,
!covered.contains(bundleName.lowercased()),
exists(app.url.appending(path: "Contents/Frameworks/Electron Framework.framework"))
- else { return nil }
+ else { continue }
let editor = vsCodeProductName(of: app)
let name = editor ?? bundleName
guard !name.isEmpty, !name.contains("/"), name != ".", name != "..", !covered.contains(name.lowercased())
- else { return nil }
- guard exists(home.appending(path: "Library/Application Support/\(name)/Local State")) else { return nil }
+ else { continue }
+ guard exists(home.appending(path: "Library/Application Support/\(name)/Local State")) else { continue }
+ if let index = made.firstIndex(where: { $0.folder == name.lowercased() }) {
+ let shared = made[index].definition
+ guard !shared.appBundleIdentifiers.contains(identifier) else { continue }
+ made[index].definition = Definition(
+ id: shared.id, name: shared.name, systemImage: shared.systemImage,
+ appBundleIdentifiers: shared.appBundleIdentifiers + [identifier], folders: shared.folders
+ )
+ continue
+ }
let data = "Library/Application Support/\(PathPattern.literal(name))"
// Each persistent session an app opens keeps the same caches in a folder of its own.
let partitions = "\(data)/Partitions/*"
@@ -1499,11 +1510,12 @@ public enum DeveloperCaches {
] + ["ShaderCache", "GrShaderCache", "GraphiteDawnCache", "GPUPersistentCache"].map {
Folder("\(data)/\($0)", .cache, source: electron + "electron_browser_client.cc#L1206-L1222")
} + (editor == nil ? [] : vsCodesOwnFolders(in: data))
- return Definition(
+ made.append((name.lowercased(), Definition(
id: "electron.\(identifier)", name: app.name, systemImage: "macwindow",
appBundleIdentifiers: [identifier], folders: folders
- )
+ )))
}
+ return made.map(\.definition)
}
/// `nameShort` in the app's `product.json`, the name VS Code keeps its data under.
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/DeveloperCachesTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/DeveloperCachesTests.swift
index 299df790..98bd7b5c 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/DeveloperCachesTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/DeveloperCachesTests.swift
@@ -283,6 +283,28 @@ struct DeveloperCachesTests {
#expect(chat.locations.map(\.url.lastPathComponent).sorted() == ["Cache", "GPUCache"])
}
+ @Test func makesOneToolOfEveryCopyOfAnElectronApp() throws {
+ let directory = try TemporaryDirectory()
+ let home = directory.url.appending(path: "home", directoryHint: .isDirectory)
+ let copy = { (place: String, identifier: String) throws -> InstalledApp in
+ try directory.directory("\(place)/Chat.app/Contents/Frameworks/Electron Framework.framework")
+ return InstalledApp(
+ url: directory.url.appending(path: "\(place)/Chat.app", directoryHint: .isDirectory),
+ bundleIdentifier: identifier, name: "Chat", bundleName: "Chat"
+ )
+ }
+ let apps = [
+ try copy("Applications", "org.example.chat"), try copy("home/Applications", "org.example.chat"),
+ try copy("Other", "org.example.chat-beta"),
+ ]
+ try directory.file("home/Library/Application Support/Chat/Local State")
+
+ let definitions = DeveloperCaches.electronDefinitions(for: apps, home: home)
+
+ #expect(definitions.map(\.id) == ["electron.org.example.chat"])
+ #expect(definitions.first?.appBundleIdentifiers == ["org.example.chat", "org.example.chat-beta"])
+ }
+
@Test func listsVSCodesOwnFoldersForAnEditorBuiltOnItAndNeverItsBackups() async throws {
let directory = try TemporaryDirectory()
let home = directory.url.appending(path: "home", directoryHint: .isDirectory)