feat: added flag emoji instead of country code in the popup view, and countryCode and flag options to the Text widget (#2916)

This commit is contained in:
Serhiy Mytrovtsiy
2026-02-23 19:26:00 +01:00
parent 3812657460
commit dec8f08749
5 changed files with 24 additions and 3 deletions

View File

@@ -1848,3 +1848,10 @@ public func isWidgetActive(_ defaults: UserDefaults?, _ widgets: [String]) -> Bo
} }
return false 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
}

View File

@@ -275,6 +275,8 @@ public class Network: Module {
case "private": replacement = value.laddr.v4 ?? value.laddr.v6 ?? "-" case "private": replacement = value.laddr.v4 ?? value.laddr.v6 ?? "-"
case "privateV4": replacement = value.laddr.v4 ?? "-" case "privateV4": replacement = value.laddr.v4 ?? "-"
case "privateV6": replacement = value.laddr.v6 ?? "-" 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 default: return
} }
case "$interface": case "$interface":

View File

@@ -525,7 +525,12 @@ internal class Popup: PopupWrapper {
} }
var ip = addr var ip = addr
if let cc = value.raddr.countryCode, !cc.isEmpty { 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 { if self.publicIPv4Field?.stringValue != ip {
self.publicIPv4Field?.stringValue = ip self.publicIPv4Field?.stringValue = ip
@@ -545,7 +550,12 @@ internal class Popup: PopupWrapper {
} }
var ip = addr var ip = addr
if let cc = value.raddr.countryCode { 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 { if self.publicIPv6Field?.stringValue != ip {
self.publicIPv6Field?.stringValue = ip self.publicIPv6Field?.stringValue = ip

View File

@@ -29,6 +29,8 @@ You can use a combination of any of the variables. There is only one limitation:
<li><b>$addr.private</b>: <small>Private/local IP address.</small></li> <li><b>$addr.private</b>: <small>Private/local IP address.</small></li>
<li><b>$addr.privateV4</b>: <small>Private/local IPv4 address.</small></li> <li><b>$addr.privateV4</b>: <small>Private/local IPv4 address.</small></li>
<li><b>$addr.privateV6</b>: <small>Private/local IPv6 address.</small></li> <li><b>$addr.privateV6</b>: <small>Private/local IPv6 address.</small></li>
<li><b>$addr.countryCode</b>: <small>Country code based on the public IP address.</small></li>
<li><b>$addr.flag</b>: <small>Emoji flag based on the country code.</small></li>
<li><b>$interface.displayName</b>: <small>Network interface name.</small></li> <li><b>$interface.displayName</b>: <small>Network interface name.</small></li>
<li><b>$interface.BSDName</b>: <small>BSD name of the network interface.</small></li> <li><b>$interface.BSDName</b>: <small>BSD name of the network interface.</small></li>
<li><b>$interface.address</b>: <small>MAC address of the network interface.</small></li> <li><b>$interface.address</b>: <small>MAC address of the network interface.</small></li>

View File

@@ -1717,7 +1717,7 @@
New, New,
); );
LastSwiftUpdateCheck = 1540; LastSwiftUpdateCheck = 1540;
LastUpgradeCheck = 2610; LastUpgradeCheck = 2620;
ORGANIZATIONNAME = "Serhiy Mytrovtsiy"; ORGANIZATIONNAME = "Serhiy Mytrovtsiy";
TargetAttributes = { TargetAttributes = {
5C22299C29CCB3C400F00E69 = { 5C22299C29CCB3C400F00E69 = {