Skip to content

Commit

Permalink
Draw rings based on menu appearance
Browse files Browse the repository at this point in the history
  • Loading branch information
flostellbrink committed Jul 18, 2023
1 parent 8f8c604 commit 08b47d8
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions RingStats/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ class AppDelegate: NSObject, NSApplicationDelegate {
NSApp.activate(ignoringOtherApps: true)
}



func drawCircularProgress(innerProgress: CGFloat, innerRadius: Int, outerProgress: CGFloat, outerRadius: Int, color: NSColor) -> NSImage {
let image = NSImage(size: NSSize(width: 20, height: 20), flipped: false) { rect in
color.withAlphaComponent(0.2).setStroke()
Expand All @@ -64,7 +62,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
outerBackground.lineWidth = 2
outerBackground.stroke()

color.setStroke()
color.withAlphaComponent(0.9).setStroke()

let innerPath = NSBezierPath()
innerPath.appendArc(withCenter: CGPoint(x: rect.midX, y: rect.midY), radius: CGFloat(innerRadius), startAngle: 90, endAngle: 360 + 90 - 360 * innerProgress, clockwise: true)
Expand All @@ -87,6 +85,9 @@ class AppDelegate: NSObject, NSApplicationDelegate {
@objc func updateStats() {
let memoryPressure = statistics.getMemoryPressure()
let processorPressure = statistics.getProcessorPressure()
if memoryPressure.isNaN || processorPressure.isNaN {
return
}

let font = NSFont.monospacedSystemFont(ofSize: NSFont.systemFontSize, weight: .regular)

Expand All @@ -110,7 +111,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
button.image = drawCircularProgress(
innerProgress: clamp(value: memoryPressure), innerRadius: 5,
outerProgress: clamp(value: processorPressure), outerRadius: 8,
color: NSColor.white)
color: button.effectiveAppearance.name.rawValue.lowercased().contains("dark") ? NSColor.white : NSColor.black)

}
}
Expand Down

0 comments on commit 08b47d8

Please sign in to comment.