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
Start the sidebar with the tools most people use, and keep each choice
Țugui Dragoș8aa179305188
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 2f5ab870..2222290c 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -28,6 +28,7 @@ The first public release, for macOS 26 and later, on Apple silicon and Intel Mac- Selects what Peel recommends, everything, or nothing, on one list or on every page of a tool at once, and asksfirst before it selects what Peel doesn't recommend.- Leaves alone the files, folders, and apps you exclude.+- Starts the sidebar with the tools most people use, and keeps each tool you turn on or off in Settings.- Checks your apps for updates, and watches the Trash for apps you remove yourself.- Says in About when a new version of Peel is out, with where to get it, and downloads nothing itself.- Exports what is installed and where each app came from, as JSON, CSV, plain text, or a Brewfile.diff --git a/Packages/PeelCore/Sources/PeelCore/Support/SidebarChoices.swift b/Packages/PeelCore/Sources/PeelCore/Support/SidebarChoices.swiftnew file mode 100644index 00000000..cf3924e2--- /dev/null+++ b/Packages/PeelCore/Sources/PeelCore/Support/SidebarChoices.swift@@ -0,0 +1,33 @@+/// The tools a person chose to show or leave out of the sidebar, kept apart from the defaults: a tool never chosen+/// follows its default, which can change with the Mac (Homebrew installed or not) or with a later version of Peel.+public struct SidebarChoices: Sendable, Hashable {+ private var shown: [String: Bool]++ /// Reads `name:1` and `name:0` joined by commas. An entry that makes no sense costs that entry only, and a name+ /// this version doesn't know is kept, since a later version may.+ public init(stored: String) {+ shown = [:]+ for entry in stored.split(separator: ",") {+ let parts = entry.split(separator: ":", omittingEmptySubsequences: false)+ guard parts.count == 2, !parts[0].isEmpty, parts[1] == "1" || parts[1] == "0" else { continue }+ shown[String(parts[0])] = parts[1] == "1"+ }+ }++ /// The choices kept before there were defaults: the names of the tools left out, joined by commas.+ public init(hiddenBefore names: String) {+ shown = Dictionary(names.split(separator: ",").map { (String($0), false) }, uniquingKeysWith: { one, _ in one })+ }++ public var stored: String {+ shown.keys.sorted().map { "\($0):\(shown[$0] == true ? 1 : 0)" }.joined(separator: ",")+ }++ public func shows(_ tool: String, byDefault: Bool) -> Bool {+ shown[tool] ?? byDefault+ }++ public mutating func choose(_ tool: String, shows: Bool) {+ shown[tool] = shows+ }+}diff --git a/Packages/PeelCore/Tests/PeelCoreTests/SidebarChoicesTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/SidebarChoicesTests.swiftnew file mode 100644index 00000000..e17c0942--- /dev/null+++ b/Packages/PeelCore/Tests/PeelCoreTests/SidebarChoicesTests.swift@@ -0,0 +1,42 @@+@testable import PeelCore+import Testing++struct SidebarChoicesTests {+ @Test func aToolNeverChosenFollowsItsDefault() {+ let choices = SidebarChoices(stored: "")++ #expect(choices.shows("plugins", byDefault: false) == false)+ #expect(choices.shows("space", byDefault: true) == true)+ }++ @Test func aChoiceWinsOverTheDefaultEitherWay() {+ var choices = SidebarChoices(stored: "")+ choices.choose("plugins", shows: true)+ choices.choose("space", shows: false)++ let kept = SidebarChoices(stored: choices.stored)++ #expect(kept.shows("plugins", byDefault: false) == true)+ #expect(kept.shows("space", byDefault: true) == false)+ #expect(kept.shows("homebrew", byDefault: false) == false)+ #expect(kept.shows("homebrew", byDefault: true) == true)+ }++ @Test func theOldListOfHiddenToolsCountsAsChosenOff() {+ let choices = SidebarChoices(hiddenBefore: "duplicates,cloud")++ #expect(choices.shows("duplicates", byDefault: true) == false)+ #expect(choices.shows("cloud", byDefault: true) == false)+ #expect(choices.shows("plugins", byDefault: false) == false)+ #expect(SidebarChoices(hiddenBefore: "") == SidebarChoices(stored: ""))+ }++ @Test func keepsANameThisVersionDoesNotKnowAndSkipsWhatMakesNoSense() {+ let choices = SidebarChoices(stored: "laterTool:1,space:0,broken,:1,plugins:yes")++ #expect(choices.shows("laterTool", byDefault: false) == true)+ #expect(choices.shows("space", byDefault: true) == false)+ #expect(choices.shows("plugins", byDefault: false) == false)+ #expect(SidebarChoices(stored: choices.stored) == choices)+ }+}diff --git a/Peel/Model/HomebrewLibrary.swift b/Peel/Model/HomebrewLibrary.swiftindex 224382f6..985150fa 100644--- a/Peel/Model/HomebrewLibrary.swift+++ b/Peel/Model/HomebrewLibrary.swift@@ -160,6 +160,11 @@ final class HomebrewLibrary {(packages ?? []).count { $0.kind == kind }}+ /// Reads again whether Homebrew is installed, which the sidebar's default for the Homebrew page follows.+ func checkInstalled() {+ isInstalled = Homebrew.executableURL != nil+ }+/// Reads the installed packages again. `includingReclaimable` also asks how much `brew cleanup` would/// free, which only the Homebrew page shows. That is a Ruby command that walks the cache and the Cellar,/// so it is asked for only while that page is open or after a command, never on every change indiff --git a/Peel/Navigation/Tool.swift b/Peel/Navigation/Tool.swiftindex 5101915d..ae6eef3b 100644--- a/Peel/Navigation/Tool.swift+++ b/Peel/Navigation/Tool.swift@@ -1,4 +1,5 @@import Foundation+import PeelCore/// A tool in the sidebar. The order of the cases is the order within each group, in the sidebar and in the View/// menu, where the first nine tools get ⌘1 to ⌘9. The `.home` group (Home, Tweaks, Terminal, History) comes first.@@ -107,14 +108,22 @@ extension Tool {}}- /// The tools the sidebar leaves out, read from their names joined by commas. A name this version doesn't- /// know, and a tool that can't be hidden, are ignored.- static func hidden(in stored: String) -> Set<Tool> {- Set(stored.split(separator: ",").compactMap { Tool(rawValue: String($0)) }.filter(\.canBeHidden))+ /// Whether the sidebar shows this tool to a person who never chose: what someone who uninstalls and frees space+ /// rarely needs starts off, and Homebrew shows while Homebrew is installed.+ func isShownByDefault(homebrewIsInstalled: Bool) -> Bool {+ switch self {+ case .backgroundItems, .extensions, .plugins, .projects, .intel, .terminal: false+ case .homebrew: homebrewIsInstalled+ default: true+ }}- static func storing(hidden tools: Set<Tool>) -> String {- tools.map(\.rawValue).sorted().joined(separator: ",")+ /// The tools the sidebar leaves out: those the person chose to, and those never chosen that start off.+ static func hidden(by choices: SidebarChoices, homebrewIsInstalled: Bool) -> Set<Tool> {+ Set(allCases.filter { tool in+ let byDefault = tool.isShownByDefault(homebrewIsInstalled: homebrewIsInstalled)+ return tool.canBeHidden && !choices.shows(tool.rawValue, byDefault: byDefault)+ })}}diff --git a/Peel/Navigation/ToolSidebar.swift b/Peel/Navigation/ToolSidebar.swiftindex 1564f824..6c9ae86a 100644--- a/Peel/Navigation/ToolSidebar.swift+++ b/Peel/Navigation/ToolSidebar.swift@@ -1,4 +1,5 @@import AppKit+import PeelCoreimport SwiftUI/// Where the sidebar can take the user. Settings is a row chosen like the tools and opens as a page in this@@ -19,7 +20,8 @@ struct ToolSidebar: View {@AppStorage("sidebar.system.expanded") private var isSystemExpanded = true/// Tools the user turned off in Settings. They leave the sidebar only: the View menu, Shortcuts, and links/// still open them, as Finder's Go menu opens a place its sidebar hides.- @AppStorage(SettingsKey.hiddenTools) private var hiddenTools = ""+ @AppStorage(SettingsKey.sidebarTools) private var sidebarTools = ""+ @Environment(HomebrewLibrary.self) private var homebrew@Binding var tool: Tool@Binding var page: SidebarDestination?/// The column's width, set by the widest label, because in some languages the longer tool names need more@@ -169,7 +171,7 @@ struct ToolSidebar: View {}private func shown(_ tools: [Tool]) -> [Tool] {- let hidden = Tool.hidden(in: hiddenTools)+ let hidden = Tool.hidden(by: SidebarChoices(stored: sidebarTools), homebrewIsInstalled: homebrew.isInstalled)return tools.filter { !hidden.contains($0) }}diff --git a/Peel/PeelApp.swift b/Peel/PeelApp.swiftindex f75d7621..5830d407 100644--- a/Peel/PeelApp.swift+++ b/Peel/PeelApp.swift@@ -70,6 +70,7 @@ struct PeelApp: App {/// too, so the carrier of their selection reads the same libraries their pages show.init() {SettingsKey.showInMenuBarAsBefore()+ SettingsKey.keepSidebarChoicesAsBefore()let notifications = PeelNotifications()notifications.activate()_notifications = State(initialValue: notifications)@@ -176,6 +177,7 @@ struct PeelApp: App {// History may have become readable again meanwhile, or stopped being, and `peel` may have moved something.history.checkReadability()stats.reload()+ homebrew.checkInstalled()// Home's checks run again whatever page is showing: permissions change in System Settings, and the// badge on Home in the sidebar shows a missing one. They read the helper's status again too.Task { await home.refresh(helper: helper) }@@ -408,6 +410,7 @@ struct PeelApp: App {MenuBarExtra(isInserted: menuBarItemIsInserted) {MenuBarPanel().environment(library)+ .environment(homebrew).environment(stats).environment(found)} label: {diff --git a/Peel/Views/MenuBarFound.swift b/Peel/Views/MenuBarFound.swiftindex 2d295549..f501a1ca 100644--- a/Peel/Views/MenuBarFound.swift+++ b/Peel/Views/MenuBarFound.swift@@ -6,7 +6,8 @@ import SwiftUI/// since the panel's own row counts its updates, and a tool turned off in Settings is left out, as in the sidebar.struct MenuBarFound: View {@Environment(FoundLastTimeStore.self) private var store- @AppStorage(SettingsKey.hiddenTools) private var hiddenTools = ""+ @AppStorage(SettingsKey.sidebarTools) private var sidebarTools = ""+ @Environment(HomebrewLibrary.self) private var homebrew@State private var pointingAt: Tool?let open: (Tool) -> Void@@ -43,7 +44,7 @@ struct MenuBarFound: View {}private var lines: [Line] {- let hidden = Tool.hidden(in: hiddenTools)+ let hidden = Tool.hidden(by: SidebarChoices(stored: sidebarTools), homebrewIsInstalled: homebrew.isInstalled)return store.findings.compactMap { tool, finding inlet looked = Looked(count: finding.count, size: finding.size)guarddiff --git a/Peel/Views/Settings/SettingsView.swift b/Peel/Views/Settings/SettingsView.swiftindex aa243593..e92ca8db 100644--- a/Peel/Views/Settings/SettingsView.swift+++ b/Peel/Views/Settings/SettingsView.swift@@ -74,8 +74,10 @@ enum SettingsKey {static let showsInMenuBar = "showsInMenuBar"static let warnsWhenDiskIsNearlyFull = "lowDiskSpace.warns"static let toldDiskIsNearlyFull = "lowDiskSpace.told"- /// The tools the sidebar leaves out (`Tool.hidden(in:)`).- static let hiddenTools = "sidebar.hiddenTools"+ /// The tools the person chose to show or leave out of the sidebar (`SidebarChoices`).+ static let sidebarTools = "sidebar.tools"+ /// The tools left out before each tool had a default, carried into `sidebarTools` once.+ private static let hiddenToolsBefore = "sidebar.hiddenTools"/// The `peel` tool reads these three keys too, so they are defined once, in PeelCore.static let updateSource = UpdatePreferences.Key.sourcestatic let ignoredUpdateApps = UpdatePreferences.Key.ignoredApps@@ -93,6 +95,17 @@ enum SettingsKey {extension SettingsKey {/// With no value yet, Peel shows in the menu bar exactly when it watches the Trash.+ /// Carries the tools a person left out before each tool had a default into their choices, once. An empty list+ /// carries no choice, so every tool starts at its default.+ static func keepSidebarChoicesAsBefore() {+ let defaults = UserDefaults.standard+ guard let hidden = defaults.string(forKey: hiddenToolsBefore) else { return }+ if defaults.string(forKey: sidebarTools) == nil {+ defaults.set(SidebarChoices(hiddenBefore: hidden).stored, forKey: sidebarTools)+ }+ defaults.removeObject(forKey: hiddenToolsBefore)+ }+static func showInMenuBarAsBefore() {let defaults = UserDefaults.standardguard defaults.object(forKey: showsInMenuBar) == nil else { return }@@ -124,7 +137,7 @@ private struct GeneralSettingsView: View {@AppStorage(SettingsKey.watchesTrash) private var watchesTrash = false@AppStorage(SettingsKey.showsInMenuBar) private var showsInMenuBar = false@AppStorage(SettingsKey.warnsWhenDiskIsNearlyFull) private var warnsWhenDiskIsNearlyFull = false- @AppStorage(SettingsKey.hiddenTools) private var hiddenTools = ""+ @AppStorage(SettingsKey.sidebarTools) private var sidebarTools = ""@Environment(TrashMonitor.self) private var trashMonitor@Environment(AppLibrary.self) private var library@Environment(HomebrewLibrary.self) private var homebrew@@ -487,7 +500,7 @@ extension GeneralSettingsView {extension GeneralSettingsView {private var sidebarToolsSummary: String {- let hidden = Tool.hidden(in: hiddenTools)+ let hidden = Tool.hidden(by: SidebarChoices(stored: sidebarTools), homebrewIsInstalled: homebrew.isInstalled)let left = Tool.Group.allCases.flatMap(\.tools).filter(hidden.contains).map { String(localized: $0.title) }guard !left.isEmpty else { return String(localized: "Every tool is in the sidebar.") }return String(localized: "Left out: \(left.formatted(.list(type: .and))).")@@ -508,11 +521,14 @@ extension GeneralSettingsView {fileprivate func showsInSidebar(_ tool: Tool) -> Binding<Bool> {Binding(- get: { !Tool.hidden(in: hiddenTools).contains(tool) },+ get: {+ !Tool.hidden(by: SidebarChoices(stored: sidebarTools), homebrewIsInstalled: homebrew.isInstalled)+ .contains(tool)+ },set: { shows in- var hidden = Tool.hidden(in: hiddenTools)- if shows { hidden.remove(tool) } else { hidden.insert(tool) }- hiddenTools = Tool.storing(hidden: hidden)+ var choices = SidebarChoices(stored: sidebarTools)+ choices.choose(tool.rawValue, shows: shows)+ sidebarTools = choices.stored})}diff --git a/README.md b/README.mdindex b357c944..4c5c6326 100644--- a/README.md+++ b/README.md@@ -232,7 +232,8 @@ Settings > General holds Peel's choices, among them which tools the sidebar show- **Export:** what's installed and where each app came from, as JSON, a spreadsheet, plain text, or a Brewfile.- **Shortcuts:** actions that open a page in Peel for you to look at. None of them removes anything.- **Sidebar:** turn off the tools you don't use in Settings, and they leave the sidebar. The View menu and- Shortcuts still open them.+ Shortcuts still open them. Background Items, Extensions, Plug-ins, Build Artifacts, Intel Software, and Terminal+ start turned off, and Homebrew starts on only when Homebrew is installed; what you turn on or off stays so.- **The `peel` command:** most of the above, from Terminal.## Safe by designdiff --git a/TERMINAL.md b/TERMINAL.mdindex 6bd4ffda..baac0e5b 100644--- a/TERMINAL.md+++ b/TERMINAL.md@@ -19,8 +19,9 @@ each checked for contrast against its background.### With Peel-Choose Terminal in Peel's sidebar, then choose a theme. Terminal opens with it and uses it in every new window, and-Put Back gives Terminal the profile it had before. Peel changes Terminal's settings only while Terminal is closed,+The Terminal page starts turned off in Peel's sidebar: turn it on in Settings > General > Sidebar, or open it from+the View menu. Choose a theme there, and Terminal opens with it and uses it in every new window, and Put Back gives+Terminal the profile it had before. Peel changes Terminal's settings only while Terminal is closed,and offers to quit it first.The Terminal tab of the same page can also leave out the "Last login" line in new windows, keep Terminal from