mirror of
https://github.com/shadowsocks/ShadowsocksX-NG.git
synced 2026-11-22 05:25:41 +00:00
App/ 根目录原有 73 个散落源文件,已无法从目录读出任何分组信息。 按「目录即分层」重组为 Composition / Application / Presentation / UI / PlatformEffects / Resources 六个目录,UI 层再按子视图分目录(Workspace、 Home、Servers(含 Plugin)、Subscriptions、Rules、Settings、Diagnostics、 StatusMenu)。纯移动:类型名、模块名与 import 均未改动,App/ 根层不再有 散落文件。 配套改动: - project.yml:Core 测试镜像的 excludes 由裸文件名改为 `**/` 递归形式。 XcodeGen 的 exclude 不跨 `/`,裸名只匹配 App 根层;MainApp.swift 下移后 旧写法会静默失效,把 @main 组合根编进测试镜像。info.path 与 entitlements.path 指向 App/Resources/;并排除 `**/*.md`——App/ 下任何 非源码文件都会被 XcodeGen 收进 Resources 阶段并封进签名后的 bundle。 - SkeletonTests 的架构守卫由「默认扫描全部 App/ + 7 个豁免文件 + 1 个豁免 前缀 + 4 个豁免目录」改为正面圈定 App/UI/,豁免登记全部删除;新增运行时 适配器放进 Application/ 即自动落在扫描范围外,无需再登记。 - README 工程结构说明同步;根 .gitignore 的生成物路径随 Resources/ 归位。 验证:clean build 0 error;task test 1022 用例全通过(含两个架构守卫); task format 无改动(证明纯移动);task lint 与移动前同为 21 条内容型 warning;packaging-gate.sh ALL CHECKS PASSED,确认 plist/entitlements 归位 后签名与 entitlements 语义不变。 注意:迁移时须先删旧的生成物再 xcodegen generate,否则遗留的 App/Info.plist 会被当作普通资源扫进 Resources 阶段。
140 lines
5.0 KiB
Swift
140 lines
5.0 KiB
Swift
import AppKit
|
|
import SwiftUI
|
|
|
|
struct PluginManagementSection: View {
|
|
@ObservedObject var model: PluginManagementModel
|
|
@ObservedObject private var catalog: PluginCatalog
|
|
@State private var editor: PluginEditorSession?
|
|
@State private var removal: PluginCatalogSnapshot.Entry?
|
|
@State private var failure: String?
|
|
|
|
init(model: PluginManagementModel) {
|
|
self.model = model
|
|
catalog = model.catalog
|
|
}
|
|
|
|
var body: some View {
|
|
Section {
|
|
if model.snapshot.mappingsUnreadable {
|
|
Text(PluginManagementCopy.error(PluginMappingError.unreadable))
|
|
.foregroundStyle(.red)
|
|
Button("重试读取") {
|
|
do { try model.retryReading() } catch { failure = PluginManagementCopy.error(error) }
|
|
}
|
|
} else {
|
|
ForEach(model.snapshot.entries, id: \.program) { entry in
|
|
pluginRow(entry)
|
|
}
|
|
HStack {
|
|
Button("新增插件…") { editor = model.beginAdding() }
|
|
Spacer()
|
|
Button("刷新") { model.refresh() }
|
|
}
|
|
}
|
|
} header: {
|
|
Text("插件").font(.headline).padding(.vertical, 2)
|
|
}
|
|
.onAppear { model.refresh() }
|
|
.onReceive(
|
|
NotificationCenter.default.publisher(for: NSApplication.didBecomeActiveNotification)
|
|
) { _ in
|
|
model.refresh()
|
|
}
|
|
.sheet(item: $editor) { session in
|
|
PluginEditorSheet(model: model, session: session)
|
|
}
|
|
.confirmationDialog(
|
|
removalIsOverride ? String(localized: "恢复内置插件?") : String(localized: "删除用户插件?"),
|
|
isPresented: Binding(get: { removal != nil }, set: { if !$0 { removal = nil } }),
|
|
titleVisibility: .visible, presenting: removal
|
|
) { entry in
|
|
Button(
|
|
removalIsOverride ? String(localized: "恢复内置") : String(localized: "删除"),
|
|
role: .destructive
|
|
) {
|
|
do { try model.remove(entry.program) } catch { failure = PluginManagementCopy.error(error) }
|
|
}
|
|
Button("取消", role: .cancel) {}
|
|
} message: { entry in
|
|
Text(
|
|
entry.program + "\n\n"
|
|
+ (removalIsOverride
|
|
? String(localized: "服务器配置将保留,后续连接使用同名内置插件。")
|
|
: String(localized: "服务器配置将保留,使用此名称的服务器可能无法连接。")))
|
|
}
|
|
.alert(
|
|
"插件配置操作失败",
|
|
isPresented: Binding(
|
|
get: { failure != nil }, set: { if !$0 { failure = nil } }
|
|
)
|
|
) {
|
|
Button("确定", role: .cancel) { failure = nil }
|
|
} message: {
|
|
Text(failure ?? "")
|
|
}
|
|
}
|
|
|
|
private var removalIsOverride: Bool {
|
|
removal.map { ManagedPluginCatalog.info(forProgram: $0.program) != nil } ?? false
|
|
}
|
|
|
|
private func pluginRow(_ entry: PluginCatalogSnapshot.Entry) -> some View {
|
|
VStack(alignment: .leading, spacing: 6) {
|
|
HStack(alignment: .top, spacing: 16) {
|
|
VStack(alignment: .leading, spacing: 3) {
|
|
Text(entry.program).font(.body)
|
|
Text(PluginManagementCopy.source(entry)).font(.caption).foregroundStyle(.secondary)
|
|
if let path = entry.path {
|
|
Text(path).font(.caption).foregroundStyle(.secondary)
|
|
.lineLimit(1).truncationMode(.middle).help(path).textSelection(.enabled)
|
|
}
|
|
}
|
|
.frame(maxWidth: .infinity, alignment: .leading)
|
|
if entry.source == .managed {
|
|
Button("覆盖…") { editor = model.beginOverriding(entry.program) }
|
|
} else {
|
|
Button("编辑…") { editor = model.beginEditing(entry.program) }
|
|
Button(
|
|
ManagedPluginCatalog.info(forProgram: entry.program) == nil
|
|
? String(localized: "删除…") : String(localized: "恢复内置…")
|
|
) { removal = entry }
|
|
}
|
|
}
|
|
if let issue = PluginManagementCopy.availability(entry.availability) {
|
|
Label(issue, systemImage: "exclamationmark.triangle.fill")
|
|
.font(.caption).foregroundStyle(.red)
|
|
}
|
|
if entry.source == .user && entry.availability == .available {
|
|
PluginSecurityDetails(facts: catalog.securityFacts[entry.program])
|
|
}
|
|
}
|
|
.padding(.vertical, 4)
|
|
}
|
|
}
|
|
|
|
private struct PluginSecurityDetails: View {
|
|
let facts: PluginSecurityFacts?
|
|
|
|
var body: some View {
|
|
if let facts {
|
|
if let warning = PluginManagementCopy.securitySummary(facts) {
|
|
Label(warning, systemImage: "exclamationmark.triangle")
|
|
.font(.caption).foregroundStyle(.orange)
|
|
}
|
|
DisclosureGroup("安全检查详情") {
|
|
VStack(alignment: .leading, spacing: 3) {
|
|
Text(PluginManagementCopy.quarantine(facts.quarantine))
|
|
Text(PluginManagementCopy.signature(facts.signature))
|
|
Text(PluginManagementCopy.policy(facts.policy))
|
|
Text("检查结果仅供参考,不能保证 macOS 允许或禁止运行。")
|
|
.foregroundStyle(.secondary)
|
|
}
|
|
.frame(maxWidth: .infinity, alignment: .leading)
|
|
}
|
|
.font(.caption)
|
|
} else {
|
|
Text("正在检查安全信息…").font(.caption).foregroundStyle(.secondary)
|
|
}
|
|
}
|
|
}
|