From dec8f0874962048c1af0bf476b9a0bf3dff2589e Mon Sep 17 00:00:00 2001 From: Serhiy Mytrovtsiy Date: Mon, 23 Feb 2026 19:26:00 +0100 Subject: [PATCH] feat: added flag emoji instead of country code in the popup view, and countryCode and flag options to the Text widget (#2916) --- Kit/helpers.swift | 7 +++++++ Modules/Net/main.swift | 2 ++ Modules/Net/popup.swift | 14 ++++++++++++-- Modules/Net/settings.swift | 2 ++ Stats.xcodeproj/project.pbxproj | 2 +- 5 files changed, 24 insertions(+), 3 deletions(-) diff --git a/Kit/helpers.swift b/Kit/helpers.swift index af3a6de1..473a91ae 100644 --- a/Kit/helpers.swift +++ b/Kit/helpers.swift @@ -1848,3 +1848,10 @@ public func isWidgetActive(_ defaults: UserDefaults?, _ widgets: [String]) -> Bo } return false } + +public func countryFlag(_ code: String) -> String? { + let uppercased = code.uppercased() + guard uppercased.count == 2 else { return nil } + let scalars = uppercased.unicodeScalars.compactMap { UnicodeScalar(127397 + $0.value) } + return scalars.count == 2 ? String(String.UnicodeScalarView(scalars)) : nil +} diff --git a/Modules/Net/main.swift b/Modules/Net/main.swift index 60be30f5..bb1a47d0 100644 --- a/Modules/Net/main.swift +++ b/Modules/Net/main.swift @@ -275,6 +275,8 @@ public class Network: Module { case "private": replacement = value.laddr.v4 ?? value.laddr.v6 ?? "-" case "privateV4": replacement = value.laddr.v4 ?? "-" case "privateV6": replacement = value.laddr.v6 ?? "-" + case "countryCode": replacement = value.raddr.countryCode ?? "-" + case "flag": replacement = value.raddr.countryCode != nil ? countryFlag(value.raddr.countryCode!) : "-" default: return } case "$interface": diff --git a/Modules/Net/popup.swift b/Modules/Net/popup.swift index 4815c943..d9007fa8 100644 --- a/Modules/Net/popup.swift +++ b/Modules/Net/popup.swift @@ -525,7 +525,12 @@ internal class Popup: PopupWrapper { } var ip = addr if let cc = value.raddr.countryCode, !cc.isEmpty { - ip += " (\(cc))" + if let flag = countryFlag(cc) { + ip += " \(flag)" + } else { + ip += " (\(cc))" + } + self.publicIPv4Field?.toolTip = cc } if self.publicIPv4Field?.stringValue != ip { self.publicIPv4Field?.stringValue = ip @@ -545,7 +550,12 @@ internal class Popup: PopupWrapper { } var ip = addr if let cc = value.raddr.countryCode { - ip += " (\(cc))" + if let flag = countryFlag(cc) { + ip += " \(flag)" + } else { + ip += " (\(cc))" + } + self.publicIPv6Field?.toolTip = cc } if self.publicIPv6Field?.stringValue != ip { self.publicIPv6Field?.stringValue = ip diff --git a/Modules/Net/settings.swift b/Modules/Net/settings.swift index 05c4b35b..15e4bc12 100644 --- a/Modules/Net/settings.swift +++ b/Modules/Net/settings.swift @@ -29,6 +29,8 @@ You can use a combination of any of the variables. There is only one limitation:
  • $addr.private: Private/local IP address.
  • $addr.privateV4: Private/local IPv4 address.
  • $addr.privateV6: Private/local IPv6 address.
  • +
  • $addr.countryCode: Country code based on the public IP address.
  • +
  • $addr.flag: Emoji flag based on the country code.
  • $interface.displayName: Network interface name.
  • $interface.BSDName: BSD name of the network interface.
  • $interface.address: MAC address of the network interface.
  • diff --git a/Stats.xcodeproj/project.pbxproj b/Stats.xcodeproj/project.pbxproj index 2359aec1..6666632a 100644 --- a/Stats.xcodeproj/project.pbxproj +++ b/Stats.xcodeproj/project.pbxproj @@ -1717,7 +1717,7 @@ New, ); LastSwiftUpdateCheck = 1540; - LastUpgradeCheck = 2610; + LastUpgradeCheck = 2620; ORGANIZATIONNAME = "Serhiy Mytrovtsiy"; TargetAttributes = { 5C22299C29CCB3C400F00E69 = {