feat: show dock badges when they don't show a number (closes #2356)

This commit is contained in:
Louis Pontoise committed 2023-02-22 19:19:48 +01:00
1 parent 0d4e0f1dab
commit 84752e0fef
3 files changed
+13 -10

No files matched your search

+2 -3
View File
@@ -95,10 +95,9 @@ class Applications {
let bundleId = app.runningApplication.bundleIdentifier,
let url = NSWorkspace.shared.urlForApplication(withBundleIdentifier: bundleId),
let matchingItem = (items.first { $0.0 == url }),
let label = matchingItem.1,
let labelInt = Int(label) {
let label = matchingItem.1 {
app.dockLabel = label
view.updateDockLabelIcon(labelInt)
view.updateDockLabelIcon(label)
} else {
app.dockLabel = nil
assignIfDifferent(&view.dockLabelIcon.isHidden, true)
+1 -1
View File
@@ -10,7 +10,7 @@ class Window {
var shouldShowTheUser = true
var isTabbed: Bool = false
var isHidden: Bool { get { application.isHidden } }
var dockLabel: Int? { get { application.dockLabel.flatMap { Int($0) } } }
var dockLabel: String? { get { application.dockLabel } }
var isFullscreen = false
var isMinimized = false
var isOnAllSpaces = false
+10 -6
View File
@@ -198,14 +198,15 @@ class ThumbnailView: NSStackView {
}
@discardableResult
func updateDockLabelIcon(_ dockLabel: Int?) -> Bool {
func updateDockLabelIcon(_ dockLabel: String?) -> Bool {
assignIfDifferent(&dockLabelIcon.isHidden, dockLabel == nil || Preferences.hideAppBadges || Preferences.iconSize == 0)
if !dockLabelIcon.isHidden, let dockLabel = dockLabel {
let view = dockLabelIcon.subviews[1] as! ThumbnailFontIconView
if dockLabel > 30 {
let dockLabelInt = Int(dockLabel)
if dockLabelInt == nil || dockLabelInt! > 30 {
view.setFilledStar()
} else {
view.setNumber(dockLabel, true)
view.setNumber(dockLabelInt!, true)
}
dockLabelIcon.setFrameOrigin(NSPoint(
x: appIcon.frame.maxX - (dockLabelIcon.fittingSize.width / 2) - (appIcon.frame.width / 7),
@@ -216,14 +217,17 @@ class ThumbnailView: NSStackView {
return false
}
func getAccessibilityHelp(_ appName: String?, _ dockLabel: Int?) -> String {
func getAccessibilityHelp(_ appName: String?, _ dockLabel: String?) -> String {
[appName, dockLabel.map { getAccessibilityTextForBadge($0) }]
.compactMap { $0 }
.joined(separator: " - ")
}
func getAccessibilityTextForBadge(_ dockLabel: Int) -> String {
"Red badge with number \(dockLabel)"
func getAccessibilityTextForBadge(_ dockLabel: String) -> String {
if let dockLabelInt = Int(dockLabel) {
return "Red badge with number \(dockLabelInt)"
}
return "Red badge"
}
private func observeDragAndDrop() {