mirror of
https://github.com/shadowsocks/ShadowsocksX-NG.git
synced 2026-11-28 09:13:47 +00:00
ui(app): render command address annotation as menu subtitle for #72
按 ifconfig 同源的 IPv6 类型注记改为次要文本行呈现:
- 菜单项用两个 Text 桥接 NSMenuItem 原生 subtitle(macOS 14+ 官方机制,
Apple adaptive controls technote),主行 {IP} - {name} 不再内联注记
- 选择器下方新增说明行「地址类型:{注记}」——无论菜单桥接行为如何,
当前选中地址的类型始终可见
- TerminalCommandAddress.label 收回纯主行,注记保持独立呈现事实;
地址身份与命令内容不受影响
This commit is contained in:
@@ -204,11 +204,17 @@ struct TerminalProxyEnvironmentCard: View {
|
||||
ForEach(
|
||||
control.snapshot.commandAddressPicker.candidates, id: \.identity
|
||||
) { candidate in
|
||||
Text(candidate.label).tag(candidate)
|
||||
menuItemLabel(for: candidate).tag(candidate)
|
||||
}
|
||||
}
|
||||
.pickerStyle(.menu)
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
if let annotation = control.snapshot.commandAddressPicker.selected.annotation {
|
||||
Text("地址类型:\(annotation)")
|
||||
.font(.caption)
|
||||
.foregroundStyle(.secondary)
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
}
|
||||
}
|
||||
commandButton(for: .zshBash)
|
||||
commandButton(for: .fish)
|
||||
@@ -232,6 +238,16 @@ struct TerminalProxyEnvironmentCard: View {
|
||||
set: { address in control.selectCommandAddress(address) })
|
||||
}
|
||||
|
||||
/// 菜单项文案:主行 `{IP} - {name}`;IPv6 类型注记作为第二个 Text——桥接
|
||||
/// 为 NSMenuItem 的原生 subtitle 次行(macOS 14+),注记缺失时仅主行。
|
||||
@ViewBuilder
|
||||
private func menuItemLabel(for candidate: TerminalCommandAddress) -> some View {
|
||||
Text(candidate.label)
|
||||
if let annotation = candidate.annotation {
|
||||
Text(annotation)
|
||||
}
|
||||
}
|
||||
|
||||
private func commandButton(for shell: TerminalCommandShell) -> some View {
|
||||
let isCopied = copiedShell == shell
|
||||
return Button {
|
||||
|
||||
@@ -29,11 +29,9 @@ struct TerminalCommandAddress: Equatable, Hashable, Sendable {
|
||||
TerminalCommandAddressIdentity(bsdName: bsdName, address: address)
|
||||
}
|
||||
|
||||
/// 候选标签:`{IP} - {name}`;带类型注记的 IPv6 为 `{IP} ({注记}) - {name}`。
|
||||
var label: String {
|
||||
let addressPart = annotation.map { "\(address) (\($0))" } ?? address
|
||||
return "\(addressPart) - \(displayName)"
|
||||
}
|
||||
/// 候选主行标签:`{IP} - {name}`;类型注记由呈现层作为菜单项副标题与
|
||||
/// 说明行单独渲染,不进主行。
|
||||
var label: String { "\(address) - \(displayName)" }
|
||||
}
|
||||
|
||||
/// 命令地址身份:BSD 接口名 + 规范化 IP。
|
||||
|
||||
@@ -85,7 +85,7 @@ final class ProxyCommandAddressWorkflowTests: XCTestCase {
|
||||
XCTAssertEqual(picker.selected.address, "127.0.0.1")
|
||||
}
|
||||
|
||||
func testTemporaryIPv6ExcludedAndAnnotationsInLabelMiddle() {
|
||||
func testTemporaryIPv6ExcludedAndAnnotationsKeptAsSeparateFacts() {
|
||||
setListenerMode(.allIPv4AndIPv6Interfaces)
|
||||
interfaceFacts.interfaces = [
|
||||
FakeLocalInterfaceFacts.wifi(
|
||||
@@ -102,14 +102,12 @@ final class ProxyCommandAddressWorkflowTests: XCTestCase {
|
||||
picker.candidates.map(\.address),
|
||||
["127.0.0.1", "::1", "240e::17", "240e::8150"],
|
||||
"RFC 4941 隐私临时地址被过滤(会轮换);其余按地址稳定排序")
|
||||
let secured = picker.candidates.first { $0.address == "240e::8150" }
|
||||
XCTAssertEqual(secured?.label, "240e::8150 - Wi-Fi", "主行标签不含注记")
|
||||
XCTAssertEqual(secured?.annotation, "autoconf secured", "注记作为独立呈现事实")
|
||||
XCTAssertEqual(
|
||||
picker.candidates.first { $0.address == "240e::8150" }?.label,
|
||||
"240e::8150 (autoconf secured) - Wi-Fi",
|
||||
"注记位于标签中间,紧贴其描述的 IP")
|
||||
XCTAssertEqual(
|
||||
picker.candidates.first { $0.address == "240e::17" }?.label,
|
||||
"240e::17 (dynamic) - Wi-Fi",
|
||||
"DHCPv6 地址注记 dynamic")
|
||||
picker.candidates.first { $0.address == "240e::17" }?.annotation,
|
||||
"dynamic", "DHCPv6 地址注记 dynamic")
|
||||
}
|
||||
|
||||
func testIPv6OnlyModeDefaultsToV1AndFiltersFamilies() {
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
| 所有 IPv4 与 IPv6 接口 | IPv4、IPv6,包含两个回环地址 | 127.0.0.1 |
|
||||
| 仅所有 IPv6 接口 | IPv6 | ::1 |
|
||||
|
||||
每项显示 `{IP} - {name}`;带内核标志的 IPv6 地址在 IP 后附与 ifconfig 同源的类型注记,标签为 `{IP} ({注记}) - {name}`(如 `autoconf secured`、`dynamic`),便于识别地址稳定性。接口名称优先取 `SCNetworkInterfaceGetLocalizedDisplayName(interface)`;名称缺失或无法映射到 SystemConfiguration 接口时,回退到 BSD 接口名,但不会因此放宽接口类型过滤。回环项回退名称为 lo0。
|
||||
每项主行显示 `{IP} - {name}`;带内核标志的 IPv6 地址附与 ifconfig 同源的类型注记(如 `autoconf secured`、`dynamic`),呈现为菜单项副标题行(两个 `Text` 桥接为 `NSMenuItem` 的原生 subtitle)与选择器下方的说明行,便于识别地址稳定性。接口名称优先取 `SCNetworkInterfaceGetLocalizedDisplayName(interface)`;名称缺失或无法映射到 SystemConfiguration 接口时,回退到 BSD 接口名,但不会因此放宽接口类型过滤。回环项回退名称为 lo0。
|
||||
|
||||
回环项置顶,双栈时 127.0.0.1 在 ::1 前。其余按接口名称排序,同一接口先 IPv4 后 IPv6,再按地址稳定排序。同一接口的重复 IP 合并;不同接口即使 IP 相同也保留接口身份。
|
||||
|
||||
|
||||
Reference in New Issue
Block a user