Skip to content

Commit 08c4ab9

Browse files
committed
feat: added tooltips to the missing elements and enabled accessibility on some not natively supported (#2321)
1 parent 8de91d9 commit 08c4ab9

13 files changed

+63
-11
lines changed

Kit/module/popup.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ internal class HeaderView: NSStackView {
418418
fileprivate func setCloseButton(_ state: Bool) {
419419
if state && !self.isCloseAction {
420420
self.activityButton?.image = Bundle(for: type(of: self)).image(forResource: "close")!
421-
self.activityButton?.toolTip = localizedString("Close popup")
421+
self.activityButton?.toolTip = localizedString("Close")
422422
self.activityButton?.action = #selector(self.closePopup)
423423
self.isCloseAction = true
424424
} else if !state && self.isCloseAction {

Kit/module/settings.swift

+2-1
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,8 @@ private class WidgetPreview: NSStackView {
496496
self.layer?.backgroundColor = NSColor.white.cgColor
497497

498498
self.identifier = NSUserInterfaceItemIdentifier(rawValue: type.rawValue)
499-
self.toolTip = localizedString("Move widget", type.name())
499+
self.setAccessibilityElement(true)
500+
self.toolTip = type.name()
500501

501502
self.orientation = .vertical
502503
self.distribution = .fill

Kit/plugins/Charts.swift

+11
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,8 @@ public class PieChartView: NSView {
486486
self.segments = segments
487487

488488
super.init(frame: frame)
489+
490+
self.setAccessibilityElement(true)
489491
}
490492

491493
required init?(coder: NSCoder) {
@@ -575,6 +577,15 @@ public class HalfCircleGraphView: NSView {
575577

576578
public var color: NSColor = NSColor.systemBlue
577579

580+
public override init(frame: NSRect) {
581+
super.init(frame: frame)
582+
self.setAccessibilityElement(true)
583+
}
584+
585+
required init?(coder: NSCoder) {
586+
fatalError("init(coder:) has not been implemented")
587+
}
588+
578589
public override func draw(_ rect: CGRect) {
579590
let arcWidth: CGFloat = 7.0
580591
let radius = (min(self.frame.width, self.frame.height) - arcWidth) / 2

Modules/CPU/popup.swift

+6
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ internal class Popup: PopupWrapper {
131131

132132
self.spacing = 0
133133
self.orientation = .vertical
134+
// self.setAccessibilityElement(true)
135+
// self.toolTip = self.title
134136

135137
self.systemColorState = SColor.fromString(Store.shared.string(key: "\(self.title)_systemColor", defaultValue: self.systemColorState.key))
136138
self.userColorState = SColor.fromString(Store.shared.string(key: "\(self.title)_userColor", defaultValue: self.userColorState.key))
@@ -375,6 +377,7 @@ internal class Popup: PopupWrapper {
375377
self.userField?.stringValue = "\(Int(value.userLoad.rounded(toPlaces: 2) * 100))%"
376378
self.idleField?.stringValue = "\(Int(value.idleLoad.rounded(toPlaces: 2) * 100))%"
377379

380+
self.circle?.toolTip = "\(localizedString("CPU usage")): \(Int(value.totalUsage.rounded(toPlaces: 2) * 100))%"
378381
self.circle?.setValue(value.totalUsage)
379382
self.circle?.setSegments([
380383
circle_segment(value: value.systemLoad, color: self.systemColor),
@@ -416,6 +419,7 @@ internal class Popup: PopupWrapper {
416419
view.isHidden = false
417420
}
418421

422+
self.temperatureCircle?.toolTip = "\(localizedString("CPU temperature")): \(temperature(value))"
419423
self.temperatureCircle?.setValue(value)
420424
self.temperatureCircle?.setText(temperature(value))
421425
self.initializedTemperature = true
@@ -447,6 +451,7 @@ internal class Popup: PopupWrapper {
447451
if let circle = self.frequencyCircle {
448452
circle.setValue((100*freq)/self.maxFreq)
449453
circle.setText("\((freq/1000).rounded(toPlaces: 2))")
454+
circle.toolTip = "\(localizedString("CPU frequency")): \(Int(freq)) MHz - \(((100*freq)/self.maxFreq).rounded(toPlaces: 2))%"
450455
}
451456
} else if value.count == 2 {
452457
let e = value.first ?? 0
@@ -463,6 +468,7 @@ internal class Popup: PopupWrapper {
463468
if let circle = self.frequencyCircle {
464469
circle.setValue((100*freq)/self.maxFreq)
465470
circle.setText("\((freq/1000).rounded(toPlaces: 2))")
471+
circle.toolTip = "\(localizedString("CPU frequency")): \(Int(freq)) MHz - \(((100*freq)/self.maxFreq).rounded(toPlaces: 2))%"
466472
}
467473
}
468474
}

Modules/CPU/portal.swift

+1
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ public class Portal: PortalWrapper {
138138
self.userField?.stringValue = "\(Int(value.userLoad.rounded(toPlaces: 2) * 100))%"
139139
self.idleField?.stringValue = "\(Int(value.idleLoad.rounded(toPlaces: 2) * 100))%"
140140

141+
self.circle?.toolTip = "\(localizedString("CPU usage")): \(Int(value.totalUsage.rounded(toPlaces: 2) * 100))%"
141142
self.circle?.setValue(value.totalUsage)
142143
self.circle?.setSegments([
143144
circle_segment(value: value.systemLoad, color: self.systemColor),

Modules/Clock/popup.swift

+4
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,8 @@ private class CalendarView: NSStackView {
165165
self.day = Calendar.current.component(.day, from: Date())
166166

167167
super.init(frame: NSRect(x: 0, y: 0, width: width, height: width - 32))
168+
self.setAccessibilityElement(true)
169+
self.toolTip = localizedString("Calendar")
168170

169171
self.spacing = 0
170172
self.orientation = .vertical
@@ -442,6 +444,8 @@ private class ClockView: NSStackView {
442444
)
443445
self.wantsLayer = true
444446
self.layer?.cornerRadius = 2
447+
self.setAccessibilityElement(true)
448+
self.toolTip = "\(clock.name): \(clock.formatted())"
445449

446450
self.clockView.widthAnchor.constraint(equalToConstant: 34).isActive = true
447451

Modules/Disk/portal.swift

+1
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ public class Portal: PortalWrapper {
106106
self.usedField?.stringValue = DiskSize(value.size - value.free).getReadableMemory()
107107
self.freeField?.stringValue = DiskSize(value.free).getReadableMemory()
108108

109+
self.circle?.toolTip = "\(localizedString("Disk usage")): \(Int(value.percentage*100))%"
109110
self.circle?.setValue(value.percentage)
110111
self.circle?.setSegments([
111112
circle_segment(value: value.percentage, color: self.valueColor)

Modules/GPU/popup.swift

+12-8
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,8 @@ private class GPUView: NSStackView {
161161
charts.distribution = .fillEqually
162162
self.chartRow = charts
163163

164-
self.addStats(id: "temperature", self.value.temperature)
165-
self.addStats(id: "utilization", self.value.utilization)
164+
self.addStats(id: "GPU temperature", self.value.temperature)
165+
self.addStats(id: "GPU utilization", self.value.utilization)
166166
self.addStats(id: "Render utilization", self.value.renderUtilization)
167167
self.addStats(id: "Tiler utilization", self.value.tilerUtilization)
168168

@@ -191,7 +191,7 @@ private class GPUView: NSStackView {
191191
} else {
192192
circle = HalfCircleGraphView(frame: NSRect(x: 0, y: 0, width: circleSize, height: circleSize))
193193
circle.id = id
194-
circle.toolTip = localizedString("GPU \(id)")
194+
circle.toolTip = localizedString(id)
195195
if let row = self.circleRow {
196196
row.setFrameSize(NSSize(width: row.frame.width, height: self.circleSize + 20))
197197
row.edgeInsets = NSEdgeInsets(top: 10, left: 10, bottom: 0, right: 10)
@@ -208,7 +208,7 @@ private class GPUView: NSStackView {
208208
chart.layer?.backgroundColor = NSColor.lightGray.withAlphaComponent(0.1).cgColor
209209
chart.layer?.cornerRadius = 3
210210
chart.id = id
211-
chart.toolTip = localizedString("GPU \(id)")
211+
chart.toolTip = localizedString(id)
212212
if let row = self.chartRow {
213213
row.setFrameSize(NSSize(width: row.frame.width, height: self.chartSize + 20))
214214
row.spacing = Constants.Popup.margins
@@ -223,31 +223,35 @@ private class GPUView: NSStackView {
223223
}
224224
}
225225

226-
if id == "temperature" {
226+
if id == "GPU temperature" {
227227
circle.setValue(value)
228228
circle.setText(temperature(value))
229+
circle.toolTip = "\(localizedString(id)): \(temperature(value))"
229230
chart.suffix = UnitTemperature.current.symbol
230231

231232
if self.temperatureChart == nil {
232233
self.temperatureChart = chart
233234
}
234-
} else if id == "utilization" {
235+
} else if id == "GPU utilization" {
235236
circle.setValue(value)
236237
circle.setText("\(Int(value*100))%")
238+
circle.toolTip = "\(localizedString(id)): \(Int(value*100))%"
237239

238240
if self.utilizationChart == nil {
239241
self.utilizationChart = chart
240242
}
241243
} else if id == "Render utilization" {
242244
circle.setValue(value)
243245
circle.setText("\(Int(value*100))%")
246+
circle.toolTip = "\(localizedString(id)): \(Int(value*100))%"
244247

245248
if self.renderUtilizationChart == nil {
246249
self.renderUtilizationChart = chart
247250
}
248251
} else if id == "Tiler utilization" {
249252
circle.setValue(value)
250253
circle.setText("\(Int(value*100))%")
254+
circle.toolTip = "\(localizedString(id)): \(Int(value*100))%"
251255

252256
if self.tilerUtilizationChart == nil {
253257
self.tilerUtilizationChart = chart
@@ -262,8 +266,8 @@ private class GPUView: NSStackView {
262266
self.stateView?.layer?.backgroundColor = (gpu.state ? NSColor.systemGreen : NSColor.systemRed).cgColor
263267
self.stateView?.toolTip = localizedString("GPU \(gpu.state ? "enabled" : "disabled")")
264268

265-
self.addStats(id: "temperature", gpu.temperature)
266-
self.addStats(id: "utilization", gpu.utilization)
269+
self.addStats(id: "GPU temperature", gpu.temperature)
270+
self.addStats(id: "GPU utilization", gpu.utilization)
267271
self.addStats(id: "Render utilization", gpu.renderUtilization)
268272
self.addStats(id: "Tiler utilization", gpu.tilerUtilization)
269273
}

Modules/GPU/portal.swift

+1
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ public class Portal: PortalWrapper {
9090
self.tilerField?.stringValue = "\(Int(value*100))%"
9191
}
9292

93+
self.circle?.toolTip = "\(localizedString("GPU usage")): \(Int(value.utilization!*100))%"
9394
self.circle?.setValue(value.utilization!)
9495
self.circle?.setText("\(Int(value.utilization!*100))%")
9596
self.initialized = true

Modules/Net/popup.swift

+10
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@ import Kit
1515
internal class Popup: PopupWrapper {
1616
private var title: String
1717

18+
private var uploadContainerView: NSView? = nil
1819
private var uploadView: NSView? = nil
1920
private var uploadValue: Int64 = 0
2021
private var uploadValueField: NSTextField? = nil
2122
private var uploadUnitField: NSTextField? = nil
2223
private var uploadStateView: ColorView? = nil
2324

25+
private var downloadContainerView: NSView? = nil
2426
private var downloadView: NSView? = nil
2527
private var downloadValue: Int64 = 0
2628
private var downloadValueField: NSTextField? = nil
@@ -166,13 +168,15 @@ internal class Popup: PopupWrapper {
166168

167169
let leftPart: NSView = NSView(frame: NSRect(x: 0, y: 0, width: view.frame.width / 2, height: view.frame.height))
168170
let downloadFields = self.topValueView(leftPart, title: localizedString("Downloading"), color: self.downloadColor)
171+
self.downloadContainerView = leftPart
169172
self.downloadView = downloadFields.0
170173
self.downloadValueField = downloadFields.1
171174
self.downloadUnitField = downloadFields.2
172175
self.downloadStateView = downloadFields.3
173176

174177
let rightPart: NSView = NSView(frame: NSRect(x: view.frame.width / 2, y: 0, width: view.frame.width / 2, height: view.frame.height))
175178
let uploadFields = self.topValueView(rightPart, title: localizedString("Uploading"), color: self.uploadColor)
179+
self.uploadContainerView = rightPart
176180
self.uploadView = uploadFields.0
177181
self.uploadValueField = uploadFields.1
178182
self.uploadUnitField = uploadFields.2
@@ -688,6 +692,9 @@ internal class Popup: PopupWrapper {
688692
let topHeight: CGFloat = 30
689693
let titleHeight: CGFloat = 15
690694

695+
view.setAccessibilityElement(true)
696+
view.toolTip = title
697+
691698
let valueWidth = "0".widthOfString(usingFont: .systemFont(ofSize: 26, weight: .light)) + 5
692699
let unitWidth = "KB/s".widthOfString(usingFont: .systemFont(ofSize: 13, weight: .light)) + 5
693700
let topPartWidth = valueWidth + unitWidth
@@ -739,6 +746,9 @@ internal class Popup: PopupWrapper {
739746
let upload = Units(bytes: self.uploadValue).getReadableTuple(base: self.base)
740747
let download = Units(bytes: self.downloadValue).getReadableTuple(base: self.base)
741748

749+
self.uploadContainerView?.toolTip = "\(localizedString("Uploading")): \(upload.0)\(upload.1)"
750+
self.downloadContainerView?.toolTip = "\(localizedString("Downloading")): \(download.0)\(download.1)"
751+
742752
var valueWidth = "\(upload.0)".widthOfString(usingFont: .systemFont(ofSize: 26, weight: .light)) + 5
743753
var unitWidth = upload.1.widthOfString(usingFont: .systemFont(ofSize: 13, weight: .light)) + 5
744754
var topPartWidth = valueWidth + unitWidth

Modules/RAM/popup.swift

+11
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ internal class Popup: PopupWrapper {
250250
self.usedField?.stringValue = Units(bytes: Int64(value.used)).getReadableMemory(style: .memory)
251251
self.freeField?.stringValue = Units(bytes: Int64(value.free)).getReadableMemory(style: .memory)
252252

253+
self.circle?.toolTip = "\(localizedString("Memory usage")): \(Int(value.usage*100))%"
253254
self.circle?.setValue(value.usage)
254255
self.circle?.setSegments([
255256
circle_segment(value: value.app/value.total, color: self.appColor),
@@ -258,6 +259,7 @@ internal class Popup: PopupWrapper {
258259
])
259260
self.circle?.setNonActiveSegmentColor(self.freeColor)
260261
self.level?.setValue(value.pressure)
262+
self.level?.toolTip = "\(localizedString("Memory pressure")): \(value.pressure.value.rawValue)"
261263

262264
self.initialized = true
263265
}
@@ -431,6 +433,15 @@ public class PressureView: NSView {
431433

432434
private var value: Pressure = Pressure(level: 1, value: .normal)
433435

436+
public override init(frame: NSRect) {
437+
super.init(frame: frame)
438+
self.setAccessibilityElement(true)
439+
}
440+
441+
required init?(coder: NSCoder) {
442+
fatalError("init(coder:) has not been implemented")
443+
}
444+
434445
public override func draw(_ rect: CGRect) {
435446
let arcWidth: CGFloat = 7.0
436447
let centerPoint = CGPoint(x: self.frame.width/2, y: self.frame.height/2)

Modules/RAM/portal.swift

+1
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ public class Portal: PortalWrapper {
111111
self.pressureLevelField?.toolTip = localizedString(level.value)
112112
}
113113

114+
self.circle?.toolTip = "\(localizedString("Memory usage")): \(Int(value.usage*100))%"
114115
self.circle?.setValue(value.usage)
115116
self.circle?.setSegments([
116117
circle_segment(value: value.app/value.total, color: self.appColor),

Stats/Views/AppSettings.swift

+2-1
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,8 @@ private class ModulePreview: NSStackView {
513513
self.layer?.backgroundColor = NSColor.white.cgColor
514514

515515
self.identifier = NSUserInterfaceItemIdentifier(rawValue: id)
516-
self.toolTip = localizedString("Move module", id)
516+
self.setAccessibilityElement(true)
517+
self.toolTip = id
517518

518519
self.orientation = .vertical
519520
self.distribution = .fill

0 commit comments

Comments
 (0)