512d7563ee
- 引擎 / 鉴权跨平台 in-place(iOS 路径 #if 守卫、逐字不变,仅加 macOS/AppKit 分支):EngineController(import 守卫 + 剪贴板 UIPasteboard→NSPasteboard 上下行两处 + device_type 平台条件)、EngineWebView(UIViewRepresentable→typealias 统一后分 NSViewRepresentable)、Theme(动态色 Color(nsColor:dynamicProvider) 同 RGB)、DeviceNameStore(Host.current().localizedName)、PushRegistry(NSApplication.registerForRemoteNotifications)、Auth/BrokerLogin(presentationAnchor→NSApplication.keyWindow)、Auth/AuthManager(死 import UIKit 守卫)
- BackgroundTaskManager:整文件 #if os(iOS)(BGContinuedProcessingTask 为 API_UNAVAILABLE(macos)、编译级拒绝)+ macOS 同签名 no-op stub,使 EngineController.syncBackgroundTask 调用点无须改动
- device_type 修正(非机械):Mac 原生客户端 boot 注入 device_type=macos(与桌面 Wails 客户端一致,后端 / 各端已识别),不再硬编 ios——否则其他端设备列表图标错、且触发其 isWakeable 的 contains("ios") 误判本 Mac 可推送唤醒
- CommilitiaDropMac target 纳入「引擎 + 登录」最小集:Shared + Sources/Engine + Sources/Auth(除 iOS 专属 LoginView)+ RecordsStore / PushRegistry / LocalNetworkPermission / DeviceNameStore / BackgroundTaskManager + Resources/i18n;依赖 WebRTC;Info.plist 加 cdrop:// 回调 scheme(ASWebAuthenticationSession OAuth 回调)+ 本地网络(NSLocalNetworkUsageDescription / NSBonjourServices _cdrop._tcp)
- Mac 壳接引擎:CommilitiaDropMacApp(@State auth + engine,MacAppRoot 登录门 + 会话激活分桶记录)、MacLoginView(Broker 账户登录,免相机)、MacRootView(背景挂离屏引擎 WebView 保活 + 设备真实 presence 列表 + 设置账号/登出/引擎日志)、MacMenuContent(账号 + 在线设备数)。传输/文件/消息详情暂占位,随 Phase 3b 复用 iOS 视图
- 验证:just mac-build(CommilitiaDropMac.app)+ iOS 模拟器(CommilitiaDrop.app)均 BUILD SUCCEEDED。运行期登录 / 引擎联通待真机自测(Broker OAuth 需账号交互)
79 lines
2.4 KiB
Swift
79 lines
2.4 KiB
Swift
#if os(macOS)
|
||
import SwiftUI
|
||
|
||
// 原生 macOS 客户端入口。单窗口 + 菜单栏常驻,桌面壳(MacRootView)替代 iOS 的标签栏。复用 iOS 引擎
|
||
// (EngineController:离屏 WKWebView 跑 JS 引擎 + 原生 libwebrtc 数据面)与鉴权(AuthManager:Broker
|
||
// 登录);引擎 WebView 挂在 MacRootView 背景保活(登录后才启)。iOS 入口另见 CDropApp。桌面专属功能
|
||
// (剪贴板自动同步 / 全局热键 / 原生通知)随后续阶段并入。
|
||
@main
|
||
struct CommilitiaDropMacApp: App
|
||
{
|
||
@State private var auth = AuthManager()
|
||
@State private var engine = EngineController()
|
||
|
||
var body: some Scene
|
||
{
|
||
Window("Commilitia Drop", id: "main")
|
||
{
|
||
MacAppRoot(auth: auth, engine: engine)
|
||
.frame(minWidth: 820, minHeight: 560)
|
||
}
|
||
.defaultLaunchBehavior(.presented)
|
||
.windowResizability(.contentMinSize)
|
||
.commands
|
||
{
|
||
// 单窗口应用:移除「新建」(⌘N),对本应用无意义。
|
||
CommandGroup(replacing: .newItem) {}
|
||
}
|
||
|
||
MenuBarExtra
|
||
{
|
||
MacMenuContent()
|
||
.environment(engine)
|
||
.environment(auth)
|
||
}
|
||
label:
|
||
{
|
||
Image(systemName: "paperplane")
|
||
}
|
||
.menuBarExtraStyle(.window)
|
||
}
|
||
}
|
||
|
||
// 登录门:有会话进桌面壳(引擎随 MacRootView 背景 WebView 启动),无会话进原生 Broker 登录页。逻辑
|
||
// 对齐 iOS 的 AppRoot(CDropApp):注入 auth 源、会话激活即按 userId 加载持久记录。
|
||
struct MacAppRoot: View
|
||
{
|
||
let auth: AuthManager
|
||
let engine: EngineController
|
||
|
||
var body: some View
|
||
{
|
||
Group
|
||
{
|
||
if auth.session != nil
|
||
{
|
||
MacRootView()
|
||
.environment(engine)
|
||
.environment(auth)
|
||
}
|
||
else
|
||
{
|
||
MacLoginView()
|
||
.environment(auth)
|
||
}
|
||
}
|
||
.onAppear
|
||
{
|
||
engine.auth = auth
|
||
// 冷启已有会话:立即按 userId 加载该用户的持久记录(reset 只清内存不动盘)。
|
||
if let uid = auth.session?.user.id { engine.activateRecords(userId: uid) }
|
||
}
|
||
.onChange(of: auth.session?.user.id)
|
||
{ _, uid in
|
||
if let uid { engine.activateRecords(userId: uid) }
|
||
}
|
||
}
|
||
}
|
||
#endif
|