feat: prepare to support macOS 10.13

This commit is contained in:
Serhiy Mytrovtsiy
2021-07-07 19:15:47 +02:00
parent 08d8d84ceb
commit 178b713353
12 changed files with 45 additions and 19 deletions

View File

@@ -166,7 +166,7 @@ public class BarChart: WidgetWrapper {
let partition = NSBezierPath(rect: NSRect(x: x, y: offset, width: partitionWidth, height: partitonHeight))
switch self.colorState {
case .systemAccent: NSColor.controlAccentColor.set()
case .systemAccent: controlAccentColor.set()
case .utilization: partitionValue.usageColor(zones: self.colorZones).setFill()
case .pressure: self.pressureLevel.pressureColor().setFill()
case .monochrome:
@@ -175,7 +175,7 @@ public class BarChart: WidgetWrapper {
} else {
(isDarkMode ? NSColor.white : NSColor.black).set()
}
default: (self.colorState.additional as? NSColor ?? NSColor.controlAccentColor).set()
default: (self.colorState.additional as? NSColor ?? controlAccentColor).set()
}
partition.fill()

View File

@@ -107,9 +107,9 @@ public class LineChart: WidgetWrapper {
let offset = lineWidth / 2
var boxSize: CGSize = CGSize(width: self.width - (Constants.Widget.margin.x*2), height: self.frame.size.height)
var color: NSColor = NSColor.controlAccentColor
var color: NSColor = controlAccentColor
switch self.colorState {
case .systemAccent: color = NSColor.controlAccentColor
case .systemAccent: color = controlAccentColor
case .utilization: color = value.usageColor()
case .pressure: color = self.pressureLevel.pressureColor()
case .monochrome:
@@ -118,7 +118,7 @@ public class LineChart: WidgetWrapper {
} else {
color = (isDarkMode ? NSColor.white : NSColor.black)
}
default: color = self.colorState.additional as? NSColor ?? NSColor.controlAccentColor
default: color = self.colorState.additional as? NSColor ?? controlAccentColor
}
if self.labelState {

View File

@@ -118,13 +118,13 @@ public class Mini: WidgetWrapper {
origin.y = 1
}
var color: NSColor = NSColor.controlAccentColor
var color: NSColor = controlAccentColor
switch self.colorState {
case .systemAccent: color = NSColor.controlAccentColor
case .systemAccent: color = controlAccentColor
case .utilization: color = value.usageColor()
case .pressure: color = self.pressureLevel.pressureColor()
case .monochrome: color = (isDarkMode ? NSColor.white : NSColor.black)
default: color = self.colorState.additional as? NSColor ?? NSColor.controlAccentColor
default: color = self.colorState.additional as? NSColor ?? controlAccentColor
}
let stringAttributes = [

View File

@@ -102,7 +102,7 @@ public extension Int {
case 3:
return NSColor.systemRed
default:
return NSColor.controlAccentColor
return controlAccentColor
}
}
}

View File

@@ -241,7 +241,9 @@ internal class HeaderView: NSStackView {
activity.translatesAutoresizingMaskIntoConstraints = false
activity.imageScaling = .scaleNone
activity.image = Bundle(for: type(of: self)).image(forResource: "chart")!
activity.contentTintColor = .lightGray
if #available(OSX 10.14, *) {
activity.contentTintColor = .lightGray
}
activity.isBordered = false
activity.action = #selector(openActivityMonitor)
activity.target = self
@@ -269,7 +271,9 @@ internal class HeaderView: NSStackView {
settings.translatesAutoresizingMaskIntoConstraints = false
settings.imageScaling = .scaleNone
settings.image = Bundle(for: type(of: self)).image(forResource: "settings")!
settings.contentTintColor = .lightGray
if #available(OSX 10.14, *) {
settings.contentTintColor = .lightGray
}
settings.isBordered = false
settings.action = #selector(openSettings)
settings.target = self

View File

@@ -371,7 +371,9 @@ internal class WidgetPreview: NSStackView {
button.image = image
}
button.imageScaling = .scaleProportionallyDown
button.contentTintColor = .lightGray
if #available(OSX 10.14, *) {
button.contentTintColor = .lightGray
}
button.isBordered = false
button.action = #selector(self.toggleSettings)
button.target = self

View File

@@ -36,7 +36,7 @@ public class LineChartView: NSView {
public var points: [Double]
public var transparent: Bool = true
public var color: NSColor = NSColor.controlAccentColor
public var color: NSColor = controlAccentColor
public init(frame: NSRect, num: Int) {
self.points = Array(repeating: 0, count: num)

View File

@@ -157,6 +157,16 @@ extension Color: CaseIterable {
}
}
public var controlAccentColor: NSColor {
get {
if #available(OSX 10.14, *) {
return NSColor.controlAccentColor
} else {
return NSColor.systemBlue
}
}
}
public typealias colorZones = (orange: Double, red: Double)
public extension Notification.Name {

View File

@@ -218,7 +218,7 @@ internal class DiskNameAndBarView: NSView {
let width: CGFloat = (view.frame.width * (percentage < 0 ? 0 : percentage)) / 1
self.usedBarSpace = NSView(frame: NSRect(x: 0, y: 0, width: width, height: view.frame.height))
self.usedBarSpace?.wantsLayer = true
self.usedBarSpace?.layer?.backgroundColor = NSColor.controlAccentColor.cgColor
self.usedBarSpace?.layer?.backgroundColor = controlAccentColor.cgColor
view.addSubview(self.usedBarSpace!)
self.addSubview(view)

View File

@@ -166,7 +166,9 @@ internal class Popup: NSStackView, Popup_p {
button.bezelStyle = .regularSquare
button.isBordered = false
button.imageScaling = NSImageScaling.scaleAxesIndependently
button.contentTintColor = .lightGray
if #available(OSX 10.14, *) {
button.contentTintColor = .lightGray
}
button.action = #selector(self.resetTotalNetworkUsage)
button.target = self
button.toolTip = localizedString("Reset")
@@ -212,7 +214,9 @@ internal class Popup: NSStackView, Popup_p {
button.bezelStyle = .regularSquare
button.isBordered = false
button.imageScaling = NSImageScaling.scaleAxesIndependently
button.contentTintColor = .lightGray
if #available(OSX 10.14, *) {
button.contentTintColor = .lightGray
}
button.action = #selector(self.refreshPublicIP)
button.target = self
button.toolTip = localizedString("Refresh")

View File

@@ -32,7 +32,9 @@ class SettingsWindow: NSWindow, NSWindowDelegate {
self.animationBehavior = .default
self.collectionBehavior = .moveToActiveSpace
self.titlebarAppearsTransparent = true
self.appearance = NSAppearance(named: .darkAqua)
if #available(OSX 10.14, *) {
self.appearance = NSAppearance(named: .darkAqua)
}
self.center()
self.setIsVisible(false)
@@ -235,7 +237,9 @@ private class SettingsView: NSView {
button.translatesAutoresizingMaskIntoConstraints = false
button.imageScaling = .scaleNone
button.image = Bundle(for: type(of: self)).image(forResource: image)!
button.contentTintColor = .lightGray
if #available(OSX 10.14, *) {
button.contentTintColor = .lightGray
}
button.isBordered = false
button.action = action
button.target = self

View File

@@ -34,7 +34,9 @@ class UpdateWindow: NSWindow, NSWindowDelegate {
self.animationBehavior = .default
self.collectionBehavior = .transient
self.titlebarAppearsTransparent = true
self.appearance = NSAppearance(named: .darkAqua)
if #available(OSX 10.14, *) {
self.appearance = NSAppearance(named: .darkAqua)
}
self.center()
self.setIsVisible(false)