Files
Commilitia-Drop/ios/CDrop/MacApp/MacRootView.swift
T
admin f7b0f04c9c 修 ultracode 扫描确认的 Quick Send 关窗静默失效 + 设备判本机回落
- Quick Send 关主窗口静默失效(ultracode medium,对抗核验为真):MacQuickSend.trigger 只写 pending,而观察 pending 弹发送表单的逻辑全挂在 MacRootView——后台 / 菜单栏常驻(关主窗口、隐藏 Dock)时 MacRootView 未挂载,选完文件无表单、零反馈,正是 Quick Send 的首要场景。修:MacQuickSend 改为自持独立 NSWindow(NSHostingController 托 MacComposeSheet)呈现发送面板,不依赖主窗口——关窗 / 隐藏 Dock 态下热键 ⌃⌥⌘S 与菜单栏「快速发送文件…」均正常。MacRootView 移除 pending 的 onChange + sheet(不再需要)
- 设备判本机回落(ultracode 核验 real=false,Mac 上不可达;作防御性对齐 iOS):MacDevicesView.others 由只比 deviceID != selfDeviceID 改为 isSelf——selfDeviceID 非空按 device_id 判、缺失回落按设备名(对齐 iOS isSelf),防边角态下本机误入「其他设备」列表被右键「移除」而吊销自身会话
- 未改:Keychain ad-hoc 重编后 ACL 失效(ultracode low)——纯本地开发内环摩擦(改一行重编即换 cdhash),Phase 6 Developer ID 稳定签名后自消,对最终用户零影响、无安全/正确性后果
- 扫描结论:6 维度里剪贴板安全 / iOS 回归 / 共享 JS 变更 / 后台生命周期 四项 finder 零发现(对抗核验通过);仅 mac-features + auth-build-config 各出一条,核验为真 2 条(本次修 1 + 防御 1)、驳回 1
- 验证:just mac-build(CommilitiaDropMac.app)BUILD SUCCEEDED;iOS 无关(仅改 macOS-only 文件)
2026-07-11 12:49:42 +08:00

314 lines
11 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#if os(macOS)
import AppKit
import SwiftUI
// NavigationSplitView / / / / + NavigationStack
// iOS WebView iOS RootView / /
// Phase 3b iOS / presence / / 3a
// i18nt() Phase 3b
struct MacRootView: View
{
@Environment(EngineController.self) private var engine
@Environment(AuthManager.self) private var auth
@State private var selection: MacSection = .transfers
var body: some View
{
NavigationSplitView
{
List(selection: $selection)
{
brandHeader
.listRowInsets(EdgeInsets(top: 10, leading: 8, bottom: 14, trailing: 8))
.listRowSeparator(.hidden)
.selectionDisabled()
Section
{
ForEach(MacSection.sidebar)
{ section in
Label(section.title, systemImage: section.icon)
.badge(badge(for: section))
.tag(section)
}
}
}
.navigationSplitViewColumnWidth(min: 200, ideal: 220, max: 280)
.navigationTitle("Commilitia Drop")
}
detail:
{
NavigationStack
{
detail
}
}
// WebView App MacBackgroundController
// WebView monitor /
// / App Nap MacBackgroundController
// / / / iOS RootView
.overlay(alignment: .top)
{
NoticeOverlay()
}
// Quick Send / MacQuickSend
}
@ViewBuilder
private var detail: some View
{
switch selection
{
case .transfers:
MacTransfersView()
case .files:
MacFilesView()
case .messages:
MacMessagesView()
case .devices:
MacDevicesView()
case .settings:
MacSettingsView()
}
}
private var brandHeader: some View
{
HStack(spacing: 10)
{
Image(systemName: "paperplane.fill")
.font(.title2)
.foregroundStyle(.tint)
Text("Commilitia Drop")
.font(.title3.weight(.semibold))
.lineLimit(1)
}
}
// / iOS RootView badge
private func badge(for section: MacSection) -> Int
{
switch section
{
case .messages: return engine.unreadMessages
case .transfers: return engine.unreadTransfers
default: return 0
}
}
}
// iOS / / / /
enum MacSection: Hashable, Identifiable, CaseIterable
{
case transfers, files, messages, devices, settings
var id: Self { self }
var title: String
{
switch self
{
case .transfers: return "传输"
case .files: return "文件"
case .messages: return "消息"
case .devices: return "设备"
case .settings: return "设置"
}
}
var icon: String
{
switch self
{
case .transfers: return "arrow.up.arrow.down"
case .files: return "folder"
case .messages: return "bubble.left.and.bubble.right"
case .devices: return "laptopcomputer.and.iphone"
case .settings: return "gearshape"
}
}
static var sidebar: [MacSection] { MacSection.allCases }
}
// presence + 线 +
struct MacDevicesView: View
{
@Environment(EngineController.self) private var engine
@State private var revokeTarget: DeviceItem?
private var others: [DeviceItem]
{
engine.devices.filter { !isSelf($0) }
}
// device_idselfDeviceID iOS isSelf
//
private func isSelf(_ dev: DeviceItem) -> Bool
{
let selfID = engine.selfDeviceID
if !selfID.isEmpty, !dev.deviceID.isEmpty { return dev.deviceID == selfID }
return dev.name == engine.deviceName
}
var body: some View
{
Group
{
if others.isEmpty
{
ContentUnavailableView("暂无其他设备", systemImage: "laptopcomputer.and.iphone",
description: Text("同账户的其他设备将显示在此。"))
}
else
{
List(others)
{ dev in
HStack(spacing: 10)
{
Image(systemName: macDeviceSymbol(dev.type))
.foregroundStyle(dev.online ? Color.green : Color.secondary)
VStack(alignment: .leading, spacing: 2)
{
Text(dev.name)
Text(dev.online ? "在线" : "离线")
.font(.caption)
.foregroundStyle(.secondary)
}
Spacer()
}
.contextMenu
{
Button("移除设备", role: .destructive) { revokeTarget = dev }
}
}
}
}
.navigationTitle("设备")
.confirmationDialog("移除该设备?",
isPresented: Binding(get: { revokeTarget != nil },
set: { if !$0 { revokeTarget = nil } }),
presenting: revokeTarget)
{ dev in
Button("移除 \(dev.name)", role: .destructive) { engine.revokeDevice(dev.deviceID) }
Button("取消", role: .cancel) {}
}
message:
{ dev in
Text("将吊销 \(dev.name) 的登录,该设备需重新登录。")
}
}
}
// + + + + +
struct MacSettingsView: View
{
@Environment(EngineController.self) private var engine
@Environment(AuthManager.self) private var auth
@AppStorage("macClipboardAutoSync") private var autoSync = true
@AppStorage("macDownloadDir") private var downloadDirPath = ""
@AppStorage("macHideDock") private var hideDock = false
@State private var nameDraft = DeviceNameStore.value
private var signalingLabel: String
{
if engine.hubConnected { return "已连接" }
if engine.hubReconnecting { return "重连中…" }
return "未连接"
}
var body: some View
{
Form
{
Section("账号")
{
LabeledContent("用户", value: auth.session?.user.name ?? "")
HStack
{
TextField("本机设备名", text: $nameDraft)
.onSubmit { commitRename() }
Button("保存") { commitRename() }
.disabled(nameDraft.trimmingCharacters(in: .whitespaces).isEmpty)
}
Button("登出", role: .destructive)
{
// App MacBackgroundController nil
auth.logout()
}
}
Section("云剪贴板")
{
Toggle("自动同步本机复制(上行)", isOn: $autoSync)
.onChange(of: autoSync) { MacBackgroundController.shared.refreshClipboardMonitor() }
Button("上传本机剪贴板") { engine.uploadClipboard() }
Button("拉取云剪贴板到本机") { engine.pullClipboard() }
}
Section("后台")
{
Toggle("隐藏 Dock 图标(仅菜单栏常驻)", isOn: $hideDock)
.onChange(of: hideDock) { MacBackgroundController.shared.applyDockPolicy() }
Text("关闭主窗口后仍在菜单栏后台运行、持续同步;点菜单栏图标可重开窗口。")
.font(.caption)
.foregroundStyle(.secondary)
}
Section("接收")
{
LabeledContent("保存到", value: downloadDirDisplay)
Button("选择目录…") { pickDownloadDir() }
}
Section("引擎")
{
LabeledContent("状态", value: engine.status)
LabeledContent("信令", value: signalingLabel)
LabeledContent("在线设备", value: "\(engine.presenceCount)")
}
Section("引擎日志")
{
if engine.logs.isEmpty
{
Text("暂无日志").foregroundStyle(.secondary)
}
else
{
ForEach(engine.logs.prefix(30))
{ entry in
Text(entry.message)
.font(.caption.monospaced())
.foregroundStyle(.secondary)
.lineLimit(2)
.textSelection(.enabled)
}
}
}
}
.formStyle(.grouped)
.navigationTitle("设置")
}
private func commitRename()
{
let name = nameDraft.trimmingCharacters(in: .whitespacesAndNewlines)
guard !name.isEmpty else { return }
engine.renameSelf(to: name)
}
private var downloadDirDisplay: String
{
downloadDirPath.isEmpty ? "下载(默认)" : (downloadDirPath as NSString).abbreviatingWithTildeInPath
}
private func pickDownloadDir()
{
let panel = NSOpenPanel()
panel.canChooseFiles = false
panel.canChooseDirectories = true
panel.allowsMultipleSelection = false
panel.prompt = "选择"
if panel.runModal() == .OK, let url = panel.url
{
downloadDirPath = url.path
}
}
}
#endif