mirror of
https://github.com/shadowsocks/ShadowsocksX-NG.git
synced 2026-11-23 14:24:12 +00:00
feat(ng2): window title follows active destination
- window.title tracks the destination via composition-root wiring into WorkspaceWindowOpeningAdapter.bindTitle; drop the static "ShadowsocksX-NG 2.0" title - delete the 28pt shell destinationHeader; subscription and diagnostics actions move into the unified toolbar - settings save/reset stay with the form as a top action row in SettingsView; form-level commit actions read wrong in a toolbar
This commit is contained in:
@@ -3,7 +3,7 @@ import SwiftUI
|
||||
/// 主窗口诊断区(spec #21 D11,issue #34/#43,地图 #52 票 #58):按原型重排
|
||||
/// 为状态摘要卡(代理状态、活动目标)+ 日志卡(GUI 事件流实时呈现 + wrapper
|
||||
/// 收敛日志尾部,来源切换 segmented、可复制)+ 底部脱敏说明行。导出诊断动作
|
||||
/// 在分区头动作槽位(由主窗口壳提供,保持 DiagnosticReportExportAction 既有
|
||||
/// 在窗口工具栏(由主窗口壳提供,保持 DiagnosticReportExportAction 既有
|
||||
/// 入口)。事实采样、轮询代际与报告准备全部经 DiagnosticsWorkflow(issue #43
|
||||
/// 的唯一 UI-facing seam);本视图只负责生命周期触发、呈现与复制动作。
|
||||
struct DiagnosticsView: View {
|
||||
|
||||
@@ -136,8 +136,7 @@ private struct AppComposition {
|
||||
loginController: loginController,
|
||||
clipboard: textClipboard,
|
||||
diagnosticReportExporter: diagnosticReportExporter)
|
||||
let windowOpening = WorkspaceWindowOpeningAdapter(
|
||||
makeContentView: { NSHostingView(rootView: workspaceContent) })
|
||||
let windowOpening = makeWindowOpening(content: workspaceContent, route: workspaceRoute)
|
||||
return AppComposition(
|
||||
controller: controller,
|
||||
catalogWorkflow: catalogWorkflow,
|
||||
@@ -151,6 +150,18 @@ private struct AppComposition {
|
||||
windowOpening: windowOpening)
|
||||
}
|
||||
|
||||
/// 主窗口开窗器装配:AppKit 直控窗口(见 adapter 文档),窗口标题跟随当前
|
||||
/// 分区(首页/服务器/订阅/设置/诊断)——组合根一次性接线,@Published 订阅
|
||||
/// 立即发出当前值,开窗前即完成标题缓存。
|
||||
private static func makeWindowOpening(
|
||||
content: MainWindowView, route: WorkspaceRoute
|
||||
) -> WorkspaceWindowOpeningAdapter {
|
||||
let windowOpening = WorkspaceWindowOpeningAdapter(
|
||||
makeContentView: { NSHostingView(rootView: content) })
|
||||
windowOpening.bindTitle(route.$destination.map(\.label).eraseToAnyPublisher())
|
||||
return windowOpening
|
||||
}
|
||||
|
||||
/// 目录工作流接线(issue #40/#41/#49):提交协调器与生产运行时适配器在此
|
||||
/// 一次性装配;Legacy 导入后的 2.0 运行时边界同为一次性注入。
|
||||
private static func makeCatalogWorkflow(
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
import SwiftUI
|
||||
|
||||
/// 主窗口外壳(地图 #52,票 #53):NavigationSplitView 侧栏承载五项导航与
|
||||
/// 底部常驻代理状态卡;详情区按 route destination 承载各分区视图,顶部是
|
||||
/// 系统设置风格的分区大标题(动作槽位留给各分区票填充)。路由状态仍由
|
||||
/// 底部常驻代理状态卡;详情区按 route destination 承载各分区视图。分区大
|
||||
/// 标题由窗口标题承担(组合根把 destination label 推给开窗器,见
|
||||
/// WorkspaceWindowOpeningAdapter.bindTitle);订阅/诊断的页级动作经 .toolbar
|
||||
/// 桥接进窗口工具栏右端(票 #56/#58 的槽位仅呈现位置变化),设置的表单级
|
||||
/// 提交动作在其视图内容顶部(见 SettingsView)。路由状态仍由
|
||||
/// WorkspaceRoute 持有;代理状态卡的开关、模式与摘要只来自代理控制工作流
|
||||
/// 的整体 snapshot(issue #47),与状态菜单同一口径。
|
||||
struct MainWindowView: View {
|
||||
@@ -17,7 +20,7 @@ struct MainWindowView: View {
|
||||
let diagnosticReportExporter: any DiagnosticReportExporter
|
||||
|
||||
@State private var selection: NodeID?
|
||||
/// 分区头动作(票 #56/#58):添加订阅 sheet 与诊断导出的呈现状态由壳持有。
|
||||
/// 分区动作的呈现状态(票 #56/#58):添加订阅 sheet 与诊断导出由壳持有。
|
||||
@State private var showAddSubscription = false
|
||||
@State private var exportedDiagnosticsPath: String?
|
||||
@StateObject private var shellActionErrors = ErrorAlertPresenter()
|
||||
@@ -27,14 +30,14 @@ struct MainWindowView: View {
|
||||
sidebar
|
||||
.navigationSplitViewColumnWidth(min: 200, ideal: 236, max: 300)
|
||||
} detail: {
|
||||
VStack(spacing: 0) {
|
||||
destinationHeader(route.destination.label) {
|
||||
headerActions
|
||||
}
|
||||
destinationView
|
||||
}
|
||||
destinationView
|
||||
}
|
||||
.frame(minWidth: 920, minHeight: 580)
|
||||
.toolbar {
|
||||
ToolbarItemGroup(placement: .primaryAction) {
|
||||
destinationActions
|
||||
}
|
||||
}
|
||||
.sheet(isPresented: $showAddSubscription) {
|
||||
AddSubscriptionSheet(workflow: workflow, errors: shellActionErrors)
|
||||
}
|
||||
@@ -60,32 +63,15 @@ struct MainWindowView: View {
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - 分区标题与动作槽位
|
||||
// MARK: - 分区动作槽位
|
||||
|
||||
/// 分区动作(票 #53/#56/#57):页级动作随 destination 切换,经工具栏桥接
|
||||
/// 出现在窗口工具栏右端;首页/服务器无页级动作。例外:设置的保存/恢复
|
||||
/// 默认是表单级提交动作,由 SettingsView 内容顶部行承载(动作与表单同置,
|
||||
/// 工具栏呈现效果差)。sheet/alert 呈现状态仍由壳持有,本处只负责动作的
|
||||
/// 呈现。
|
||||
@ViewBuilder
|
||||
private func destinationHeader<ActionContent: View>(
|
||||
_ title: String,
|
||||
@ViewBuilder actions: () -> ActionContent
|
||||
) -> some View {
|
||||
VStack(spacing: 0) {
|
||||
HStack(alignment: .center) {
|
||||
Text(title)
|
||||
.font(.system(size: 28, weight: .bold))
|
||||
.lineLimit(1)
|
||||
Spacer(minLength: 16)
|
||||
actions()
|
||||
}
|
||||
.padding(.leading, 28)
|
||||
.padding(.trailing, 32)
|
||||
.padding(.top, 18)
|
||||
.padding(.bottom, 14)
|
||||
Divider()
|
||||
}
|
||||
}
|
||||
|
||||
/// 分区头动作槽位(票 #53/#56/#57):页级动作放在分区大标题右侧。
|
||||
@ViewBuilder
|
||||
private var headerActions: some View {
|
||||
private var destinationActions: some View {
|
||||
switch route.destination {
|
||||
case .subscriptions:
|
||||
HStack(spacing: 8) {
|
||||
@@ -101,23 +87,11 @@ struct MainWindowView: View {
|
||||
}
|
||||
.disabled(workflow.subscriptions.isEmpty)
|
||||
}
|
||||
case .settings:
|
||||
HStack(spacing: 8) {
|
||||
Button("恢复默认") {
|
||||
Task { _ = await settingsWorkflow.reset() }
|
||||
}
|
||||
.disabled(settingsWorkflow.isCommitting)
|
||||
Button(settingsWorkflow.isCommitting ? "保存中…" : "保存设置") {
|
||||
Task { _ = await settingsWorkflow.save() }
|
||||
}
|
||||
.keyboardShortcut(.defaultAction)
|
||||
.disabled(!settingsWorkflow.canSave)
|
||||
}
|
||||
case .diagnostics:
|
||||
Button("导出诊断…", systemImage: "square.and.arrow.up") {
|
||||
exportDiagnostics()
|
||||
}
|
||||
case .home, .servers:
|
||||
case .home, .servers, .settings:
|
||||
EmptyView()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import SwiftUI
|
||||
|
||||
/// 设置分区(issue #33/#44,地图 #52 票 #57):按原型重排为常规 / 代理端点 /
|
||||
/// 高级三张分组卡,行式呈现(主文案 + 次说明 + 行尾控件);保存/恢复默认动作
|
||||
/// 在分区头动作槽位(由主窗口壳提供,确认弹窗仍由本视图的 alert 呈现)。
|
||||
/// 高级三张分组卡,行式呈现(主文案 + 次说明 + 行尾控件);保存/恢复默认是
|
||||
/// 表单级提交动作,固定在本视图内容顶部行(不进窗口工具栏,避免动作与表单
|
||||
/// 脱节),确认弹窗由本视图的 alert 呈现。
|
||||
/// 字段绑定编辑 workflow 的扁平 UI-shaped draft;issues 按字段渲染;端口行读
|
||||
/// typed field state;是否需要确认及摘要来自 seam 的统一事实;登录项开关
|
||||
/// 绑定独立控制器。
|
||||
@@ -11,12 +12,15 @@ struct SettingsView: View {
|
||||
@ObservedObject var loginController: LaunchAtLoginController
|
||||
|
||||
var body: some View {
|
||||
Form {
|
||||
generalSection
|
||||
endpointSection
|
||||
advancedSection
|
||||
VStack(spacing: 0) {
|
||||
commitActionsRow
|
||||
Form {
|
||||
generalSection
|
||||
endpointSection
|
||||
advancedSection
|
||||
}
|
||||
.formStyle(.grouped)
|
||||
}
|
||||
.formStyle(.grouped)
|
||||
.padding(.leading, 20)
|
||||
.padding(.trailing, 24)
|
||||
.onAppear {
|
||||
@@ -36,6 +40,28 @@ struct SettingsView: View {
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - 提交动作行(内容顶部,固定不随表单滚动)
|
||||
|
||||
/// 保存/恢复默认(原壳动作槽位,票 #57):表单级提交动作与表单同置;
|
||||
/// 保存走 Return 默认键位。恢复默认的确认与保存的 PAC 失效确认都经
|
||||
/// pendingConfirmation 由本视图 alert 呈现。
|
||||
private var commitActionsRow: some View {
|
||||
HStack(spacing: 8) {
|
||||
Spacer(minLength: 0)
|
||||
Button("恢复默认") {
|
||||
Task { _ = await workflow.reset() }
|
||||
}
|
||||
.disabled(workflow.isCommitting)
|
||||
Button(workflow.isCommitting ? "保存中…" : "保存设置") {
|
||||
Task { _ = await workflow.save() }
|
||||
}
|
||||
.keyboardShortcut(.defaultAction)
|
||||
.disabled(!workflow.canSave)
|
||||
}
|
||||
.padding(.top, 12)
|
||||
.padding(.bottom, 8)
|
||||
}
|
||||
|
||||
// MARK: - 常规
|
||||
|
||||
private var generalSection: some View {
|
||||
@@ -171,7 +197,7 @@ struct SettingsView: View {
|
||||
.foregroundStyle(.orange)
|
||||
}
|
||||
if workflow.isDirty {
|
||||
Label("存在未保存的修改;点击分区头「保存设置」生效。", systemImage: "pencil")
|
||||
Label("存在未保存的修改;点击顶部「保存设置」生效。", systemImage: "pencil")
|
||||
.font(.footnote)
|
||||
.foregroundStyle(.secondary)
|
||||
}
|
||||
@@ -182,7 +208,7 @@ struct SettingsView: View {
|
||||
|
||||
// MARK: - 呈现组件
|
||||
|
||||
/// 分区头:标题 + 副题 + 可选尾随徽标(票 #57)。
|
||||
/// 分组卡标题行:标题 + 副题 + 可选尾随徽标(票 #57)。
|
||||
private func sectionHeader(_ title: String, subtitle: String, trailing: String? = nil)
|
||||
-> some View
|
||||
{
|
||||
@@ -231,14 +257,6 @@ struct SettingsView: View {
|
||||
|
||||
// MARK: - 确认 alert 呈现(视图只持有呈现状态,事实来自 seam)
|
||||
|
||||
private struct ConfirmationPresentation {
|
||||
let title: String
|
||||
let confirmTitle: String
|
||||
let confirmRole: ButtonRole?
|
||||
let confirm: () -> Void
|
||||
let cancel: () -> Void
|
||||
}
|
||||
|
||||
private func confirmationPresentation(
|
||||
for confirmation: SettingsConfirmation
|
||||
) -> ConfirmationPresentation {
|
||||
@@ -271,6 +289,18 @@ struct SettingsView: View {
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - 确认 alert 呈现(同文件扩展,保持 private 访问)
|
||||
|
||||
extension SettingsView {
|
||||
private struct ConfirmationPresentation {
|
||||
let title: String
|
||||
let confirmTitle: String
|
||||
let confirmRole: ButtonRole?
|
||||
let confirm: () -> Void
|
||||
let cancel: () -> Void
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - 端口行(同文件扩展,保持 private 访问)
|
||||
|
||||
extension SettingsView {
|
||||
|
||||
@@ -2,8 +2,8 @@ import SwiftUI
|
||||
|
||||
/// 订阅分区(spec #21 D11,issue #35/#41,地图 #52 票 #56):每订阅一张卡片
|
||||
/// (图标 + 名称 + 「HTTPS 订阅地址已隐藏」+ 状态徽标 + 更新/重试 + 「…」菜单 +
|
||||
/// 三列元数据 + 脱敏说明行),失败卡警告色描边。添加订阅与更新全部在分区头
|
||||
/// 动作槽位(由主窗口壳提供)。卡片数据来自订阅 projection(非敏感);结构化
|
||||
/// 三列元数据 + 脱敏说明行),失败卡警告色描边。添加订阅与更新全部在窗口
|
||||
/// 工具栏(由主窗口壳提供)。卡片数据来自订阅 projection(非敏感);结构化
|
||||
/// 刷新状态在呈现层本地化(story 42)。
|
||||
struct SubscriptionsView: View {
|
||||
@ObservedObject var workflow: CatalogWorkflow
|
||||
@@ -38,7 +38,7 @@ struct SubscriptionsView: View {
|
||||
if workflow.subscriptions.isEmpty {
|
||||
ContentUnavailableView(
|
||||
"暂无订阅", systemImage: "arrow.triangle.2.circlepath",
|
||||
description: Text("用分区头「添加订阅」粘贴 HTTPS 订阅地址(SIP-008 JSON)")
|
||||
description: Text("用工具栏「添加订阅」粘贴 HTTPS 订阅地址(SIP-008 JSON)")
|
||||
)
|
||||
.allowsHitTesting(false)
|
||||
}
|
||||
@@ -276,7 +276,7 @@ private struct SubscriptionCard: View {
|
||||
}
|
||||
}
|
||||
|
||||
/// 「添加订阅」表单(分区头入口):粘贴 HTTPS 订阅地址;创建后立即首次刷新。
|
||||
/// 「添加订阅」表单(工具栏入口):粘贴 HTTPS 订阅地址;创建后立即首次刷新。
|
||||
struct AddSubscriptionSheet: View {
|
||||
let workflow: CatalogWorkflow
|
||||
let errors: ErrorAlertPresenter
|
||||
|
||||
@@ -72,7 +72,7 @@ struct WorkspaceDiagnosticsView: View {
|
||||
@StateObject private var errors = ErrorAlertPresenter()
|
||||
|
||||
var body: some View {
|
||||
// 导出诊断动作在分区头动作槽位(票 #58);本包装只承载复制错误呈现。
|
||||
// 导出诊断动作在窗口工具栏(票 #58);本包装只承载复制错误呈现。
|
||||
DiagnosticsView(
|
||||
diagnostics: diagnostics,
|
||||
errors: errors,
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import AppKit
|
||||
import Combine
|
||||
import SwiftUI
|
||||
|
||||
/// 组合根持有的 workspace 开窗器:主窗口是 AppKit 拥有的 NSWindow,内容为
|
||||
@@ -13,6 +14,9 @@ final class WorkspaceWindowOpeningAdapter: WorkspaceWindowOpening {
|
||||
static let workspaceWindowID = NSUserInterfaceItemIdentifier("main")
|
||||
|
||||
private var window: NSWindow?
|
||||
/// 当前分区名(组合根经 bindTitle 接线):开窗前先缓存,开窗时应用。
|
||||
private var latestTitle = ""
|
||||
private var titleCancellable: AnyCancellable?
|
||||
private let makeContentView: () -> NSView
|
||||
|
||||
/// 内容视图由组合根惰性构造:主窗口内的 SwiftUI 状态只在首次开窗时创建。
|
||||
@@ -20,6 +24,15 @@ final class WorkspaceWindowOpeningAdapter: WorkspaceWindowOpening {
|
||||
self.makeContentView = makeContentView
|
||||
}
|
||||
|
||||
/// 窗口标题接线(组合根一次性调用):标题跟随当前 workspace destination
|
||||
/// 的分区名,随 workspace 内导航实时变化;订阅生命周期由本 adapter 持有。
|
||||
func bindTitle(_ updates: AnyPublisher<String, Never>) {
|
||||
titleCancellable = updates.sink { [weak self] title in
|
||||
self?.latestTitle = title
|
||||
self?.window?.title = title
|
||||
}
|
||||
}
|
||||
|
||||
func ensureWorkspaceVisible() {
|
||||
NSApp.activate(ignoringOtherApps: true)
|
||||
let window = self.window ?? makeWindow()
|
||||
@@ -31,7 +44,7 @@ final class WorkspaceWindowOpeningAdapter: WorkspaceWindowOpening {
|
||||
contentRect: NSRect(x: 0, y: 0, width: 960, height: 640),
|
||||
styleMask: [.titled, .closable, .miniaturizable, .resizable, .fullSizeContentView],
|
||||
backing: .buffered, defer: false)
|
||||
window.title = "ShadowsocksX-NG 2.0"
|
||||
window.title = latestTitle
|
||||
window.titlebarAppearsTransparent = true
|
||||
window.identifier = Self.workspaceWindowID
|
||||
window.isReleasedWhenClosed = false
|
||||
@@ -41,8 +54,8 @@ final class WorkspaceWindowOpeningAdapter: WorkspaceWindowOpening {
|
||||
// 只装一半——玻璃背景画进内容区顶部而内容不缩进,分区大标题被糊成
|
||||
// 色块。
|
||||
// ② .fullSizeContentView + titlebarAppearsTransparent:侧栏通顶、窗口
|
||||
// 标题呈现在内容区前缘(scene 版外观)。缺省标题栏会把标题挤在
|
||||
// 红绿灯旁截断成「ShadowsocksX-N…」。
|
||||
// 标题(当前分区名)呈现在内容区前缘(scene 版外观)。缺省标题栏会把
|
||||
// 标题挤在红绿灯旁的窄条里。
|
||||
let toolbar = NSToolbar(identifier: "workspace")
|
||||
window.toolbar = toolbar
|
||||
window.toolbarStyle = .unified
|
||||
|
||||
Reference in New Issue
Block a user