mirror of
https://github.com/morgan9e/macos-stats
synced 2026-04-15 00:34:08 +09:00
feat: small codebase refactoring (mostly removed unused code and changes in access control)
This commit is contained in:
@@ -24,7 +24,7 @@ public class BatteryWidget: WidgetWrapper {
|
||||
private var _ACStatus: Bool = false
|
||||
private var _optimizedCharging: Bool = false
|
||||
|
||||
public init(title: String, config: NSDictionary?, preview: Bool = false) {
|
||||
public init(title: String, preview: Bool = false) {
|
||||
let widgetTitle: String = title
|
||||
|
||||
super.init(.battery, title: widgetTitle, frame: CGRect(
|
||||
@@ -449,7 +449,7 @@ public class BatteryDetailsWidget: WidgetWrapper {
|
||||
private var percentage: Double? = nil
|
||||
private var time: Int = 0
|
||||
|
||||
public init(title: String, config: NSDictionary?, preview: Bool = false) {
|
||||
public init(title: String, preview: Bool = false) {
|
||||
super.init(.batteryDetails, title: title, frame: CGRect(
|
||||
x: Constants.Widget.margin.x,
|
||||
y: Constants.Widget.margin.y,
|
||||
|
||||
@@ -11,10 +11,10 @@
|
||||
|
||||
import Cocoa
|
||||
|
||||
public class Label: WidgetWrapper {
|
||||
internal class Label: WidgetWrapper {
|
||||
private var label: String
|
||||
|
||||
public init(title: String, config: NSDictionary, preview: Bool = false) {
|
||||
internal init(title: String, config: NSDictionary) {
|
||||
if let title = config["Title"] as? String {
|
||||
self.label = title
|
||||
} else {
|
||||
@@ -56,12 +56,4 @@ public class Label: WidgetWrapper {
|
||||
margin.y += size.height
|
||||
}
|
||||
}
|
||||
|
||||
public func setLabel(_ new: String) {
|
||||
guard self.label != new else { return }
|
||||
self.label = new
|
||||
DispatchQueue.main.async(execute: {
|
||||
self.needsDisplay = true
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,10 +16,6 @@ public class Mini: WidgetWrapper {
|
||||
private var colorState: Color = .monochrome
|
||||
private var alignmentState: String = "left"
|
||||
|
||||
private var labelLayer: CATextLayer? = nil
|
||||
private var valueLayer: CATextLayer? = nil
|
||||
|
||||
private let onlyValueWidth: CGFloat = 40
|
||||
private var colors: [Color] = Color.allCases
|
||||
|
||||
private var _value: Double = 0
|
||||
|
||||
@@ -13,7 +13,6 @@ import Cocoa
|
||||
|
||||
public class SpeedWidget: WidgetWrapper {
|
||||
private var icon: String = "dots"
|
||||
private var state: Bool = false
|
||||
private var valueState: Bool = true
|
||||
private var unitsState: Bool = true
|
||||
private var monochromeState: Bool = false
|
||||
@@ -28,9 +27,6 @@ public class SpeedWidget: WidgetWrapper {
|
||||
|
||||
private var symbols: [String] = ["U", "D"]
|
||||
|
||||
private var uploadField: NSTextField? = nil
|
||||
private var downloadField: NSTextField? = nil
|
||||
|
||||
private var uploadValue: Int64 = 0
|
||||
private var downloadValue: Int64 = 0
|
||||
|
||||
@@ -91,10 +87,6 @@ public class SpeedWidget: WidgetWrapper {
|
||||
self.reverseOrderState = Store.shared.bool(key: "\(self.title)_\(self.type.rawValue)_reverseOrder", defaultValue: self.reverseOrderState)
|
||||
}
|
||||
|
||||
if self.valueState && self.icon != "none" {
|
||||
self.state = true
|
||||
}
|
||||
|
||||
if preview {
|
||||
self.downloadValue = 8947141
|
||||
self.uploadValue = 478678
|
||||
@@ -111,9 +103,9 @@ public class SpeedWidget: WidgetWrapper {
|
||||
var width: CGFloat = 0
|
||||
switch self.modeState {
|
||||
case "oneRow":
|
||||
width = self.drawOneRow(dirtyRect)
|
||||
width = self.drawOneRow()
|
||||
case "twoRows":
|
||||
width = self.drawTwoRows(dirtyRect)
|
||||
width = self.drawTwoRows()
|
||||
default:
|
||||
width = 0
|
||||
}
|
||||
@@ -123,7 +115,7 @@ public class SpeedWidget: WidgetWrapper {
|
||||
|
||||
// MARK: - one row
|
||||
|
||||
private func drawOneRow(_ dirtyRect: NSRect) -> CGFloat {
|
||||
private func drawOneRow() -> CGFloat {
|
||||
var width: CGFloat = Constants.Widget.margin.x
|
||||
let downloadIconColor = self.downloadValue >= 1_024 ? self.downloadColor : self.noActivityColor
|
||||
let uploadIconColor = self.uploadValue >= 1_024 ? self.uploadColor : self.noActivityColor
|
||||
@@ -279,17 +271,17 @@ public class SpeedWidget: WidgetWrapper {
|
||||
|
||||
// MARK: - two rows
|
||||
|
||||
private func drawTwoRows(_ dirtyRect: NSRect) -> CGFloat {
|
||||
private func drawTwoRows() -> CGFloat {
|
||||
var width: CGFloat = 7
|
||||
var x: CGFloat = 7
|
||||
|
||||
switch self.icon {
|
||||
case "dots":
|
||||
self.drawDots(dirtyRect)
|
||||
self.drawDots()
|
||||
case "arrows":
|
||||
self.drawArrows(dirtyRect)
|
||||
self.drawArrows()
|
||||
case "chars":
|
||||
self.drawChars(dirtyRect)
|
||||
self.drawChars()
|
||||
default:
|
||||
x = 0
|
||||
width = 0
|
||||
@@ -335,7 +327,7 @@ public class SpeedWidget: WidgetWrapper {
|
||||
return width
|
||||
}
|
||||
|
||||
private func drawDots(_ dirtyRect: NSRect) {
|
||||
private func drawDots() {
|
||||
let rowHeight: CGFloat = self.frame.height / 2
|
||||
let size: CGFloat = 6
|
||||
let y: CGFloat = (rowHeight-size)/2
|
||||
@@ -353,7 +345,7 @@ public class SpeedWidget: WidgetWrapper {
|
||||
uploadCircle.fill()
|
||||
}
|
||||
|
||||
private func drawArrows(_ dirtyRect: NSRect) {
|
||||
private func drawArrows() {
|
||||
let arrowAngle = CGFloat(Double.pi / 5)
|
||||
let half = self.frame.size.height / 2
|
||||
let scaleFactor = NSScreen.main?.backingScaleFactor ?? 1
|
||||
@@ -394,7 +386,7 @@ public class SpeedWidget: WidgetWrapper {
|
||||
uploadArrow.close()
|
||||
}
|
||||
|
||||
private func drawChars(_ dirtyRect: NSRect) {
|
||||
private func drawChars() {
|
||||
let rowHeight: CGFloat = self.frame.height / 2
|
||||
let downloadY: CGFloat = self.reverseOrderState ? rowHeight+1 : 1
|
||||
let uploadY: CGFloat = self.reverseOrderState ? 1 : rowHeight+1
|
||||
|
||||
@@ -14,7 +14,6 @@ import Cocoa
|
||||
public struct Stack_t: KeyValue_p {
|
||||
public var key: String
|
||||
public var value: String
|
||||
public var additional: Any?
|
||||
|
||||
var index: Int {
|
||||
get {
|
||||
@@ -25,10 +24,9 @@ public struct Stack_t: KeyValue_p {
|
||||
}
|
||||
}
|
||||
|
||||
public init(key: String, value: String, additional: Any? = nil) {
|
||||
public init(key: String, value: String) {
|
||||
self.key = key
|
||||
self.value = value
|
||||
self.additional = additional
|
||||
}
|
||||
}
|
||||
|
||||
@@ -280,7 +278,7 @@ private class OrderTableView: NSView, NSTableViewDelegate, NSTableViewDataSource
|
||||
private let tableView = NSTableView()
|
||||
private var dragDropType = NSPasteboard.PasteboardType(rawValue: "\(Bundle.main.bundleIdentifier!).sensors-row")
|
||||
|
||||
public var reorderCallback: () -> Void = {}
|
||||
fileprivate var reorderCallback: () -> Void = {}
|
||||
private let list: UnsafeMutablePointer<[Stack_t]>
|
||||
|
||||
init(_ list: UnsafeMutablePointer<[Stack_t]>) {
|
||||
@@ -334,7 +332,7 @@ private class OrderTableView: NSView, NSTableViewDelegate, NSTableViewDataSource
|
||||
NotificationCenter.default.removeObserver(self)
|
||||
}
|
||||
|
||||
public func update() {
|
||||
fileprivate func update() {
|
||||
self.tableView.reloadData()
|
||||
}
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ public class Tachometer: WidgetWrapper {
|
||||
|
||||
private let size: CGFloat = Constants.Widget.height - (Constants.Widget.margin.y*2) + (Constants.Widget.margin.x*2)
|
||||
|
||||
public init(title: String, config: NSDictionary?, preview: Bool = false) {
|
||||
public init(title: String, preview: Bool = false) {
|
||||
let widgetTitle: String = title
|
||||
|
||||
super.init(.tachometer, title: widgetTitle, frame: CGRect(
|
||||
|
||||
Reference in New Issue
Block a user