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.

Run no other brew while the chosen one can't be run

Țugui Dragoș222cdcb57fd6
diff --git a/ARCHITECTURE.md b/ARCHITECTURE.md
index dc7e378d..946fd6ea 100644
--- a/ARCHITECTURE.md
+++ b/ARCHITECTURE.md
@@ -462,7 +462,7 @@ where a Homebrew install takes them from.
| `~/Library/Application Support/Peel/left-for-an-administrator.json` | What an uninstall left that only an administrator can move, from a place the helper doesn't serve, so Orphaned Files lists it under Needs an Administrator once the app is gone. |
| `~/Library/Application Support/Peel/dock-tiles.json` | The Dock icons an uninstall took out, and where each was, so History puts them back with their app. |
| `~/Library/Application Support/Peel/app-folders.json` | The folders the user chose for Peel to look for apps in, beside the Applications folders. |
-| `~/Library/Application Support/Peel/homebrew.json` | The `brew` the user chose for a Homebrew in a folder of its own, which the app and `peel` run. |
+| `~/Library/Application Support/Peel/homebrew.json` | The `brew` the user chose for a Homebrew in a folder of its own, which the app and `peel` run, and no other while it is chosen, even when it can no longer be run. |
| `~/Library/Application Support/Peel/Terminal/zshrc`, `Terminal/ssh_config` | The shell and ssh settings chosen on the Terminal page, which zsh and ssh read through the lines the user adds. |
| `~/Library/Application Support/Peel/release-notes.json` | What is new in each update that waits, as the app's own sources say it, so its page shows it with no connection. |
| `~/Library/Application Support/Peel/*.lock` | The lock beside each file the app and `peel` both change, so a read and the write after it are one step (`FileLock`). |
diff --git a/Localization/Peel/Localizable.xcstrings b/Localization/Peel/Localizable.xcstrings
index 91b221e6..e1a14d54 100644
--- a/Localization/Peel/Localizable.xcstrings
+++ b/Localization/Peel/Localizable.xcstrings
@@ -115310,6 +115310,113 @@
"comment" : "The app's name, never translated.",
"shouldTranslate" : false
},
+ "Peel Can’t Run the `brew` You Chose" : {
+ "comment" : "The title of the Homebrew page when the brew program the person chose in Settings > General can no longer be run (moved, not a program, or not theirs). Keep `brew` as it is: it is Homebrew's command.",
+ "localizations" : {
+ "cs" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel nemůže spustit `brew`, který jste zvolili"
+ }
+ },
+ "de" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel kann das von dir gewählte `brew` nicht ausführen"
+ }
+ },
+ "es" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel no puede ejecutar el `brew` que has seleccionado"
+ }
+ },
+ "fr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel ne peut pas exécuter le `brew` que vous avez choisi"
+ }
+ },
+ "it" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel non può eseguire il `brew` che hai scelto"
+ }
+ },
+ "ja" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peelは選択した`brew`を実行できません"
+ }
+ },
+ "ko" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "사용자가 선택한 `brew`를 Peel이 실행할 수 없음"
+ }
+ },
+ "nl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel kan de gekozen `brew` niet uitvoeren"
+ }
+ },
+ "pl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel nie może uruchomić wybranego przez Ciebie `brew`"
+ }
+ },
+ "pt" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "O Peel Não Pode Executar o `brew` que Você Escolheu"
+ }
+ },
+ "ro" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel nu poate rula programul `brew` pe care l‑ați ales"
+ }
+ },
+ "ru" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel не может запустить выбранный Вами `brew`"
+ }
+ },
+ "sv" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel kan inte köra den `brew` som du valde"
+ }
+ },
+ "tr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel Seçtiğiniz `brew` Programını Çalıştıramıyor"
+ }
+ },
+ "uk" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel не може запустити вибраний вами `brew`"
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel无法运行你选取的`brew`"
+ }
+ },
+ "zh-Hant" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel無法執行你選擇的`brew`"
+ }
+ }
+ }
+ },
"Peel Inventory.%@" : {
"comment" : "A suggested file name. Translate the words before the dot. %@ is the file extension, such as json.",
"localizations" : {
@@ -129471,6 +129578,220 @@
}
}
},
+ "Peel runs only the `brew` you chose in Settings, %@, and that one can’t be run now." : {
+ "comment" : "Under the title of the same name on the Homebrew page. %@ is the path of the brew program they chose, such as ~/brew/bin/brew. A second line under it says why it can't be run. Keep `brew` as it is.",
+ "localizations" : {
+ "cs" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel spouští jen `brew`, který jste zvolili v Nastavení, %@, a ten teď nelze spustit."
+ }
+ },
+ "de" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel führt nur das `brew` aus, das du in den Einstellungen gewählt hast (%@), und dieses lässt sich jetzt nicht ausführen."
+ }
+ },
+ "es" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel solo ejecuta el `brew` que has seleccionado en Ajustes, %@, y ahora no se puede ejecutar."
+ }
+ },
+ "fr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel n’exécute que le `brew` que vous avez choisi dans les Réglages, %@, et celui-ci ne peut pas être exécuté pour l’instant."
+ }
+ },
+ "it" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel esegue solo il `brew` che hai scelto nelle Impostazioni, %@, e al momento non è possibile eseguirlo."
+ }
+ },
+ "ja" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peelは“設定”で選択した`brew`(%@)だけを実行しますが、それは現在実行できません。"
+ }
+ },
+ "ko" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel은 사용자가 설정에서 선택한 `brew`인 %@만 실행하는데, 지금은 이를 실행할 수 없습니다."
+ }
+ },
+ "nl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel voert alleen de `brew` uit die je in Instellingen hebt gekozen, %@, en die kan nu niet worden uitgevoerd."
+ }
+ },
+ "pl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel uruchamia tylko `brew` wybrany przez Ciebie w Ustawieniach, %@, a tego nie można teraz uruchomić."
+ }
+ },
+ "pt" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "O Peel só executa o `brew` que você escolheu nos Ajustes, %@, e esse não pode ser executado agora."
+ }
+ },
+ "ro" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel rulează doar programul `brew` pe care l‑ați ales în Configurări, %@, iar acesta nu poate fi rulat acum."
+ }
+ },
+ "ru" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel запускает только `brew`, выбранный Вами в Настройках (%@), но сейчас его нельзя запустить."
+ }
+ },
+ "sv" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel kör bara den `brew` som du valde i Inställningar, %@, och den kan inte köras just nu."
+ }
+ },
+ "tr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel yalnızca Ayarlar’da seçtiğiniz `brew` programını (%@) çalıştırır ve o program şu anda çalıştırılamıyor."
+ }
+ },
+ "uk" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel запускає лише `brew`, вибраний вами в Параметрах (%@), а його зараз не вдається запустити."
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel只运行你在“设置”中选取的`brew`(%@),而它现在无法运行。"
+ }
+ },
+ "zh-Hant" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel只會執行你在「設定」中選擇的`brew`(%@),而目前無法執行它。"
+ }
+ }
+ }
+ },
+ "Peel runs only the `brew` you chose, and that one can’t be run now." : {
+ "comment" : "In Settings > General > Homebrew and on the Terminal page's Tools tab, when the brew program the person chose can no longer be run. A line under it says why. Keep `brew` as it is.",
+ "localizations" : {
+ "cs" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel spouští jen `brew`, který jste zvolili, a ten teď nelze spustit."
+ }
+ },
+ "de" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel führt nur das `brew` aus, das du gewählt hast, und dieses lässt sich jetzt nicht ausführen."
+ }
+ },
+ "es" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel solo ejecuta el `brew` que has seleccionado, y ahora no se puede ejecutar."
+ }
+ },
+ "fr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel n’exécute que le `brew` que vous avez choisi, et celui-ci ne peut pas être exécuté pour l’instant."
+ }
+ },
+ "it" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel esegue solo il `brew` che hai scelto, e al momento non è possibile eseguirlo."
+ }
+ },
+ "ja" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peelは選択した`brew`だけを実行しますが、それは現在実行できません。"
+ }
+ },
+ "ko" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel은 사용자가 선택한 `brew`만 실행하는데, 지금은 이를 실행할 수 없습니다."
+ }
+ },
+ "nl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel voert alleen de `brew` uit die je hebt gekozen, en die kan nu niet worden uitgevoerd."
+ }
+ },
+ "pl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel uruchamia tylko `brew` wybrany przez Ciebie, a tego nie można teraz uruchomić."
+ }
+ },
+ "pt" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "O Peel só executa o `brew` que você escolheu, e esse não pode ser executado agora."
+ }
+ },
+ "ro" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel rulează doar programul `brew` pe care l‑ați ales, iar acesta nu poate fi rulat acum."
+ }
+ },
+ "ru" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel запускает только выбранный Вами `brew`, но сейчас его нельзя запустить."
+ }
+ },
+ "sv" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel kör bara den `brew` som du valde, och den kan inte köras just nu."
+ }
+ },
+ "tr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel yalnızca seçtiğiniz `brew` programını çalıştırır ve o program şu anda çalıştırılamıyor."
+ }
+ },
+ "uk" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel запускає лише вибраний вами `brew`, а його зараз не вдається запустити."
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel只运行你选取的`brew`,而它现在无法运行。"
+ }
+ },
+ "zh-Hant" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel只會執行你選擇的`brew`,而目前無法執行它。"
+ }
+ }
+ }
+ },
"Peel runs the `brew` in /opt/homebrew or /usr/local. If your Homebrew is in a folder of its own, such as /opt/brew, choose its `brew`, and Peel and `peel` run that one." : {
"localizations" : {
"cs" : {
diff --git a/Packages/PeelCore/Sources/PeelCommandLine/Commands/AppCommands.swift b/Packages/PeelCore/Sources/PeelCommandLine/Commands/AppCommands.swift
index 7f393981..b5b05231 100644
--- a/Packages/PeelCore/Sources/PeelCommandLine/Commands/AppCommands.swift
+++ b/Packages/PeelCore/Sources/PeelCommandLine/Commands/AppCommands.swift
@@ -51,7 +51,7 @@ struct InventoryCommand: AsyncParsableCommand {
private static func brewfile() async throws -> String {
let why: String
if !(await Homebrew.hasLocalDefinitions()) {
- why = noDefinitions(isInstalled: Homebrew.executableURL != nil)
+ why = noDefinitions(isInstalled: Homebrew.executableURL != nil, unrunnable: HomebrewChoice().unrunnable())
} else if let installation = await Homebrew.installation() {
do {
return try await Homebrew.brewfile(from: installation)
@@ -75,9 +75,10 @@ struct InventoryCommand: AsyncParsableCommand {
why = error.output
}
} else {
- why = noDefinitions(isInstalled: Homebrew.executableURL != nil)
+ why = noDefinitions(isInstalled: Homebrew.executableURL != nil, unrunnable: HomebrewChoice().unrunnable())
}
- if let note = homebrewNote(isInstalled: Homebrew.executableURL != nil, why: why) {
+ let isChosen = HomebrewChoice().load() != nil
+ if let note = homebrewNote(isInstalled: Homebrew.executableURL != nil || isChosen, why: why) {
Output.note(note)
}
return []
@@ -91,8 +92,11 @@ struct InventoryCommand: AsyncParsableCommand {
/// Why Homebrew was not asked: without its local copy of the definitions it would download them. The copy is
/// missing because Homebrew isn't installed, or because it never fetched one.
- static func noDefinitions(isInstalled: Bool) -> String {
- isInstalled ? "Homebrew has no list of packages on this Mac. Run `brew update` first." : "Homebrew isn't installed."
+ static func noDefinitions(isInstalled: Bool, unrunnable: HomebrewChoice.Unrunnable? = nil) -> String {
+ if let unrunnable {
+ return "Peel runs only the brew chosen in its Settings, \(unrunnable.brew.path(percentEncoded: false)), and that one can't be run."
+ }
+ return isInstalled ? "Homebrew has no list of packages on this Mac. Run `brew update` first." : "Homebrew isn't installed."
}
}
diff --git a/Packages/PeelCore/Sources/PeelCore/Homebrew/Homebrew.swift b/Packages/PeelCore/Sources/PeelCore/Homebrew/Homebrew.swift
index 406aeeb1..43bc55cd 100644
--- a/Packages/PeelCore/Sources/PeelCore/Homebrew/Homebrew.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Homebrew/Homebrew.swift
@@ -550,7 +550,8 @@ public enum Homebrew {
}
static func executable(chosen: URL?) -> URL? {
- chosen ?? ["/opt/homebrew/bin/brew", "/usr/local/bin/brew"]
+ if let chosen { return HomebrewChoice.refusal(of: chosen) == nil ? chosen : nil }
+ return ["/opt/homebrew/bin/brew", "/usr/local/bin/brew"]
.map { URL(filePath: $0) }
.first { FileManager.default.isExecutableFile(atPath: $0.path(percentEncoded: false)) }
}
diff --git a/Packages/PeelCore/Sources/PeelCore/Homebrew/HomebrewChoice.swift b/Packages/PeelCore/Sources/PeelCore/Homebrew/HomebrewChoice.swift
index 621ebee1..325201f7 100644
--- a/Packages/PeelCore/Sources/PeelCore/Homebrew/HomebrewChoice.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Homebrew/HomebrewChoice.swift
@@ -14,6 +14,11 @@ public struct HomebrewChoice: Sendable {
case writableByEveryone
}
+ public struct Unrunnable: Sendable, Equatable {
+ public let brew: URL
+ public let refusal: Refusal
+ }
+
public let url: URL
public init(url: URL = HomebrewChoice.defaultURL) {
@@ -24,12 +29,17 @@ public struct HomebrewChoice: Sendable {
PeelFolder.url.appending(path: "homebrew.json")
}
- /// The chosen `brew`, or nil when none was chosen or the one chosen can no longer be run.
+ /// The chosen `brew`, or nil when none was chosen. It stays chosen when it can no longer be run, so Peel runs
+ /// no other one in its place.
public func load() -> URL? {
guard let data = BoundedRead.data(at: url), let path = try? JSONDecoder().decode(String?.self, from: data)
else { return nil }
- let brew = URL(filePath: path)
- return Self.refusal(of: brew) == nil ? brew : nil
+ return URL(filePath: path)
+ }
+
+ public func unrunnable() -> Unrunnable? {
+ guard let brew = load(), let refusal = Self.refusal(of: brew) else { return nil }
+ return Unrunnable(brew: brew, refusal: refusal)
}
/// Keeps `brew` as the one to run, or forgets the choice when it is nil. False when it could not be saved.
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/CommandLineTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/CommandLineTests.swift
index 684c6847..463c825d 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/CommandLineTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/CommandLineTests.swift
@@ -11,6 +11,8 @@ struct CommandLineTests {
@Test func saysWhyHomebrewHasNoListInTheWayThatFits() {
#expect(InventoryCommand.noDefinitions(isInstalled: false) == "Homebrew isn't installed.")
#expect(InventoryCommand.noDefinitions(isInstalled: true) == "Homebrew has no list of packages on this Mac. Run `brew update` first.")
+ let chosen = HomebrewChoice.Unrunnable(brew: URL(filePath: "/opt/brew/bin/brew"), refusal: .notAProgram)
+ #expect(InventoryCommand.noDefinitions(isInstalled: false, unrunnable: chosen) == "Peel runs only the brew chosen in its Settings, /opt/brew/bin/brew, and that one can't be run.")
}
/// A list of apps says nothing of Homebrew on a Mac without it, and says why when Homebrew is there and did
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/HomebrewChoiceTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/HomebrewChoiceTests.swift
index a3c8332b..9a16c9d2 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/HomebrewChoiceTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/HomebrewChoiceTests.swift
@@ -36,7 +36,7 @@ struct HomebrewChoiceTests {
#expect(choice.load() == nil)
}
- @Test func forgetsABrewThatCanNoLongerBeRun() throws {
+ @Test func runsNoOtherBrewWhileTheChosenOneCannotRun() throws {
let directory = try TemporaryDirectory()
let brew = try program("opt/brew/bin/brew", in: directory)
let choice = HomebrewChoice(url: directory.url.appending(path: "homebrew.json"))
@@ -44,7 +44,9 @@ struct HomebrewChoiceTests {
chmod(brew.path(percentEncoded: false), 0o644)
- #expect(choice.load() == nil)
+ #expect(choice.load()?.path(percentEncoded: false) == brew.path(percentEncoded: false))
+ #expect(choice.unrunnable()?.refusal == .notAProgram)
+ #expect(Homebrew.executable(chosen: choice.load()) == nil)
}
@Test func runsTheChosenBrewAndFindsItsOwnPrograms() throws {
diff --git a/Peel/Model/HomebrewLibrary.swift b/Peel/Model/HomebrewLibrary.swift
index bff83c3c..4cfe127b 100644
--- a/Peel/Model/HomebrewLibrary.swift
+++ b/Peel/Model/HomebrewLibrary.swift
@@ -61,6 +61,8 @@ final class HomebrewLibrary {
/// Checked again on every refresh, so Homebrew installed while Peel is open is found without a relaunch.
private(set) var isInstalled = Homebrew.executableURL != nil
+ /// The `brew` chosen in Settings when it can no longer be run, in which case Peel runs none.
+ private(set) var unrunnableChoice = HomebrewChoice().unrunnable()
/// Homebrew's output when the last reading failed, which is not the same as nothing being installed.
private(set) var couldNotRead: String?
private(set) var packages: [HomebrewPackage]?
@@ -209,6 +211,13 @@ final class HomebrewLibrary {
/// Reads again whether Homebrew is installed, which the sidebar's default for the Homebrew page follows.
func checkInstalled() {
isInstalled = Homebrew.executableURL != nil
+ unrunnableChoice = HomebrewChoice().unrunnable()
+ }
+
+ /// Whether the sidebar shows the Homebrew page by default: also while the `brew` chosen can't be run, so the page
+ /// can say so.
+ var isInstalledOrChosen: Bool {
+ isInstalled || unrunnableChoice != nil
}
/// Reads the packages again when Homebrew checked for new versions since they were read, as `brew update` in
@@ -225,6 +234,7 @@ final class HomebrewLibrary {
/// `/Applications`.
func refresh(includingReclaimable: Bool = false) async {
isInstalled = Homebrew.executableURL != nil
+ unrunnableChoice = HomebrewChoice().unrunnable()
guard isInstalled else {
forgetHomebrew()
return
diff --git a/Peel/Model/TerminalToolLibrary.swift b/Peel/Model/TerminalToolLibrary.swift
index 5fa88141..1d359e39 100644
--- a/Peel/Model/TerminalToolLibrary.swift
+++ b/Peel/Model/TerminalToolLibrary.swift
@@ -7,6 +7,7 @@ final class TerminalToolLibrary {
struct State: Equatable {
var prefix: URL?
var installed: Set<TerminalTool>
+ var unrunnable: HomebrewChoice.Unrunnable?
}
struct Catalog {
@@ -29,7 +30,7 @@ final class TerminalToolLibrary {
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))
+ state = State(prefix: prefix, installed: Set(installed), unrunnable: HomebrewChoice().unrunnable())
guard prefix != nil else { return }
if case .notAsked = asked {
asked = .asking
diff --git a/Peel/Views/Homebrew/HomebrewList.swift b/Peel/Views/Homebrew/HomebrewList.swift
index 9b71a2f5..c2a9e5ad 100644
--- a/Peel/Views/Homebrew/HomebrewList.swift
+++ b/Peel/Views/Homebrew/HomebrewList.swift
@@ -73,7 +73,8 @@ struct HomebrewList: View {
.announcesScan(
homebrew.isScanning,
found: homebrew.summary,
- couldNotLook: !homebrew.isInstalled ? "Homebrew Isn’t Installed"
+ couldNotLook: homebrew.unrunnableChoice != nil ? "Peel Can’t Run the `brew` You Chose"
+ : !homebrew.isInstalled ? "Homebrew Isn’t Installed"
: !homebrew.needsDefinitions ? nil
: homebrew.mayChange ? "Homebrew Has to Update First" : "Homebrew Belongs to Another Account",
wasStopped: homebrew.scanRun.wasStopped
@@ -691,7 +692,18 @@ struct HomebrewList: View {
@ViewBuilder
private func placeholder(_ shown: [HomebrewPackage]) -> some View {
- if !homebrew.isInstalled {
+ if let chosen = homebrew.unrunnableChoice {
+ ContentUnavailableView {
+ Label("Peel Can’t Run the `brew` You Chose", systemImage: "mug")
+ } description: {
+ VStack(spacing: 6) {
+ Text("Peel runs only the `brew` you chose in Settings, \(chosen.brew.abbreviatedPath), and that one can’t be run now.")
+ chosen.refusal.explanation
+ }
+ } actions: {
+ Button("Open Peel Settings") { SettingsPane.general.open(with: openSettings) }
+ }
+ } else if !homebrew.isInstalled {
ContentUnavailableView {
Label("Homebrew Isn’t Installed", systemImage: "mug")
} description: {
diff --git a/Peel/Views/MenuBarFound.swift b/Peel/Views/MenuBarFound.swift
index 41db18f1..a570f3f0 100644
--- a/Peel/Views/MenuBarFound.swift
+++ b/Peel/Views/MenuBarFound.swift
@@ -44,7 +44,9 @@ struct MenuBarFound: View {
}
private var lines: [Line] {
- let hidden = Tool.hidden(by: SidebarChoices(stored: sidebarTools), homebrewIsInstalled: homebrew.isInstalled)
+ let hidden = Tool.hidden(
+ by: SidebarChoices(stored: sidebarTools), homebrewIsInstalled: homebrew.isInstalledOrChosen
+ )
return store.findings.compactMap { tool, finding in
let looked = Looked(count: finding.count, size: finding.size)
guard
diff --git a/Peel/Views/Settings/HomebrewSection.swift b/Peel/Views/Settings/HomebrewSection.swift
index 089466b5..d351e150 100644
--- a/Peel/Views/Settings/HomebrewSection.swift
+++ b/Peel/Views/Settings/HomebrewSection.swift
@@ -13,14 +13,23 @@ struct HomebrewSection: View {
@State private var couldNotSave = false
var body: some View {
+ let unrunnable = HomebrewChoice().unrunnable()
Section {
LabeledContent {
- Text(Homebrew.executableURL?.abbreviatedPath ?? String(localized: "Not found"))
+ Text((unrunnable?.brew ?? Homebrew.executableURL)?.abbreviatedPath ?? String(localized: "Not found"))
.lineLimit(1)
.truncationMode(.middle)
} label: {
Text(verbatim: "brew")
}
+ if let unrunnable {
+ VStack(alignment: .leading, spacing: 4) {
+ StatusLabel(title: Text("Peel runs only the `brew` you chose, and that one can’t be run now."))
+ unrunnable.refusal.explanation
+ .font(.callout)
+ .foregroundStyle(.secondary)
+ }
+ }
if couldNotSave {
StatusLabel(title: Text("Peel couldn’t save which `brew` to run."))
}
@@ -47,7 +56,7 @@ struct HomebrewSection: View {
.alert("Peel can’t run this file.", isPresented: isShowingRefusal) {
Button("OK", role: .cancel) {}
} message: {
- refusalMessage
+ refusal?.explanation ?? Text(verbatim: "")
}
.alert("Run this brew for Homebrew?", isPresented: isConfirming, presenting: confirming) { brew in
Button("Use It") { use(brew) }
@@ -65,19 +74,20 @@ struct HomebrewSection: View {
Binding(get: { confirming != nil }, set: { if !$0 { confirming = nil } })
}
- private var refusalMessage: Text {
- switch refusal {
+ private func use(_ brew: URL?) {
+ couldNotSave = !HomebrewChoice().save(brew)
+ choice = HomebrewChoice().load()
+ Task { await homebrew.refresh() }
+ }
+}
+
+extension HomebrewChoice.Refusal {
+ var explanation: Text {
+ switch self {
case .notBrew: Text("Choose the file called `brew`, in the bin folder of your Homebrew.")
case .notAProgram: Text("It isn’t a program Peel can run.")
case .ownedByAnotherAccount: Text("It belongs to another account, which could change what it runs.")
case .writableByEveryone: Text("Anyone on this Mac can change it, so Peel won’t run it.")
- case nil: Text(verbatim: "")
}
}
-
- private func use(_ brew: URL?) {
- couldNotSave = !HomebrewChoice().save(brew)
- choice = HomebrewChoice().load()
- Task { await homebrew.refresh() }
- }
}
diff --git a/Peel/Views/Settings/SettingsView.swift b/Peel/Views/Settings/SettingsView.swift
index dfd1a448..eda902c9 100644
--- a/Peel/Views/Settings/SettingsView.swift
+++ b/Peel/Views/Settings/SettingsView.swift
@@ -605,7 +605,9 @@ extension GeneralSettingsView {
extension GeneralSettingsView {
private var sidebarToolsSummary: String {
- let hidden = Tool.hidden(by: SidebarChoices(stored: sidebarTools), homebrewIsInstalled: homebrew.isInstalled)
+ let hidden = Tool.hidden(
+ by: SidebarChoices(stored: sidebarTools), homebrewIsInstalled: homebrew.isInstalledOrChosen
+ )
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))).")
@@ -627,8 +629,9 @@ extension GeneralSettingsView {
fileprivate func showsInSidebar(_ tool: Tool) -> Binding<Bool> {
Binding(
get: {
- !Tool.hidden(by: SidebarChoices(stored: sidebarTools), homebrewIsInstalled: homebrew.isInstalled)
- .contains(tool)
+ !Tool.hidden(
+ by: SidebarChoices(stored: sidebarTools), homebrewIsInstalled: homebrew.isInstalledOrChosen
+ ).contains(tool)
},
set: { shows in
var choices = SidebarChoices(stored: sidebarTools)
diff --git a/Peel/Views/Terminal/ToolsTab.swift b/Peel/Views/Terminal/ToolsTab.swift
index d978b760..9135b8ba 100644
--- a/Peel/Views/Terminal/ToolsTab.swift
+++ b/Peel/Views/Terminal/ToolsTab.swift
@@ -7,7 +7,17 @@ struct ToolsTab: View {
var body: some View {
Form {
if let state = tools.state {
- if state.prefix == nil {
+ if let unrunnable = state.unrunnable {
+ Section {
+ VStack(alignment: .leading, spacing: 4) {
+ StatusLabel(title: Text("Peel runs only the `brew` you chose, and that one can’t be run now."))
+ unrunnable.refusal.explanation
+ .font(.callout)
+ .foregroundStyle(.secondary)
+ }
+ .padding(.vertical, 4)
+ }
+ } else if state.prefix == nil {
Section {
VStack(alignment: .leading, spacing: 4) {
HStack(spacing: 5) {