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.

Developer lists the web caches of apps built on Electron

Țugui Dragoș94c08bad7405
diff --git a/Packages/PeelCore/Sources/PeelCore/Developer/DeveloperCaches.swift b/Packages/PeelCore/Sources/PeelCore/Developer/DeveloperCaches.swift
index f7b08497..c5987909 100644
--- a/Packages/PeelCore/Sources/PeelCore/Developer/DeveloperCaches.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Developer/DeveloperCaches.swift
@@ -733,7 +733,43 @@ public enum DeveloperCaches {
@concurrent
public static func scan(homeDirectory: URL = .homeDirectory, exclusions: Exclusions = .none) async -> [DeveloperEnvironment] {
- await scan(definitions, homeDirectory: homeDirectory, exclusions: exclusions)
+ let apps = await AppCatalog.installedApps()
+ let electron = electronDefinitions(for: apps, home: homeDirectory)
+ return await scan(definitions + electron, homeDirectory: homeDirectory, exclusions: exclusions)
+ }
+
+ /// One definition for each installed Electron app whose session data folder, `Application Support/<its name>` as
+ /// Electron's `docs/api/app.md` puts it, holds the `Local State` Electron writes there. It lists only what Electron
+ /// and Chromium name as caches, and an app a definition of the table already covers is left to that definition.
+ static func electronDefinitions(for apps: [InstalledApp], home: URL) -> [Definition] {
+ let covered = Set(definitions.flatMap(\.folders).compactMap { folder -> String? in
+ let names = PathComponents.of(folder.path)
+ guard names.count > 2, names[0] == "Library", names[1] == "Application Support" else { return nil }
+ return names[2].lowercased()
+ })
+ let electron = "https://github.com/electron/electron/blob/main/shell/browser/"
+ let chromium = "https://github.com/chromium/chromium/blob/main/"
+ let codeCache = chromium + "content/browser/storage_partition_impl.cc#L1585"
+ let exists = { (url: URL) in FileManager.default.fileExists(atPath: url.path(percentEncoded: false)) }
+ return apps.compactMap { app in
+ guard let name = app.bundleName, !name.isEmpty, !name.contains("/"), !covered.contains(name.lowercased()),
+ exists(app.url.appending(path: "Contents/Frameworks/Electron Framework.framework"))
+ else { return nil }
+ let data = "Library/Application Support/\(name)"
+ guard exists(home.appending(path: "\(data)/Local State")) else { return nil }
+ let folders = [
+ Folder("\(data)/Cache", .cache, source: electron + "net/network_context_service.cc#L94-L95"),
+ Folder("\(data)/Code Cache", .cache, source: codeCache),
+ ] + ["GPUCache", "DawnWebGPUCache", "DawnGraphiteCache"].map {
+ Folder("\(data)/\($0)", .cache, source: chromium + "gpu/ipc/common/gpu_disk_cache_type.cc#L43-L50")
+ } + ["ShaderCache", "GrShaderCache", "GraphiteDawnCache", "GPUPersistentCache"].map {
+ Folder("\(data)/\($0)", .cache, source: electron + "electron_browser_client.cc#L1206-L1222")
+ }
+ return Definition(
+ id: "electron.\(app.bundleIdentifier)", name: app.name, systemImage: "macwindow",
+ appBundleIdentifiers: [app.bundleIdentifier], folders: folders
+ )
+ }
}
static func scan(
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/DeveloperCachesTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/DeveloperCachesTests.swift
index 4002b512..54c656ce 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/DeveloperCachesTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/DeveloperCachesTests.swift
@@ -136,6 +136,38 @@ struct DeveloperCachesTests {
#expect(models.allSatisfy { $0.kind == .models && !$0.isRecommended })
}
+ @Test func listsAnElectronAppsCachesWhereItsDataCarriesLocalState() async throws {
+ let directory = try TemporaryDirectory()
+ let home = directory.url.appending(path: "home", directoryHint: .isDirectory)
+ let app = { (name: String, electron: Bool) throws -> InstalledApp in
+ let bundle = try directory.directory("Applications/\(name).app/Contents/Frameworks")
+ if electron {
+ let framework = bundle.appending(path: "Electron Framework.framework")
+ try FileManager.default.createDirectory(at: framework, withIntermediateDirectories: true)
+ }
+ return InstalledApp(
+ url: bundle.deletingLastPathComponent().deletingLastPathComponent(),
+ bundleIdentifier: "org.example.\(name.lowercased())", name: name, bundleName: name
+ )
+ }
+ let apps = [try app("Chat", true), try app("Notes", true), try app("Native", false), try app("Code", true)]
+ for name in ["Chat", "Native", "Code"] {
+ try directory.file("home/Library/Application Support/\(name)/Local State")
+ try directory.file("home/Library/Application Support/\(name)/GPUCache/data_0", bytes: 4_096)
+ }
+ try directory.file("home/Library/Application Support/Notes/GPUCache/data_0", bytes: 4_096)
+ try directory.file("home/Library/Application Support/Chat/Cache/Cache_Data/index", bytes: 4_096)
+ try directory.file("home/Library/Application Support/Chat/Local Storage/leveldb/000003.log", bytes: 4_096)
+
+ let definitions = DeveloperCaches.electronDefinitions(for: apps, home: home)
+ let environments = await DeveloperCaches.scan(definitions, homeDirectory: home)
+
+ #expect(definitions.map(\.id) == ["electron.org.example.chat"])
+ let chat = try #require(environments.first)
+ #expect(chat.appBundleIdentifiers == ["org.example.chat"])
+ #expect(chat.locations.map(\.url.lastPathComponent).sorted() == ["Cache", "GPUCache"])
+ }
+
/// A large `DerivedData`, or a Gradle cache on a cold disk, may not be measured in time. Such a folder is not
/// read as empty: it is listed first, with no size, and never selected for the user.
@Test func aFolderThatDidNotAnswerInTimeIsNotReadAsEmpty() async throws {
diff --git a/README.md b/README.md
index 469e2a04..534d8745 100644
--- a/README.md
+++ b/README.md
@@ -103,10 +103,11 @@ Peel is free and open source, and it speaks English and 17 other languages.
- **Orphaned Files:** files left behind by apps you already removed.
- **Developer:** caches of Xcode, package managers, build systems, editors, cloud and virtual machine tools, game
- engines, AI models, and the graphics caches of Chrome, Chromium, and Brave (never what a browser keeps for you).
- Xcode's archives and the symbols it copied from your devices, model weights, installed packages, and what a tool
- keeps for you to install again (Vagrant boxes, Asset Store packages) are listed but never selected for you, and
- toolchains or anything holding an account are never listed.
+ engines, and AI models, the graphics caches of Chrome, Chromium, and Brave, and the web caches of apps built on
+ Electron, such as Slack or Discord (never what a browser or an app keeps for you). Xcode's archives and the symbols
+ it copied from your devices, model weights, installed packages, and what a tool keeps for you to install again
+ (Vagrant boxes, Asset Store packages) are listed but never selected for you, and toolchains or anything holding an
+ account are never listed.
- **Build Artifacts:** what builds left in the folders you choose, like `node_modules`, `DerivedData`, and
`target`. A project changed in the last 7 days is never selected for you, and neither is a Python environment,
Terraform's `.terraform`, or a folder like `target` whose name says nothing on its own.