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.

Show a note's caution with a colored symbol instead of colored words

Țugui Dragoșe5329f673b97
diff --git a/Peel/Views/InfoNote.swift b/Peel/Views/InfoNote.swift
index c55bdb8a..fc6776fe 100644
--- a/Peel/Views/InfoNote.swift
+++ b/Peel/Views/InfoNote.swift
@@ -5,12 +5,12 @@ struct InfoNote: View {
/// Already localized: the heading of the note, and the name its accessibility label uses.
let name: String
/// Built when the note opens: a list draws hundreds of these, and few are ever opened.
- let detail: () -> Text
+ let detail: () -> Text?
var symbol: String?
/// The technical line, when there is one worth keeping but not worth a row of its own.
var footnote: Text?
- /// Draws the circle in the accent color, for a note holding something to know before acting.
- var isMarked = false
+ /// Something to know before acting. It draws the circle in the accent color.
+ var caution: Text?
/// Only Home passes this; see `noteTint`.
var isAlbum = false
/// True for the note in each row of a list of items, whose button takes `RowButtonStyle`.
@@ -26,10 +26,10 @@ struct InfoNote: View {
init(
name: String,
- detail: @autoclosure @escaping () -> Text,
+ detail: @autoclosure @escaping () -> Text?,
symbol: String? = nil,
footnote: Text? = nil,
- isMarked: Bool = false,
+ caution: Text? = nil,
isAlbum: Bool = false,
isInRow: Bool = false,
opening: Binding<Bool>? = nil
@@ -38,12 +38,16 @@ struct InfoNote: View {
self.detail = detail
self.symbol = symbol
self.footnote = footnote
- self.isMarked = isMarked
+ self.caution = caution
self.isAlbum = isAlbum
self.isInRow = isInRow
self.opening = opening
}
+ private var isMarked: Bool {
+ caution != nil
+ }
+
/// A marked note says so in its shape as well: by color alone it is the fainter of the two in light mode.
private var mark: String {
isMarked ? "exclamationmark.circle.fill" : "info.circle"
@@ -62,7 +66,10 @@ struct InfoNote: View {
.padding(-4)
.accessibilityLabel(isMarked ? Text("A caution about \(name)") : Text("What \(name) is for"))
.popover(isPresented: isOpen, arrowEdge: .bottom) {
- NoteCard(name: name, detail: detail(), symbol: symbol ?? mark, footnote: footnote, isAlbum: isAlbum)
+ NoteCard(
+ name: name, detail: detail(), symbol: symbol ?? mark, footnote: footnote, caution: caution,
+ isAlbum: isAlbum
+ )
}
}
}
@@ -72,9 +79,10 @@ struct InfoNote: View {
struct NoteCard: View {
/// Already localized: the heading of the note.
let name: String
- let detail: Text
+ let detail: Text?
var symbol: String?
var footnote: Text?
+ var caution: Text?
var isAlbum = false
private var tint: Color { noteTint(isAlbum: isAlbum) }
@@ -90,9 +98,16 @@ struct NoteCard: View {
Text(verbatim: name)
.font(.headline)
.foregroundStyle(isAlbum ? Album.ink : .primary)
- detail
- .font(.callout)
- .foregroundStyle(.secondary)
+ if let detail {
+ detail
+ .font(.callout)
+ .foregroundStyle(.secondary)
+ }
+ if let caution {
+ StatusLabel(title: caution, tint: tint)
+ .font(.callout)
+ .foregroundStyle(.secondary)
+ }
if let footnote {
footnote
.font(.caption.monospaced())
diff --git a/Peel/Views/RemovalRow.swift b/Peel/Views/RemovalRow.swift
index 6a303cca..efe44f0e 100644
--- a/Peel/Views/RemovalRow.swift
+++ b/Peel/Views/RemovalRow.swift
@@ -88,7 +88,7 @@ struct RemovalRow: View {
isOn: Binding(get: { isSelected }, set: { selection.setSelected($0, for: url) }),
label: spokenItem,
// What the note says, since its button takes no keyboard focus.
- hint: hasExplanation ? String(explanation.characters) : nil
+ hint: hasExplanation ? spokenNote : nil
)
clickableItem
.checkboxTitle()
@@ -226,9 +226,9 @@ struct RemovalRow: View {
if hasExplanation {
InfoNote(
name: url.lastPathComponent,
- detail: Text(explanation),
+ detail: explanation.characters.isEmpty ? nil : Text(explanation),
footnote: Text(verbatim: url.path(percentEncoded: false)),
- isMarked: warning != nil,
+ caution: warning.map { Text(Self.commandsMarked($0)) },
isInRow: true,
opening: $isNoteOpen
)
@@ -252,14 +252,14 @@ struct RemovalRow: View {
let written = String(localized: "Last changed \(lastWritten, format: .relative(presentation: .named))")
text += AttributedString(text.characters.isEmpty ? written : "\n\n\(written)")
}
- if let warning {
- var marked = Self.commandsMarked(text.characters.isEmpty ? warning : "\n\n\(warning)")
- marked.foregroundColor = Color.accentColor
- text += marked
- }
return text
}
+ private var spokenNote: String {
+ let caution = warning.map { String(Self.commandsMarked($0).characters) } ?? ""
+ return [String(explanation.characters), caution].filter { !$0.isEmpty }.joined(separator: "\n\n")
+ }
+
/// Marks the text between backticks as code, as `Text` does, and keeps the rest as written. It doesn't
/// parse Markdown, because a path in a warning can hold characters Markdown would read as emphasis.
private static func commandsMarked(_ string: String) -> AttributedString {
diff --git a/Peel/Views/Tweaks/TweakDetailView.swift b/Peel/Views/Tweaks/TweakDetailView.swift
index a998db31..1ad37917 100644
--- a/Peel/Views/Tweaks/TweakDetailView.swift
+++ b/Peel/Views/Tweaks/TweakDetailView.swift
@@ -43,9 +43,9 @@ struct TweakRow: View {
.minimumScaleFactor(0.8)
InfoNote(
name: String(localized: tweak.words.title),
- detail: Text(note),
+ detail: Text(verbatim: note),
footnote: Text(verbatim: "\(tweak.domain) \(tweak.key)"),
- isMarked: tweak.words.caution != nil
+ caution: tweak.words.caution.map { Text($0) }
)
}
// A folder tweak holds a path rather than on or off, so the path is the row's second line.
@@ -83,28 +83,18 @@ struct TweakRow: View {
.padding(.leading, parent == nil ? 0 : 20)
}
- /// The note the circled i opens: what the tweak does, any caution (in the accent color), how the change
- /// takes effect, and whether macOS has its own control for the setting.
- private var note: AttributedString {
- var text = AttributedString(String(localized: tweak.words.detail))
- if let caution = tweak.words.caution {
- var marked = AttributedString("\n\n\(String(localized: caution))")
- marked.foregroundColor = Color.accentColor
- text += marked
- }
- // Each sentence gets its own paragraph instead of being joined with a space, since Japanese and
- // Chinese put no space between sentences.
- var paragraphs: [String] = []
+ /// The note the circled i opens: what the tweak does, how the change takes effect, and whether macOS has its
+ /// own control for the setting. Each sentence gets its own paragraph instead of being joined with a space,
+ /// since Japanese and Chinese put no space between sentences.
+ private var note: String {
+ var paragraphs = [String(localized: tweak.words.detail)]
if let restart = tweak.restart.sentence {
paragraphs.append(String(localized: restart))
}
if tweak.hasASystemControl {
paragraphs.append(String(localized: "macOS has its own control for this, so it can change back."))
}
- if !paragraphs.isEmpty {
- text += AttributedString("\n\n" + paragraphs.joined(separator: "\n\n"))
- }
- return text
+ return paragraphs.joined(separator: "\n\n")
}
/// A label for a setting Peel can't change: one locked by a configuration profile, or one whose last write