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.

Background items show their state alike in the list and on the page

Țugui Dragoșa7abfda317a7
diff --git a/Peel/Views/BackgroundItems/BackgroundItemDetailView.swift b/Peel/Views/BackgroundItems/BackgroundItemDetailView.swift
index cf3b6277..116e41f2 100644
--- a/Peel/Views/BackgroundItems/BackgroundItemDetailView.swift
+++ b/Peel/Views/BackgroundItems/BackgroundItemDetailView.swift
@@ -282,15 +282,9 @@ struct BackgroundItemDetailView: View {
/// The item's state, as one badge whose text, symbol, and color change with it. A badge per state would swap
/// without a fade, because a form row shows a newly inserted view at once.
private var stateBadge: some View {
- let (title, symbol, tint): (Text, String, Color) = switch item.state {
- case .unknown: (Text(.unknownBackgroundItemState), "questionmark.circle.dashed", .secondary)
- case _ where item.isDisabled: (Text("Disabled"), "minus.circle", .orange)
- case .running(let pid): (Text("Running · PID \(String(pid))"), "circle.fill", .green)
- case .loaded: (Text("Not running"), "circle", .secondary)
- case .notLoaded: (Text("Not loaded"), "circle.dashed", .secondary)
- }
+ let look = item.stateLook(withProcess: true)
// The state changes right after the user presses a button here, so the text and symbol crossfade.
- return Badge(title: title, systemImage: symbol, tint: tint)
+ return Badge(title: look.title, systemImage: look.symbol, tint: look.tint)
.contentTransition(.opacity)
}
diff --git a/Peel/Views/BackgroundItems/BackgroundItemList.swift b/Peel/Views/BackgroundItems/BackgroundItemList.swift
index be206737..b55118ea 100644
--- a/Peel/Views/BackgroundItems/BackgroundItemList.swift
+++ b/Peel/Views/BackgroundItems/BackgroundItemList.swift
@@ -180,39 +180,25 @@ struct BackgroundItemStateIndicator: View {
let item: BackgroundItem
var body: some View {
- Image(systemName: symbol)
- .foregroundStyle(color)
+ let look = item.stateLook()
+ Image(systemName: look.symbol)
+ .foregroundStyle(look.tint)
.imageScale(.small)
- .accessibilityLabel(label)
- }
-
- // A state Peel could not read comes first, since whether the job is disabled may not have been read either.
- private var symbol: String {
- switch item.state {
- case .unknown: "questionmark.circle.dashed"
- case _ where item.isDisabled: "minus.circle.fill"
- case .running: "circle.fill"
- case .loaded: "circle"
- case .notLoaded: "circle.dashed"
- }
- }
-
- private var color: Color {
- switch item.state {
- case .unknown: .secondary
- case _ where item.isDisabled: .orange
- case .running: .green
- case .loaded, .notLoaded: .secondary
- }
+ .accessibilityLabel(look.title)
}
+}
- private var label: Text {
- switch item.state {
- case .unknown: Text(.unknownBackgroundItemState)
- case _ where item.isDisabled: Text("Disabled")
- case .running: Text("Running")
- case .loaded: Text("Not running")
- case .notLoaded: Text("Not loaded")
+extension BackgroundItem {
+ /// How the job's state is shown, in the list and on its page alike. A state Peel could not read comes first,
+ /// since whether the job is disabled may not have been read either. `withProcess` names a running job's process.
+ func stateLook(withProcess: Bool = false) -> (title: Text, symbol: String, tint: Color) {
+ switch state {
+ case .unknown: (Text(.unknownBackgroundItemState), "questionmark.circle.dashed", .secondary)
+ case _ where isDisabled: (Text("Disabled"), "minus.circle.fill", .orange)
+ case .running(let pid):
+ (withProcess ? Text("Running · PID \(String(pid))") : Text("Running"), "circle.fill", .green)
+ case .loaded: (Text("Not running"), "circle", .secondary)
+ case .notLoaded: (Text("Not loaded"), "circle.dashed", .secondary)
}
}
}