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.

Tell VoiceOver what a background item's action left it as

Țugui Dragoș90799afe5664
diff --git a/Localization/Peel/Localizable.xcstrings b/Localization/Peel/Localizable.xcstrings
index 7582c572..3818e810 100644
--- a/Localization/Peel/Localizable.xcstrings
+++ b/Localization/Peel/Localizable.xcstrings
@@ -114797,6 +114797,112 @@
}
}
},
+ "Part of this list may be missing." : {
+ "localizations" : {
+ "cs" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Část tohoto seznamu může chybět."
+ }
+ },
+ "de" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Ein Teil dieser Liste fehlt möglicherweise."
+ }
+ },
+ "es" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Puede que falte parte de esta lista."
+ }
+ },
+ "fr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Il manque peut-être une partie de cette liste."
+ }
+ },
+ "it" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Potrebbe mancare una parte di questo elenco."
+ }
+ },
+ "ja" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "このリストの一部が欠けている可能性があります。"
+ }
+ },
+ "ko" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "이 목록의 일부가 누락되었을 수 있습니다."
+ }
+ },
+ "nl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Een deel van deze lijst ontbreekt mogelijk."
+ }
+ },
+ "pl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Może brakować części tej listy."
+ }
+ },
+ "pt" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Parte desta lista pode estar faltando."
+ }
+ },
+ "ro" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "O parte din această listă ar putea lipsi."
+ }
+ },
+ "ru" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Часть этого списка может отсутствовать."
+ }
+ },
+ "sv" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "En del av listan kan saknas."
+ }
+ },
+ "tr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Bu listenin bir kısmı eksik olabilir."
+ }
+ },
+ "uk" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Може бракувати частини цього списку."
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "此列表可能缺少部分内容。"
+ }
+ },
+ "zh-Hant" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "此列表可能缺少一部分。"
+ }
+ }
+ }
+ },
"Path from your home folder" : {
"localizations" : {
"cs" : {
diff --git a/Peel/Model/BackgroundItemLibrary.swift b/Peel/Model/BackgroundItemLibrary.swift
index eb9e5e1c..59103a38 100644
--- a/Peel/Model/BackgroundItemLibrary.swift
+++ b/Peel/Model/BackgroundItemLibrary.swift
@@ -1,6 +1,7 @@
import Foundation
import Observation
import PeelCore
+import SwiftUI
@Observable
final class BackgroundItemLibrary {
@@ -116,6 +117,13 @@ final class BackgroundItemLibrary {
alerts.dismissCurrent()
}
+ /// What VoiceOver hears once an action on `item` is done and the list read again: the state it is in now, which
+ /// its badge shows without a word, or nil when it left the list.
+ static func announcement(for item: BackgroundItem, in listed: [BackgroundItem]?) -> AttributedString? {
+ guard let now = listed?.first(where: { $0.id == item.id }) else { return nil }
+ return AttributedString(localized: "\(now.label): \(String(localized: now.stateWords()))")
+ }
+
/// A job enabled while launchd doesn't have it leaves the list, since it is listed only while disabled or loaded.
static func alertAfterEnabling(_ item: BackgroundItem, listed: [BackgroundItem]?) -> ActionAlert? {
guard let listed, !listed.contains(where: { $0.id == item.id }) else { return nil }
@@ -129,6 +137,7 @@ final class BackgroundItemLibrary {
) async {
runningActionItemIDs.insert(item.id)
defer { runningActionItemIDs.remove(item.id) }
+ var failed = false
do {
switch action {
case .start: try await BackgroundItemActions.start(item)
@@ -155,9 +164,15 @@ final class BackgroundItemLibrary {
}
}
} catch {
+ failed = true
alerts.add(.failed(ActionFailure(label: item.label, action: action, reason: error)))
}
+ let shown = scans
await refresh(installedApps: installedApps)
+ // History tells of a move to the Trash, and an alert of a failure.
+ if action != .moveToTrash, !failed, scans > shown, let words = Self.announcement(for: item, in: items) {
+ AccessibilityNotification.Announcement(words).post()
+ }
}
}
diff --git a/Peel/Views/BackgroundItems/BackgroundItemList.swift b/Peel/Views/BackgroundItems/BackgroundItemList.swift
index 231823b7..708ae8d2 100644
--- a/Peel/Views/BackgroundItems/BackgroundItemList.swift
+++ b/Peel/Views/BackgroundItems/BackgroundItemList.swift
@@ -49,7 +49,7 @@ struct BackgroundItemList: View {
.navigationTitle(Text(Tool.backgroundItems.title))
.announcesScan(
backgroundItems.isScanning,
- found: backgroundItems.summary,
+ found: announcement,
couldNotLook: couldNotLook,
wasStopped: backgroundItems.scanRun.wasStopped
)
@@ -90,6 +90,13 @@ struct BackgroundItemList: View {
}
}
+ /// What VoiceOver hears when a scan ends: what it found, and that part of the list may be missing when it may.
+ private var announcement: AttributedString? {
+ guard let found = backgroundItems.summary else { return nil }
+ guard backgroundItems.missingNote != nil else { return found }
+ return found + " " + AttributedString(localized: "Part of this list may be missing.")
+ }
+
private var couldNotLook: LocalizedStringResource? {
if !backgroundItems.unanswered.isEmpty { return "macOS Didn’t Answer" }
return backgroundItems.unreadableFolders.isEmpty ? nil : "Not Everything Could Be Read"
@@ -274,19 +281,26 @@ 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) {
+ let title = Text(stateWords(withProcess: withProcess))
+ return switch state {
+ case .unknown: (title, "questionmark.circle.dashed", .secondary)
+ case _ where isDisabled: (title, "minus.circle.fill", .orange)
+ case .running: (title, "circle.fill", .green)
+ case .loaded: (title, "circle", .secondary)
+ case .notLoaded: (title, "circle.dashed", .secondary)
+ }
+ }
+
+ func stateWords(withProcess: Bool = false) -> LocalizedStringResource {
switch state {
- case .unknown: (Text(.unknownBackgroundItemState), "questionmark.circle.dashed", .secondary)
+ case .unknown: .unknownBackgroundItemState
// Disabling a job keeps launchd from loading it again, and leaves what runs now running.
case .running(let pid) where isDisabled:
- (
- withProcess ? Text("Disabled, still running · PID \(String(pid))") : Text("Disabled, still running"),
- "minus.circle.fill", .orange
- )
- 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)
+ withProcess ? "Disabled, still running · PID \(String(pid))" : "Disabled, still running"
+ case _ where isDisabled: "Disabled"
+ case .running(let pid): withProcess ? "Running · PID \(String(pid))" : "Running"
+ case .loaded: "Not running"
+ case .notLoaded: "Not loaded"
}
}
}
diff --git a/PeelTests/BackgroundItemAnnouncementTests.swift b/PeelTests/BackgroundItemAnnouncementTests.swift
new file mode 100644
index 00000000..d7c7d710
--- /dev/null
+++ b/PeelTests/BackgroundItemAnnouncementTests.swift
@@ -0,0 +1,29 @@
+import Foundation
+@testable import Peel
+@testable import PeelCore
+import Testing
+
+@MainActor
+struct BackgroundItemAnnouncementTests {
+ private func job(_ state: BackgroundItem.State, disabled: Bool = false) -> BackgroundItem {
+ BackgroundItem(
+ label: "org.example.agent", kind: .agent, source: .userLibrary, plistURL: nil,
+ program: "/usr/local/bin/agent", runsAtLoad: true, keepsAlive: false, ownerBundleIdentifier: nil,
+ ownerName: nil, ownerURL: nil, isOrphan: false, state: state, isDisabled: disabled
+ )
+ }
+
+ @Test func saysTheStateAnActionLeftAnItemIn() {
+ let stopped = BackgroundItemLibrary.announcement(for: job(.running(pid: 42)), in: [job(.loaded)])
+ let disabled = BackgroundItemLibrary.announcement(for: job(.loaded), in: [job(.loaded, disabled: true)])
+ let gone = BackgroundItemLibrary.announcement(for: job(.loaded), in: [])
+
+ #expect(stopped.map { String($0.characters) } == words("Not running"))
+ #expect(disabled.map { String($0.characters) } == words("Disabled"))
+ #expect(gone == nil)
+ }
+
+ private func words(_ state: LocalizedStringResource) -> String {
+ String(localized: "\("org.example.agent"): \(String(localized: state))")
+ }
+}
diff --git a/PeelTests/BackgroundItemStateLookTests.swift b/PeelTests/BackgroundItemStateLookTests.swift
index e2efab6a..f64b8df0 100644
--- a/PeelTests/BackgroundItemStateLookTests.swift
+++ b/PeelTests/BackgroundItemStateLookTests.swift
@@ -1,7 +1,6 @@
import Foundation
@testable import Peel
@testable import PeelCore
-import SwiftUI
import Testing
struct BackgroundItemStateLookTests {
@@ -14,8 +13,8 @@ struct BackgroundItemStateLookTests {
}
@Test func aDisabledJobThatStillRunsSaysBoth() {
- #expect(job(.running(pid: 4_242), disabled: true).stateLook().title == Text("Disabled, still running"))
- #expect(job(.loaded, disabled: true).stateLook().title == Text("Disabled"))
- #expect(job(.running(pid: 4_242), disabled: false).stateLook().title == Text("Running"))
+ #expect(String(localized: job(.running(pid: 4_242), disabled: true).stateWords()) == String(localized: "Disabled, still running"))
+ #expect(String(localized: job(.loaded, disabled: true).stateWords()) == String(localized: "Disabled"))
+ #expect(String(localized: job(.running(pid: 4_242), disabled: false).stateWords()) == String(localized: "Running"))
}
}