Files
ShadowsocksX-NG/ShadowsocksX-NG2/App/UI/Servers/CatalogNodeDetailView.swift
T
Qiu Yuzhou ba01e305c5 feat(servers): mark groups containing the active target with a hollow bolt
Ancestor groups of the active target now show a hollow bolt beside the
existing filled bolt on the target itself, in the servers tree, the
favorites table and the home target browser; the node detail subtitle
shows "含活动目标". The derivation lives in
CatalogTreeSnapshot.ancestors(of:) so every surface shares one rule
while activeTargetID stays a runtime fact outside the catalog
projection. Groups activated directly keep the filled bolt and leave
their member rows unmarked.
2026-10-20 01:03:54 +08:00

132 lines
5.1 KiB
Swift

import SwiftUI
/// 装配当前节点的详情会话;查询、参数装载与命令均留在共用视图之外。
struct CatalogNodeDetailView: View {
@Environment(\.locale) private var locale
@Environment(\.timeZone) private var timeZone
@ObservedObject var workflow: CatalogWorkflow
@ObservedObject var activation: ActivationFeedbackState
let nodeID: NodeID
let isActiveTarget: Bool
/// 子树含活动目标(严格后代),与行级空心闪电同源判定。
let containsActiveTarget: Bool
let errors: ErrorAlertPresenter
@StateObject private var parameters = ServerDetailParameters()
private var node: CatalogTreeNode? { workflow.tree.node(withID: nodeID) }
private var eligibility: ActivationEligibility? { workflow.activationEligibility(for: nodeID) }
var body: some View {
if let node {
let detail = presentation(for: node)
NodeDetailView(detail: detail) {
Button(
activation.pendingTargetID == nodeID
? String(localized: "激活中…", table: "ServerDetails")
: String(localized: "激活", table: "ServerDetails"),
systemImage: "bolt.fill"
) {
Task { @MainActor in
do {
_ = try await activation.activate(nodeID, via: workflow)
} catch {
// 激活状态记录失败,详情在 feedback 区域显示结果。
}
}
}
.disabled(!(eligibility?.canActivate ?? false) || activation.isPending)
if let subscription = subscriptionSummary(for: node) {
Button(
workflow.refreshingSubscriptionIDs.contains(subscription.id)
? String(localized: "更新中…", table: "ServerDetails")
: String(localized: "更新", table: "ServerDetails"),
systemImage: "arrow.clockwise"
) {
Task { await workflow.refreshSubscription(subscription.id) }
}
.disabled(workflow.refreshingSubscriptionIDs.contains(subscription.id))
}
} secondaryActions: {
if let module = workflow.connectivity {
ConnectivityTestButton(module: module, node: node)
}
Button(
workflow.isFavorite(nodeID)
? String(localized: "取消收藏", table: "ServerDetails")
: String(localized: "收藏", table: "ServerDetails")
) {
do {
try workflow.setFavorite(nodeID, isFavorite: !workflow.isFavorite(nodeID))
} catch {
errors.present(error)
}
}
if !node.isGroup && parameters.failure != nil {
Button(String(localized: "重新加载", table: "ServerDetails")) {
parameters.reload(load: workflow.serverDetailPluginOptions)
}
}
} feedback: {
ActivationDetailFeedbackView(
messages: detail.activationMessages,
completion: activation.completion?.targetID == nodeID ? activation.completion : nil)
if let subscription = subscriptionSummary(for: node) {
SubscriptionRefreshFeedbackView(
isRefreshing: workflow.refreshingSubscriptionIDs.contains(subscription.id),
completion: workflow.subscriptionRefreshCompletions[subscription.id]
)
.id(subscription.id)
}
} propertiesFooter: { group in
if group.id == .subscription,
let fraction = subscriptionSummary(for: node)?.information?.usedFraction
{
ProgressView(value: fraction) {
Text("流量消耗")
} currentValueLabel: {
Text(fraction, format: .percent.precision(.fractionLength(0)))
}
.progressViewStyle(.linear)
.tint(.accentColor)
} else {
nil
}
} supplement: {
if let module = workflow.connectivity {
ConnectivityDetailView(module: module, node: node, workflow: workflow)
}
}
.onAppear {
if !node.isGroup {
parameters.showServer(nodeID, load: workflow.serverDetailPluginOptions)
}
}
.onReceive(workflow.serverDetailChanges) { affected in
parameters.didRefresh(affectedServers: affected, load: workflow.serverDetailPluginOptions)
}
}
}
private func presentation(for node: CatalogTreeNode) -> NodeDetailPresentation {
let server = node.isGroup ? nil : workflow.serverDetailPresentation(for: nodeID)
let subscription = subscriptionSummary(for: node)
var detail = NodeDetailPresentation(
node: node, server: server, eligibility: eligibility, isActiveTarget: isActiveTarget,
containsActiveTarget: containsActiveTarget,
subscription: subscription, locale: locale, timeZone: timeZone)
if let server, server.plugin.selection != .none {
if parameters.failure != nil {
detail.appendPluginParameterFailure()
} else {
detail.appendPluginParameters(parameters.options.rawText)
}
}
return detail
}
private func subscriptionSummary(for node: CatalogTreeNode) -> SubscriptionSummary? {
guard node.isRootSubscriptionGroup else { return nil }
return workflow.subscriptions.first { $0.groupID == node.id }
}
}