mirror of
https://github.com/morgan9e/macos-stats
synced 2026-04-14 00:04:15 +09:00
67 lines
1.9 KiB
Swift
67 lines
1.9 KiB
Swift
//
|
|
// portal.swift
|
|
// GPU
|
|
//
|
|
// Created by Serhiy Mytrovtsiy on 18/02/2023
|
|
// Using Swift 5.0
|
|
// Running on macOS 13.2
|
|
//
|
|
// Copyright © 2023 Serhiy Mytrovtsiy. All rights reserved.
|
|
//
|
|
|
|
import Cocoa
|
|
import Kit
|
|
|
|
public class Portal: NSStackView, Portal_p {
|
|
public var name: String
|
|
|
|
private var circle: HalfCircleGraphView? = nil
|
|
|
|
private var initialized: Bool = false
|
|
|
|
init(_ name: String) {
|
|
self.name = name
|
|
|
|
super.init(frame: NSRect.zero)
|
|
|
|
self.wantsLayer = true
|
|
self.layer?.backgroundColor = NSColor.windowBackgroundColor.cgColor
|
|
self.layer?.cornerRadius = 3
|
|
|
|
self.orientation = .vertical
|
|
self.distribution = .fillEqually
|
|
self.spacing = Constants.Popup.spacing*2
|
|
self.edgeInsets = NSEdgeInsets(
|
|
top: Constants.Popup.spacing*2,
|
|
left: Constants.Popup.spacing*2,
|
|
bottom: 0,
|
|
right: Constants.Popup.spacing*2
|
|
)
|
|
self.addArrangedSubview(PortalHeader(name))
|
|
|
|
self.circle = HalfCircleGraphView()
|
|
self.circle!.toolTip = localizedString("GPU usage")
|
|
self.addArrangedSubview(self.circle!)
|
|
|
|
self.heightAnchor.constraint(equalToConstant: Constants.Popup.portalHeight).isActive = true
|
|
}
|
|
|
|
required init?(coder: NSCoder) {
|
|
fatalError("init(coder:) has not been implemented")
|
|
}
|
|
|
|
public override func updateLayer() {
|
|
self.layer?.backgroundColor = NSColor.windowBackgroundColor.cgColor
|
|
}
|
|
|
|
public func loadCallback(_ value: GPU_Info) {
|
|
DispatchQueue.main.async(execute: {
|
|
if (self.window?.isVisible ?? false) || !self.initialized {
|
|
self.circle?.setValue(value.utilization!)
|
|
self.circle?.setText("\(Int(value.utilization!*100))%")
|
|
self.initialized = true
|
|
}
|
|
})
|
|
}
|
|
}
|