diff --git a/Kit/Widgets/NetworkChart.swift b/Kit/Widgets/NetworkChart.swift index 1ebf951d..effbfdaf 100644 --- a/Kit/Widgets/NetworkChart.swift +++ b/Kit/Widgets/NetworkChart.swift @@ -24,7 +24,7 @@ public class NetworkChart: WidgetWrapper { private var chart: NetworkChartView = NetworkChartView( frame: NSRect(x: 0, y: 0, width: 30, height: Constants.Widget.height - (2*Constants.Widget.margin.y)), - num: 60, minMax: false + num: 60, minMax: false, toolTip: false ) private var width: CGFloat { get { diff --git a/Kit/plugins/Charts.swift b/Kit/plugins/Charts.swift index 5ad7179c..3bda89e4 100644 --- a/Kit/plugins/Charts.swift +++ b/Kit/plugins/Charts.swift @@ -300,14 +300,16 @@ public class NetworkChartView: NSView { private var commonScale: Bool = true private var reverseOrder: Bool = false + private var cursorToolTip: Bool = false private var cursor: NSPoint? = nil private var stop: Bool = false - public init(frame: NSRect, num: Int, minMax: Bool = true, outColor: NSColor = .systemRed, inColor: NSColor = .systemBlue) { + public init(frame: NSRect, num: Int, minMax: Bool = true, outColor: NSColor = .systemRed, inColor: NSColor = .systemBlue, toolTip: Bool = false) { self.minMax = minMax self.points = Array(repeating: (0, 0), count: num) self.topColor = inColor self.bottomColor = outColor + self.cursorToolTip = toolTip super.init(frame: frame) self.addTrackingArea(NSTrackingArea( @@ -561,30 +563,36 @@ public class NetworkChartView: NSView { } public override func mouseEntered(with event: NSEvent) { + guard self.cursorToolTip else { return } self.cursor = convert(event.locationInWindow, from: nil) self.needsDisplay = true } public override func mouseMoved(with event: NSEvent) { + guard self.cursorToolTip else { return } self.cursor = convert(event.locationInWindow, from: nil) self.needsDisplay = true } public override func mouseDragged(with event: NSEvent) { + guard self.cursorToolTip else { return } self.cursor = convert(event.locationInWindow, from: nil) self.needsDisplay = true } public override func mouseExited(with event: NSEvent) { + guard self.cursorToolTip else { return } self.cursor = nil self.needsDisplay = true } public override func mouseDown(with: NSEvent) { + guard self.cursorToolTip else { return } self.shadowPoints = self.points self.stop = true } public override func mouseUp(with: NSEvent) { + guard self.cursorToolTip else { return } self.stop = false } } @@ -858,11 +866,11 @@ public class BarChartView: NSView { let value = self.values[i] let color = value.color ?? .controlAccentColor let activeBlockNum = Int(round(value.value*Double(blocks))) - let h = value.value*partitionSize.height + let h = value.value*(partitionSize.height-spacing) - if dirtyRect.height < 30 && h != 0 { + if dirtyRect.height < 30 && h != 0 { let block = NSBezierPath( - roundedRect: NSRect(x: x+spacing, y: 1, width: partitionSize.width-(spacing*2), height: value.value*partitionSize.height), + roundedRect: NSRect(x: x+spacing, y: 1, width: partitionSize.width-(spacing*2), height: h), xRadius: 1, yRadius: 1 ) color.setFill() diff --git a/Modules/CPU/portal.swift b/Modules/CPU/portal.swift index 1cb6bae9..f87bcf04 100644 --- a/Modules/CPU/portal.swift +++ b/Modules/CPU/portal.swift @@ -47,6 +47,8 @@ public class Portal: PortalWrapper { private var pCoresColor: NSColor { self.pCoresColorState.additional as? NSColor ?? NSColor.systemBlue } public override func load() { + self.loadColors() + let view = NSStackView() view.orientation = .horizontal view.distribution = .fillEqually @@ -70,6 +72,14 @@ public class Portal: PortalWrapper { detailsView.heightAnchor.constraint(equalTo: view.heightAnchor).isActive = true } + public func loadColors() { + self.systemColorState = Color.fromString(Store.shared.string(key: "\(self.name)_systemColor", defaultValue: self.systemColorState.key)) + self.userColorState = Color.fromString(Store.shared.string(key: "\(self.name)_userColor", defaultValue: self.userColorState.key)) + self.idleColorState = Color.fromString(Store.shared.string(key: "\(self.name)_idleColor", defaultValue: self.idleColorState.key)) + self.eCoresColorState = Color.fromString(Store.shared.string(key: "\(self.name)_eCoresColor", defaultValue: self.eCoresColorState.key)) + self.pCoresColorState = Color.fromString(Store.shared.string(key: "\(self.name)_pCoresColor", defaultValue: self.pCoresColorState.key)) + } + private func charts() -> NSView { let view = NSStackView() view.orientation = .vertical @@ -145,7 +155,7 @@ public class Portal: PortalWrapper { var usagePerCore: [ColorValue] = [] if let cores = SystemKit.shared.device.info.cpu?.cores, cores.count == value.usagePerCore.count { for i in 0.. NSView { + let view = NSStackView() + view.orientation = .vertical + view.distribution = .fillEqually + view.spacing = Constants.Popup.spacing*2 + view.edgeInsets = NSEdgeInsets( + top: Constants.Popup.spacing*4, + left: Constants.Popup.spacing*4, + bottom: Constants.Popup.spacing*4, + right: Constants.Popup.spacing*4 + ) + + let chart = PieChartView(frame: NSRect.zero, segments: [], drawValue: true) + chart.toolTip = localizedString("Disk usage") + view.addArrangedSubview(chart) + self.circle = chart + + return view } - public func loadCallback(_ value: Double) { + private func details() -> NSView { + let view = NSStackView() + view.orientation = .vertical + view.distribution = .fillEqually + view.spacing = Constants.Popup.spacing*2 + + self.nameField = portalRow(view, title: "\(localizedString("Name")):") + self.usedField = portalRow(view, title: "\(localizedString("Used")):") + self.freeField = portalRow(view, title: "\(localizedString("Free")):") + + let chart = NetworkChartView(frame: NSRect.zero, num: 120, minMax: false, outColor: self.writeColor, inColor: self.readColor) + chart.heightAnchor.constraint(equalToConstant: 26).isActive = true + self.chart = chart + view.addArrangedSubview(chart) + + return view + } + + internal func utilizationCallback(_ value: drive) { DispatchQueue.main.async(execute: { if (self.window?.isVisible ?? false) || !self.initialized { - self.circle?.setValue(value) + self.nameField?.stringValue = value.mediaName + self.usedField?.stringValue = DiskSize(value.size - value.free).getReadableMemory() + self.freeField?.stringValue = DiskSize(value.free).getReadableMemory() + + self.circle?.setValue(value.percentage) self.circle?.setSegments([ - circle_segment(value: value, color: .controlAccentColor) + circle_segment(value: value.percentage, color: self.valueColor) ]) self.initialized = true } }) } + + internal func activityCallback(_ value: drive) { + DispatchQueue.main.async(execute: { + self.chart?.addValue(upload: Double(value.activity.write), download: Double(value.activity.read)) + }) + } } diff --git a/Modules/Net/popup.swift b/Modules/Net/popup.swift index 2b27c22d..20fdf2ff 100644 --- a/Modules/Net/popup.swift +++ b/Modules/Net/popup.swift @@ -174,7 +174,7 @@ internal class Popup: PopupWrapper { let chart = NetworkChartView( frame: NSRect(x: 0, y: 1, width: container.frame.width, height: container.frame.height - 2), - num: 120, outColor: self.uploadColor, inColor: self.downloadColor + num: 120, outColor: self.uploadColor, inColor: self.downloadColor, toolTip: true ) chart.setReverseOrder(self.reverseOrderState) chart.base = self.base