44096069a7
- 发送端流式(R-iOS-4):新增 FileSource 抽象(web/src/features/transfer/source.ts),iOS 经 HTTP Range 惰性拉取(原生 WKURLSchemeHandler 认 Range 头 seek 回 206),整文件不进 WebView 内存;web/桌面经 fileSource 包装字节不变。p2p/relay/transfer 改吃 FileSource - 后台续传:iOS 26 BGContinuedProcessingTask(BackgroundTaskManager + AppDelegate 注册 + BGTaskSchedulerPermittedIdentifiers),引擎传输进度驱动系统进度 UI - APNs:后端 internal/apns(ES256 .p8 JWT + HTTP/2,仿 internal/push)+ push_subscriptions.platform 列 + POST /api/push/apns/register + transfer/message 未投递分支分流;原生 PushRegistry 授权 + 设备令牌经引擎桥 registerPush 上报;aps-environment + remote-notification 后台模式 - Share Extension:CDropShare appex 抓文件 → App Group 收件箱 → cdrop://share 深链唤主程序选设备发送(只交接、不跑引擎) - 控制中心剪贴板两控件:CDropWidgets widgetkit appex(ControlWidget + AppIntent + 纯原生 ClipboardClient REST);用专用 broker 设备会话(主程序经引擎 provisionWidgetSession 代铸独立 device_id 会话存 App Group,控件自刷不与引擎抢 refresh 轮换) - 真机分发预备:committed 签名改 ad-hoc 使模拟器 entitlement 生效;真机手动签名 scaffold(Signing.xcconfig 仅 device SDK 套 Manual + gitignore 的 Local.xcconfig 填 Team/profile)+ just ios-device / ios-devices 全 CLI 装机;包名改 net.commilitia.Commilitia-Drop(含 .share/.widgets,BG task 前缀同改);REALDEVICE.md 重写为门户 + CLI 装机手册 - I18n.swift 移 Shared/ 供三 target 共用;i18n 加 ios.bg/share/control.* 键 - ultracode 多 agent 审查修复(0 HIGH,2 MED + 7 LOW):分享 send 后留收件箱致重发→move 私有暂存;WidgetSession 锁屏文件保护→UntilFirstUserAuthentication;outgoing/安全作用域登出释放;控件 device_id 登出清理;并发控件 refresh CAS-before-clear;APNs 读 reason + prune bad token + bust 过期 JWT;APNSEnv 大小写归一;Share-ext completeRequest 挪进 open 回调
67 lines
3.2 KiB
Swift
67 lines
3.2 KiB
Swift
import Foundation
|
||
|
||
// App Group:主 app 与 Share Extension 共享容器,用于交接待发文件——扩展只把文件搬进收件箱、
|
||
// 不跑传输引擎(避 120MB jetsam,见 PLAN §I5 / 决策 D)。两 target 共用此文件(xcodegen 多
|
||
// target 引用)。
|
||
//
|
||
// 收件箱布局:每个待发文件放进独立的 <uuid> 子目录,文件本身保留原名(发送时直接用作传输
|
||
// 文件名);发送 / 取消后删掉该子目录即清理。
|
||
enum AppGroup
|
||
{
|
||
static let identifier = "group.net.commilitia.cdrop"
|
||
|
||
// 共享收件箱根目录。容器不存在(App Group 未生效)时返回 nil,调用方降级为静默不交接。
|
||
static func inboxURL() -> URL?
|
||
{
|
||
guard let base = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: identifier)
|
||
else { return nil }
|
||
let inbox = base.appendingPathComponent("SharedInbox", isDirectory: true)
|
||
try? FileManager.default.createDirectory(at: inbox, withIntermediateDirectories: true)
|
||
return inbox
|
||
}
|
||
|
||
// 为一个原名分配新的暂存目标 URL(<inbox>/<uuid>/<originalName>),并建好父目录。
|
||
static func stagedDestination(originalName: String) -> URL?
|
||
{
|
||
guard let inbox = inboxURL() else { return nil }
|
||
let dir = inbox.appendingPathComponent(UUID().uuidString, isDirectory: true)
|
||
try? FileManager.default.createDirectory(at: dir, withIntermediateDirectories: true)
|
||
let safeName = originalName.isEmpty ? "file" : originalName
|
||
return dir.appendingPathComponent(safeName)
|
||
}
|
||
|
||
// 收件箱内现存的待发文件(主 app 处理分享时扫描,发送后逐个 remove)。
|
||
static func inboxFiles() -> [URL]
|
||
{
|
||
guard let inbox = inboxURL() else { return [] }
|
||
let dirs = (try? FileManager.default.contentsOfDirectory(at: inbox, includingPropertiesForKeys: nil)) ?? []
|
||
return dirs.compactMap
|
||
{ dir in
|
||
guard dir.hasDirectoryPath else { return nil }
|
||
let inner = (try? FileManager.default.contentsOfDirectory(at: dir, includingPropertiesForKeys: nil)) ?? []
|
||
return inner.first { !$0.hasDirectoryPath }
|
||
}
|
||
}
|
||
|
||
// 发送 / 取消后清理:删掉该文件所在的 <uuid> 子目录。
|
||
static func removeStaged(_ fileURL: URL)
|
||
{
|
||
try? FileManager.default.removeItem(at: fileURL.deletingLastPathComponent())
|
||
}
|
||
|
||
// 清理陈旧暂存:发送是异步读取暂存文件的,故发送后不立即删;改由此惰性回收超期子目录
|
||
// (默认 6 小时——远超任何传输时长),避免收件箱无限累积。主 app 每次导入分享时调用。
|
||
static func pruneStale(olderThan seconds: TimeInterval = 6 * 60 * 60)
|
||
{
|
||
guard let inbox = inboxURL() else { return }
|
||
let dirs = (try? FileManager.default.contentsOfDirectory(
|
||
at: inbox, includingPropertiesForKeys: [ .creationDateKey ])) ?? []
|
||
let cutoff = Date().addingTimeInterval(-seconds)
|
||
for dir in dirs
|
||
{
|
||
let created = (try? dir.resourceValues(forKeys: [ .creationDateKey ]).creationDate) ?? .distantPast
|
||
if created < cutoff { try? FileManager.default.removeItem(at: dir) }
|
||
}
|
||
}
|
||
}
|