mirror of
https://github.com/morgan9e/macos-stats
synced 2026-04-15 00:34:08 +09:00
feat: add button to reset network usage (#303)
This commit is contained in:
@@ -153,27 +153,48 @@ internal class Popup: NSStackView, Popup_p {
|
||||
}
|
||||
|
||||
private func initDetails() -> NSView {
|
||||
let height: CGFloat = 22*6
|
||||
let view: NSView = NSView(frame: NSRect(x: 0, y: 0, width: self.frame.width, height: height + Constants.Popup.separatorHeight))
|
||||
view.heightAnchor.constraint(equalToConstant: view.bounds.height).isActive = true
|
||||
let view: NSView = NSView(frame: NSRect(x: 0, y: 0, width: self.frame.width, height: 0))
|
||||
let container: NSStackView = NSStackView(frame: NSRect(x: 0, y: 0, width: view.frame.width, height: 0))
|
||||
container.orientation = .vertical
|
||||
container.spacing = 0
|
||||
|
||||
let separator = SeparatorView(LocalizedString("Details"), origin: NSPoint(x: 0, y: height), width: self.frame.width)
|
||||
let container: NSView = NSView(frame: NSRect(x: 0, y: 0, width: self.frame.width, height: separator.frame.origin.y))
|
||||
let row: NSView = NSView(frame: NSRect(x: 0, y: 0, width: view.frame.width, height: Constants.Popup.separatorHeight))
|
||||
|
||||
let button = NSButtonWithPadding()
|
||||
button.frame = CGRect(x: view.frame.width - 18, y: 6, width: 18, height: 18)
|
||||
button.bezelStyle = .regularSquare
|
||||
button.isBordered = false
|
||||
button.imageScaling = NSImageScaling.scaleAxesIndependently
|
||||
button.contentTintColor = .lightGray
|
||||
button.action = #selector(self.resetTotalNetworkUsage)
|
||||
button.target = self
|
||||
button.toolTip = LocalizedString("Reset")
|
||||
button.image = Bundle(for: Module.self).image(forResource: "refresh")!
|
||||
|
||||
row.addSubview(SeparatorView(LocalizedString("Details"), origin: NSPoint(x: 0, y: 0), width: self.frame.width))
|
||||
row.addSubview(button)
|
||||
|
||||
container.addArrangedSubview(row)
|
||||
|
||||
self.totalUploadField = PopupWithColorRow(container, color: NSColor.systemRed, n: 5, title: "\(LocalizedString("Total upload")):", value: "0")
|
||||
self.totalDownloadField = PopupWithColorRow(container, color: NSColor.systemBlue, n: 4, title: "\(LocalizedString("Total download")):", value: "0")
|
||||
|
||||
|
||||
self.interfaceField = PopupRow(container, n: 3, title: "\(LocalizedString("Interface")):", value: LocalizedString("Unknown")).1
|
||||
self.ssidField = PopupRow(container, n: 2, title: "\(LocalizedString("Network")):", value: LocalizedString("Unknown")).1
|
||||
self.macAdressField = PopupRow(container, n: 1, title: "\(LocalizedString("Physical address")):", value: LocalizedString("Unknown")).1
|
||||
self.localIPField = PopupRow(container, n: 0, title: "\(LocalizedString("Local IP")):", value: LocalizedString("Unknown")).1
|
||||
|
||||
|
||||
self.localIPField?.isSelectable = true
|
||||
self.macAdressField?.isSelectable = true
|
||||
|
||||
view.addSubview(separator)
|
||||
view.addSubview(container)
|
||||
|
||||
let h = container.arrangedSubviews.map({ $0.bounds.height }).reduce(0, +)
|
||||
view.setFrameSize(NSSize(width: self.frame.width, height: h))
|
||||
container.setFrameSize(NSSize(width: self.frame.width, height: view.bounds.height))
|
||||
view.heightAnchor.constraint(equalToConstant: view.bounds.height).isActive = true
|
||||
container.heightAnchor.constraint(equalToConstant: view.bounds.height).isActive = true
|
||||
|
||||
return view
|
||||
}
|
||||
|
||||
@@ -431,6 +452,10 @@ internal class Popup: NSStackView, Popup_p {
|
||||
@objc private func refreshPublicIP() {
|
||||
NotificationCenter.default.post(name: .refreshPublicIP, object: nil, userInfo: nil)
|
||||
}
|
||||
|
||||
@objc private func resetTotalNetworkUsage() {
|
||||
NotificationCenter.default.post(name: .resetTotalNetworkUsage, object: nil, userInfo: nil)
|
||||
}
|
||||
}
|
||||
|
||||
public class NetworkProcessView: NSView {
|
||||
|
||||
@@ -72,6 +72,7 @@ internal class UsageReader: Reader<Network_Usage> {
|
||||
}
|
||||
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(refreshPublicIP), name: .refreshPublicIP, object: nil)
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(resetTotalNetworkUsage), name: .resetTotalNetworkUsage, object: nil)
|
||||
}
|
||||
|
||||
public override func read() {
|
||||
@@ -276,6 +277,10 @@ internal class UsageReader: Reader<Network_Usage> {
|
||||
self.getPublicIP()
|
||||
}
|
||||
}
|
||||
|
||||
@objc func resetTotalNetworkUsage() {
|
||||
self.usage.total = (0, 0)
|
||||
}
|
||||
}
|
||||
|
||||
public class ProcessReader: Reader<[Network_Process]> {
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>$(MARKETING_VERSION)</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>243</string>
|
||||
<string>247</string>
|
||||
<key>Description</key>
|
||||
<string>Simple macOS system monitor in your menu bar</string>
|
||||
<key>LSApplicationCategoryType</key>
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
"Statistics" = "Статистика";
|
||||
"Max" = "Макс.";
|
||||
"Min" = "Мин.";
|
||||
"Reset" = "Reset";
|
||||
|
||||
// Alerts
|
||||
"New version available" = "Налична е нова версия";
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
"Statistics" = "Statistiky";
|
||||
"Max" = "Max";
|
||||
"Min" = "Min";
|
||||
"Reset" = "Reset";
|
||||
|
||||
// Alerts
|
||||
"New version available" = "Nová verze k dispozici";
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
"Statistics" = "Statistiken";
|
||||
"Max" = "Max";
|
||||
"Min" = "Min";
|
||||
"Reset" = "Reset";
|
||||
|
||||
// Alerts
|
||||
"New version available" = "Neue Version verfügbar";
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
"Statistics" = "Statistics";
|
||||
"Max" = "Max";
|
||||
"Min" = "Min";
|
||||
"Reset" = "Reset";
|
||||
|
||||
// Alerts
|
||||
"New version available" = "New version available";
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
"Statistics" = "Estadísticas";
|
||||
"Max" = "Max";
|
||||
"Min" = "Min";
|
||||
"Reset" = "Reset";
|
||||
|
||||
// Alerts
|
||||
"New version available" = "Nueva versión disponible";
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
"Statistics" = "Statistiques";
|
||||
"Max" = "Max";
|
||||
"Min" = "Min";
|
||||
"Reset" = "Reset";
|
||||
|
||||
// Alerts
|
||||
"New version available" = "Nouvelle version disponible";
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
"Statistics" = "Statisztikák";
|
||||
"Max" = "Max";
|
||||
"Min" = "Min";
|
||||
"Reset" = "Reset";
|
||||
|
||||
// Alerts
|
||||
"New version available" = "Új verzió érhető el";
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
"Statistics" = "Statistiche";
|
||||
"Max" = "Max";
|
||||
"Min" = "Min";
|
||||
"Reset" = "Reset";
|
||||
|
||||
// Alerts
|
||||
"New version available" = "Nuova versione disponibile";
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
"Statistics" = "統計";
|
||||
"Max" = "Max";
|
||||
"Min" = "Min";
|
||||
"Reset" = "Reset";
|
||||
|
||||
// Alerts
|
||||
"New version available" = "新しいバージョンが利用可能です";
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
"Statistics" = "통계";
|
||||
"Max" = "Max";
|
||||
"Min" = "Min";
|
||||
"Reset" = "Reset";
|
||||
|
||||
// Alerts
|
||||
"New version available" = "새로운 버전을 이용할 수 있습니다";
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
"Statistics" = "Statistikk";
|
||||
"Max" = "Max";
|
||||
"Min" = "Min";
|
||||
"Reset" = "Reset";
|
||||
|
||||
// Alerts
|
||||
"New version available" = "Ny versjon tilgjengelig";
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
"Statistics" = "Statistieken";
|
||||
"Max" = "Maximaal";
|
||||
"Min" = "Min";
|
||||
"Reset" = "Reset";
|
||||
|
||||
// Alerts
|
||||
"New version available" = "Nieuwe versie beschikbaar";
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
"Statistics" = "Statystyki";
|
||||
"Max" = "Max";
|
||||
"Min" = "Min";
|
||||
"Reset" = "Zresetować";
|
||||
|
||||
// Alerts
|
||||
"New version available" = "Nowa wersja dostępna";
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
"Statistics" = "Estatísticas";
|
||||
"Max" = "Max";
|
||||
"Min" = "Min";
|
||||
"Reset" = "Reset";
|
||||
|
||||
// Alerts
|
||||
"New version available" = "Nova versão disponível";
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
"Statistics" = "Estatísticas";
|
||||
"Max" = "Max";
|
||||
"Min" = "Min";
|
||||
"Reset" = "Reset";
|
||||
|
||||
// Alerts
|
||||
"New version available" = "Nova versão disponível";
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
"Statistics" = "Statistici";
|
||||
"Max" = "Max";
|
||||
"Min" = "Min";
|
||||
"Reset" = "Reset";
|
||||
|
||||
// Alerts
|
||||
"New version available" = "Versiune nouă disponibilă";
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
"Statistics" = "Статистика";
|
||||
"Max" = "Max";
|
||||
"Min" = "Min";
|
||||
"Reset" = "Сбросить";
|
||||
|
||||
// Alerts
|
||||
"New version available" = "Доступна новая версия";
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
"Statistics" = "İstatistik";
|
||||
"Max" = "Max";
|
||||
"Min" = "Min";
|
||||
"Reset" = "Reset";
|
||||
|
||||
// Alerts
|
||||
"New version available" = "Yeni versiyon indirilebilir";
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
"Statistics" = "Статистика";
|
||||
"Max" = "Max";
|
||||
"Min" = "Min";
|
||||
"Reset" = "Скинути";
|
||||
|
||||
// Alerts
|
||||
"New version available" = "Доступна нова версія";
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
"Statistics" = "Số liệu thống kê";
|
||||
"Max" = "Tối đa";
|
||||
"Min" = "Tối thiểu";
|
||||
"Reset" = "Reset";
|
||||
|
||||
// Alerts
|
||||
"New version available" = "Phiên bản mới có sẵn";
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
"Statistics" = "统计";
|
||||
"Max" = "最大";
|
||||
"Min" = "最小";
|
||||
"Reset" = "Reset";
|
||||
|
||||
// Alerts
|
||||
"New version available" = "新版本可用";
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
"Statistics" = "統計資料";
|
||||
"Max" = "最大值";
|
||||
"Min" = "最小值";
|
||||
"Reset" = "Reset";
|
||||
|
||||
// Alerts
|
||||
"New version available" = "有新版本可用";
|
||||
|
||||
@@ -254,7 +254,13 @@ public func PopupWithColorRow(_ view: NSView, color: NSColor, n: CGFloat, title:
|
||||
rowView.addSubview(colorView)
|
||||
rowView.addSubview(labelView)
|
||||
rowView.addSubview(valueView)
|
||||
view.addSubview(rowView)
|
||||
|
||||
if let view = view as? NSStackView {
|
||||
rowView.heightAnchor.constraint(equalToConstant: rowView.bounds.height).isActive = true
|
||||
view.addArrangedSubview(rowView)
|
||||
} else {
|
||||
view.addSubview(rowView)
|
||||
}
|
||||
|
||||
return valueView
|
||||
}
|
||||
|
||||
@@ -165,4 +165,5 @@ public extension Notification.Name {
|
||||
static let changeCronInterval = Notification.Name("changeCronInterval")
|
||||
static let clickInSettings = Notification.Name("clickInSettings")
|
||||
static let refreshPublicIP = Notification.Name("refreshPublicIP")
|
||||
static let resetTotalNetworkUsage = Notification.Name("resetTotalNetworkUsage")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user