From 5effa6440aa5c5435641795cc3eae426f66ddd15 Mon Sep 17 00:00:00 2001 From: Serhiy Mytrovtsiy Date: Fri, 14 Mar 2025 21:17:23 +0100 Subject: [PATCH] feat: added an option to show ICMP status and latency in the text widget (allows to show ping latency in the menu bar) --- Kit/module/reader.swift | 7 ++++++- Modules/Net/main.swift | 7 +++++++ Modules/Net/settings.swift | 2 ++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/Kit/module/reader.swift b/Kit/module/reader.swift index 8a12d6a8..4e8d5778 100644 --- a/Kit/module/reader.swift +++ b/Kit/module/reader.swift @@ -41,7 +41,12 @@ open class Reader: NSObject, ReaderInternal_p { public var log: NextLog { NextLog.shared.copy(category: "\(String(describing: self))") } - public var value: T? + private let valueQueue = DispatchQueue(label: "eu.exelban.readerActiveQueue") + private var _value: T? + public var value: T? { + get { self.valueQueue.sync { self._value } } + set { self.valueQueue.sync { self._value = newValue } } + } public var name: String { String(NSStringFromClass(type(of: self)).split(separator: ".").last ?? "unknown") } diff --git a/Modules/Net/main.swift b/Modules/Net/main.swift index 9dad744a..5449a9b3 100644 --- a/Modules/Net/main.swift +++ b/Modules/Net/main.swift @@ -294,6 +294,13 @@ public class Network: Module { } case "$type": replacement = value.connectionType?.rawValue ?? "-" + case "$icmp": + guard let connectivity = self.connectivityReader?.value else { return } + switch pair.value { + case "status": replacement = localizedString(connectivity.status ? "UP" : "DOWN") + case "latency": replacement = "\(Int(connectivity.latency)) ms" + default: return + } default: return } diff --git a/Modules/Net/settings.swift b/Modules/Net/settings.swift index da364933..24829e1e 100644 --- a/Modules/Net/settings.swift +++ b/Modules/Net/settings.swift @@ -48,6 +48,8 @@ You can use a combination of any of the variables. There is only one limitation:
  • $download.total: Total amount of data downloaded over the connection.
  • $download: Current download bandwidth used.
  • $type: Type of network connection (e.g., Ethernet, Wi-Fi, Cellular).
  • +
  • $icmp.status: ICMP status.
  • +
  • $icmp.latency: ICMP latency.
  • """