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.

Ask Homebrew about the tools only where it goes nowhere, and say while it is asked

Țugui Dragoșf1c2944a8885
diff --git a/ARCHITECTURE.md b/ARCHITECTURE.md
index bc5f2b34..5938c2a6 100644
--- a/ARCHITECTURE.md
+++ b/ARCHITECTURE.md
@@ -298,7 +298,9 @@ macOS asks the user to approve it once. It talks to the app over XPC.
zsh is also asked which `.zshrc` it reads and, while Peel's prompt is on, which prompt a new window shows
(`ShellSessions`), by running it with the person's startup files as Terminal does; Peel changes none of them.
The Tools tab installs nothing: `TerminalTool` gives each tool's Homebrew formulae and the lines its
- documentation gives, and Homebrew is asked whether it still offers them.
+ documentation gives, and Homebrew is asked, from its local copy of the definitions, whether it still offers
+ them, unless its own settings would make it update its lists over the network first (`Homebrew.overrides`), so
+ the Terminal page goes nowhere.
- **Peel's own updates.** Sparkle, built from its source by `Scripts/build_sparkle.sh`, reads Peel's signed feed
on GitHub (`PeelUpdater`) and installs a new version only when the person chooses it, once the feed and the disk
image it offers are signed with Peel's update key. For a change of key, Sparkle keeps a second way: a disk image
diff --git a/Localization/Peel/Localizable.xcstrings b/Localization/Peel/Localizable.xcstrings
index dd533664..b4c314eb 100644
--- a/Localization/Peel/Localizable.xcstrings
+++ b/Localization/Peel/Localizable.xcstrings
@@ -18202,6 +18202,112 @@
}
}
},
+ "Asking Homebrew…" : {
+ "localizations" : {
+ "cs" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Dotaz na Homebrew…"
+ }
+ },
+ "de" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Homebrew wird gefragt …"
+ }
+ },
+ "es" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Preguntando a Homebrew…"
+ }
+ },
+ "fr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Interrogation de Homebrew…"
+ }
+ },
+ "it" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Chiedo a Homebrew…"
+ }
+ },
+ "ja" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Homebrewに問い合わせ中…"
+ }
+ },
+ "ko" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Homebrew에 묻는 중…"
+ }
+ },
+ "nl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Navragen bij Homebrew…"
+ }
+ },
+ "pl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Pytam Homebrew…"
+ }
+ },
+ "pt" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Perguntando ao Homebrew…"
+ }
+ },
+ "ro" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Interogare Homebrew…"
+ }
+ },
+ "ru" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Запрос к Homebrew…"
+ }
+ },
+ "sv" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Frågar Homebrew…"
+ }
+ },
+ "tr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Homebrew’a soruluyor…"
+ }
+ },
+ "uk" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Запит до Homebrew…"
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "正在询问Homebrew…"
+ }
+ },
+ "zh-Hant" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "正在詢問Homebrew⋯"
+ }
+ }
+ }
+ },
"Asking macOS what is allowed." : {
"localizations" : {
"cs" : {
diff --git a/Peel/Model/TerminalToolLibrary.swift b/Peel/Model/TerminalToolLibrary.swift
index 84a4d26d..5fa88141 100644
--- a/Peel/Model/TerminalToolLibrary.swift
+++ b/Peel/Model/TerminalToolLibrary.swift
@@ -14,30 +14,54 @@ final class TerminalToolLibrary {
let packages: [HomebrewPackage]
}
+ /// Whether Homebrew was asked which tools it still offers: not yet, while the question runs, and what it
+ /// answered, nil when it could not be asked.
+ enum Asked {
+ case notAsked
+ case asking
+ case answered(Catalog?)
+ }
+
private(set) var state: State?
- private(set) var catalog: Catalog?
+ private(set) var asked = Asked.notAsked
private var askingHomebrew: Task<Void, Never>?
func refresh() async {
let prefix = Homebrew.executableURL?.deletingLastPathComponent().deletingLastPathComponent()
let installed = prefix.map { prefix in TerminalTool.allCases.filter { $0.isInstalled(prefix: prefix) } } ?? []
state = State(prefix: prefix, installed: Set(installed))
- guard prefix != nil, catalog == nil else { return }
- if askingHomebrew == nil {
+ guard prefix != nil else { return }
+ if case .notAsked = asked {
+ asked = .asking
askingHomebrew = Task {
- catalog = await Self.askHomebrew()
+ asked = .answered(await Self.askHomebrew())
askingHomebrew = nil
}
}
await askingHomebrew?.value
}
- func availability(of tool: TerminalTool) -> TerminalTool.Availability {
- catalog.map { tool.availability(known: $0.known, packages: $0.packages) } ?? .available
+ func availability(of tool: TerminalTool) -> TerminalTool.Availability? {
+ Self.availability(of: tool, in: asked)
+ }
+
+ /// What the page says of a tool: nothing while Homebrew is being asked, its answer once it has one, and
+ /// available, with its commands, before Homebrew is asked or when it could not be.
+ static func availability(of tool: TerminalTool, in asked: Asked) -> TerminalTool.Availability? {
+ switch asked {
+ case .notAsked: .available
+ case .asking: nil
+ case .answered(let catalog):
+ catalog.map { tool.availability(known: $0.known, packages: $0.packages) } ?? .available
+ }
}
+ /// Homebrew's answer from its local copy of the definitions, and nothing when it has none or when its own
+ /// settings would make it update its lists over the network first, so the Terminal page goes nowhere.
private static func askHomebrew() async -> Catalog? {
- guard await Homebrew.hasLocalDefinitions() else { return nil }
+ guard await Homebrew.hasLocalDefinitions(), let overrides = await Homebrew.overrides(),
+ !overrides.contains(.updatesItself)
+ else { return nil }
let names = await Homebrew.formulaNames()
guard !names.isEmpty else { return nil }
let packages = await Homebrew.formulae(
diff --git a/Peel/Views/Terminal/ToolsTab.swift b/Peel/Views/Terminal/ToolsTab.swift
index 17006ad7..d978b760 100644
--- a/Peel/Views/Terminal/ToolsTab.swift
+++ b/Peel/Views/Terminal/ToolsTab.swift
@@ -77,11 +77,15 @@ private struct TerminalToolRow: View {
.font(.caption)
.foregroundStyle(.secondary)
switch tools.availability(of: tool) {
- case .unknownToHomebrew:
+ case nil:
+ Text("Asking Homebrew…")
+ .font(.caption)
+ .foregroundStyle(.secondary)
+ case .unknownToHomebrew?:
StatusLabel(title: Text("Homebrew no longer offers it."), tint: .accentColor)
.font(.caption)
.foregroundStyle(.secondary)
- case .retired(let retirement):
+ case .retired(let retirement)?:
StatusLabel(title: retirement.title, tint: .accentColor)
.font(.caption.weight(.semibold))
.foregroundStyle(.secondary)
@@ -89,7 +93,7 @@ private struct TerminalToolRow: View {
.font(.caption)
.foregroundStyle(.secondary)
.fixedSize(horizontal: false, vertical: true)
- case .available:
+ case .available?:
let setups = tool.setup(prefix: state.prefix ?? Self.defaultPrefix)
if !isInstalled || !setups.isEmpty {
let title: LocalizedStringKey =
diff --git a/PeelTests/TerminalLibrariesTests.swift b/PeelTests/TerminalLibrariesTests.swift
index 62f7bff2..c9a6a0f5 100644
--- a/PeelTests/TerminalLibrariesTests.swift
+++ b/PeelTests/TerminalLibrariesTests.swift
@@ -136,6 +136,16 @@ struct TerminalLibrariesTests {
#expect(!library.wasRefused)
}
+ @Test func aToolsAvailabilityIsNotKnownWhileHomebrewIsAsked() {
+ let fzf = HomebrewPackage(name: "fzf", kind: .formula)
+ let catalog = TerminalToolLibrary.Catalog(known: ["fzf"], packages: [fzf])
+ #expect(TerminalToolLibrary.availability(of: .fzf, in: .asking) == nil)
+ #expect(TerminalToolLibrary.availability(of: .fzf, in: .notAsked) == .available)
+ #expect(TerminalToolLibrary.availability(of: .fzf, in: .answered(catalog)) == .available)
+ #expect(TerminalToolLibrary.availability(of: .fzfTab, in: .answered(catalog)) == .unknownToHomebrew)
+ #expect(TerminalToolLibrary.availability(of: .fzfTab, in: .notAsked) == .available)
+ }
+
@Test func aGitChangeSavesTheLedgerInTheStoreItWasGiven() async throws {
let home = try madeUpHome()
defer { try? FileManager.default.removeItem(at: home) }