feat: add button to reset network usage (#303)

This commit is contained in:
Serhiy Mytrovtsiy
2021-05-21 21:27:52 +02:00
parent f92edd4851
commit e768a42e12
27 changed files with 69 additions and 10 deletions

View File

@@ -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 {

View File

@@ -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]> {

View File

@@ -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>

View File

@@ -34,6 +34,7 @@
"Statistics" = "Статистика";
"Max" = "Макс.";
"Min" = "Мин.";
"Reset" = "Reset";
// Alerts
"New version available" = "Налична е нова версия";

View File

@@ -34,6 +34,7 @@
"Statistics" = "Statistiky";
"Max" = "Max";
"Min" = "Min";
"Reset" = "Reset";
// Alerts
"New version available" = "Nová verze k dispozici";

View File

@@ -34,6 +34,7 @@
"Statistics" = "Statistiken";
"Max" = "Max";
"Min" = "Min";
"Reset" = "Reset";
// Alerts
"New version available" = "Neue Version verfügbar";

View File

@@ -34,6 +34,7 @@
"Statistics" = "Statistics";
"Max" = "Max";
"Min" = "Min";
"Reset" = "Reset";
// Alerts
"New version available" = "New version available";

View File

@@ -34,6 +34,7 @@
"Statistics" = "Estadísticas";
"Max" = "Max";
"Min" = "Min";
"Reset" = "Reset";
// Alerts
"New version available" = "Nueva versión disponible";

View File

@@ -34,6 +34,7 @@
"Statistics" = "Statistiques";
"Max" = "Max";
"Min" = "Min";
"Reset" = "Reset";
// Alerts
"New version available" = "Nouvelle version disponible";

View File

@@ -34,6 +34,7 @@
"Statistics" = "Statisztikák";
"Max" = "Max";
"Min" = "Min";
"Reset" = "Reset";
// Alerts
"New version available" = "Új verzió érhető el";

View File

@@ -34,6 +34,7 @@
"Statistics" = "Statistiche";
"Max" = "Max";
"Min" = "Min";
"Reset" = "Reset";
// Alerts
"New version available" = "Nuova versione disponibile";

View File

@@ -34,6 +34,7 @@
"Statistics" = "統計";
"Max" = "Max";
"Min" = "Min";
"Reset" = "Reset";
// Alerts
"New version available" = "新しいバージョンが利用可能です";

View File

@@ -34,6 +34,7 @@
"Statistics" = "통계";
"Max" = "Max";
"Min" = "Min";
"Reset" = "Reset";
// Alerts
"New version available" = "새로운 버전을 이용할 수 있습니다";

View File

@@ -34,6 +34,7 @@
"Statistics" = "Statistikk";
"Max" = "Max";
"Min" = "Min";
"Reset" = "Reset";
// Alerts
"New version available" = "Ny versjon tilgjengelig";

View File

@@ -34,6 +34,7 @@
"Statistics" = "Statistieken";
"Max" = "Maximaal";
"Min" = "Min";
"Reset" = "Reset";
// Alerts
"New version available" = "Nieuwe versie beschikbaar";

View File

@@ -34,6 +34,7 @@
"Statistics" = "Statystyki";
"Max" = "Max";
"Min" = "Min";
"Reset" = "Zresetować";
// Alerts
"New version available" = "Nowa wersja dostępna";

View File

@@ -34,6 +34,7 @@
"Statistics" = "Estatísticas";
"Max" = "Max";
"Min" = "Min";
"Reset" = "Reset";
// Alerts
"New version available" = "Nova versão disponível";

View File

@@ -34,6 +34,7 @@
"Statistics" = "Estatísticas";
"Max" = "Max";
"Min" = "Min";
"Reset" = "Reset";
// Alerts
"New version available" = "Nova versão disponível";

View File

@@ -34,6 +34,7 @@
"Statistics" = "Statistici";
"Max" = "Max";
"Min" = "Min";
"Reset" = "Reset";
// Alerts
"New version available" = "Versiune nouă disponibilă";

View File

@@ -34,6 +34,7 @@
"Statistics" = "Статистика";
"Max" = "Max";
"Min" = "Min";
"Reset" = "Сбросить";
// Alerts
"New version available" = "Доступна новая версия";

View File

@@ -34,6 +34,7 @@
"Statistics" = "İstatistik";
"Max" = "Max";
"Min" = "Min";
"Reset" = "Reset";
// Alerts
"New version available" = "Yeni versiyon indirilebilir";

View File

@@ -34,6 +34,7 @@
"Statistics" = "Статистика";
"Max" = "Max";
"Min" = "Min";
"Reset" = "Скинути";
// Alerts
"New version available" = "Доступна нова версія";

View File

@@ -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";

View File

@@ -34,6 +34,7 @@
"Statistics" = "统计";
"Max" = "最大";
"Min" = "最小";
"Reset" = "Reset";
// Alerts
"New version available" = "新版本可用";

View File

@@ -34,6 +34,7 @@
"Statistics" = "統計資料";
"Max" = "最大值";
"Min" = "最小值";
"Reset" = "Reset";
// Alerts
"New version available" = "有新版本可用";

View File

@@ -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
}

View File

@@ -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")
}