- 应用图标改用与 Web favicon 同源的扁平标记,金色 SIM 卡体加三格递增信号,29pt 下仍可读 - 标签统一为胶囊形状,提高深色主题下的描边权重,避免标签在暗色下消失 - 消息卡片与详情分区卡片收紧行距,单屏信息密度明显提升 - 详情头部指标精简为 4 行,数据模块改为单条读数 - 批量选择勾选框移出名称区域,工具栏控件统一为等高 34pt - 分组编辑器改为点选即生效,移除说明文字与常驻禁用按钮
80 lines
2.3 KiB
Swift
80 lines
2.3 KiB
Swift
import Foundation
|
|
#if canImport(UIKit)
|
|
import UIKit
|
|
#endif
|
|
|
|
struct SettingsRuntime: Equatable {
|
|
let appName: String
|
|
let marketingVersion: String
|
|
let buildVersion: String
|
|
let platform: String
|
|
let systemVersion: String
|
|
}
|
|
|
|
@MainActor
|
|
final class SettingsViewModel: ObservableObject {
|
|
@Published private(set) var runtime: SettingsRuntime?
|
|
@Published private(set) var isLoading = false
|
|
@Published var storageLabel = "--"
|
|
@Published var notice: String?
|
|
@Published var errorMessage: String?
|
|
|
|
private let store: any LogStore
|
|
|
|
init(store: any LogStore) {
|
|
self.store = store
|
|
}
|
|
|
|
func refresh() async {
|
|
isLoading = true
|
|
errorMessage = nil
|
|
|
|
runtime = SettingsRuntime(
|
|
appName: AppMetadata.name,
|
|
marketingVersion: AppMetadata.marketingVersion,
|
|
buildVersion: AppMetadata.buildVersion,
|
|
platform: "iOS",
|
|
systemVersion: Self.systemVersion()
|
|
)
|
|
await loadStorageLabel()
|
|
|
|
isLoading = false
|
|
}
|
|
|
|
func clearRuntimeLogs() async -> Int {
|
|
do {
|
|
let removed = try await store.clearRuntimeLogs()
|
|
notice = removed > 0 ? "已清除 \(removed) 条运行日志。" : "没有可清除的运行日志。"
|
|
errorMessage = nil
|
|
await loadStorageLabel()
|
|
return removed
|
|
} catch {
|
|
notice = nil
|
|
errorMessage = "清除运行日志失败。"
|
|
return 0
|
|
}
|
|
}
|
|
|
|
private func loadStorageLabel() async {
|
|
do {
|
|
let runtimeCount = try await store.runtimeLogs().count
|
|
let connectionCount = try await store.connectionLogs().count
|
|
storageLabel = "\(runtimeCount) 条运行日志 · \(connectionCount) 条连接日志"
|
|
} catch {
|
|
storageLabel = "--"
|
|
errorMessage = "无法读取本地数据状态。"
|
|
}
|
|
}
|
|
|
|
/// 只报对用户有意义的系统版本,不暴露机器标识之类的原始信息。
|
|
private static func systemVersion() -> String {
|
|
#if canImport(UIKit)
|
|
let device = UIDevice.current
|
|
return "\(device.systemName) \(device.systemVersion)"
|
|
#else
|
|
let version = ProcessInfo.processInfo.operatingSystemVersion
|
|
return "iOS \(version.majorVersion).\(version.minorVersion)"
|
|
#endif
|
|
}
|
|
}
|