- KangkangApp: ModelContainer 创建失败时重置本地 store 重建, 避免 demo 阶段 schema 演进导致旧真机启动崩溃(注:生产需正式迁移) - ModelSelfTestView: 正式的推理自检页(固定 prompt + 流式输出 + tok/s), 仅当 LLM 模型就绪时从「模型管理」出现入口 - 删除 DEBUG-only 的 DebugAIRunner,自检转正为就绪后可见的正式入口 - HomeView: 删除写死的「今日摘记」假数据卡;问候改为按时段动态 (早安/下午好/晚上好)+ 当天日期;影像档案数字接真实 @Query 计数 - MeView: 模型管理卡动态状态 + 关于页接真实版本号(用户改动一并纳入) Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
47 lines
1.6 KiB
Swift
47 lines
1.6 KiB
Swift
import SwiftUI
|
||
import SwiftData
|
||
|
||
@main
|
||
struct KangkangApp: App {
|
||
var sharedModelContainer: ModelContainer = {
|
||
let schema = Schema([
|
||
Indicator.self,
|
||
Report.self,
|
||
DiaryEntry.self,
|
||
Asset.self,
|
||
ChatTurn.self,
|
||
Symptom.self,
|
||
UserProfile.self,
|
||
MetricReminder.self,
|
||
CustomMonitorMetric.self,
|
||
HealthExport.self,
|
||
])
|
||
let config = ModelConfiguration(schema: schema, isStoredInMemoryOnly: false)
|
||
do {
|
||
return try ModelContainer(for: schema, configurations: [config])
|
||
} catch {
|
||
// Demo 阶段 schema 仍在演进:旧 store 与新 schema 不兼容且无正式迁移时,
|
||
// 自动迁移会失败导致启动崩溃。这里重置本地 store 重建(测试数据可丢)。
|
||
// ⚠️ 生产环境必须改为正式的 SwiftData 迁移方案,不能静默删数据。
|
||
print("⚠️ ModelContainer 创建失败,重置本地 store 重建: \(error)")
|
||
let fm = FileManager.default
|
||
let storePath = config.url.path
|
||
for path in [storePath, storePath + "-wal", storePath + "-shm"] {
|
||
try? fm.removeItem(atPath: path)
|
||
}
|
||
do {
|
||
return try ModelContainer(for: schema, configurations: [config])
|
||
} catch {
|
||
fatalError("Could not create ModelContainer even after reset: \(error)")
|
||
}
|
||
}
|
||
}()
|
||
|
||
var body: some Scene {
|
||
WindowGroup {
|
||
RootView()
|
||
}
|
||
.modelContainer(sharedModelContainer)
|
||
}
|
||
}
|