Mac 原生系统通知 + 接收目录可配(Phase 4b·1)
- MacNotifier:窗口非前台(!NSApp.isActive)时对「收到消息 / 收到文件」发原生系统通知(UNUserNotificationCenter,授权已由引擎启动的 PushRegistry.requestAuthorizationAndRegister 一并请求)。对齐桌面 app.ShowNotification——前台事件由应用内 NoticeOverlay / 未读红点负责,仅 app 非活跃才发系统通知,避免与应用内提示重复。引擎 handleNotify 的 "message"(新到对端消息,非当前会话)+ "transferDone"(incoming 且 completed)两处加 macOS 挂钩 - 接收目录可配:DownloadManager.downloadDir 在 macOS 读 UserDefaults macDownloadDir(设置页 NSOpenPanel 选目录),未配 / 目录已失效则回退系统「下载」目录(比「文稿」更符桌面直觉);iOS 仍固定沙盒 Documents。设置加「接收」区(显示当前保存目录 + 选择目录…)。非沙盒构建用普通路径即可;沙盒分发(Phase 6)须改安全作用域书签 - 验证:just mac-build(CommilitiaDropMac.app)+ iOS 模拟器(CommilitiaDrop.app)均 BUILD SUCCEEDED
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
#if os(macOS)
|
||||
import AppKit
|
||||
import SwiftUI
|
||||
|
||||
// 桌面根界面:NavigationSplitView 侧栏(传输 / 文件 / 消息 / 设备 / 设置)+ 详情 NavigationStack,
|
||||
@@ -210,6 +211,7 @@ 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 = ""
|
||||
@State private var nameDraft = DeviceNameStore.value
|
||||
|
||||
private var signalingLabel: String
|
||||
@@ -245,6 +247,11 @@ struct MacSettingsView: View
|
||||
Button("上传本机剪贴板") { engine.uploadClipboard() }
|
||||
Button("拉取云剪贴板到本机") { engine.pullClipboard() }
|
||||
}
|
||||
Section("接收")
|
||||
{
|
||||
LabeledContent("保存到", value: downloadDirDisplay)
|
||||
Button("选择目录…") { pickDownloadDir() }
|
||||
}
|
||||
Section("引擎")
|
||||
{
|
||||
LabeledContent("状态", value: engine.status)
|
||||
@@ -280,5 +287,23 @@ struct MacSettingsView: View
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user