// // SaveClipIntent.swift // Note // // Created by Kimi Code CLI on 2026/7/15. // import AppIntents struct SaveClipIntent: AppIntent { static var title: LocalizedStringResource = "保存剪贴板到 Note" static var description: IntentDescription? = "将一段文本保存到 Note App 的收集箱,稍后统一处理。" @Parameter(title: "文案", description: "要保存的文本内容", requestValueDialog: "请提供要保存的文案") var text: String @Parameter(title: "来源", description: "文案来源,例如应用名称", default: "快捷指令") var source: String? init() {} init(text: String, source: String? = nil) { self.text = text self.source = source } func perform() async throws -> some IntentResult & ReturnsValue { let trimmed = text.trimmingCharacters(in: .whitespacesAndNewlines) guard !trimmed.isEmpty else { return .result(value: "文案为空,未保存。") } guard !isSystemClipboardPlaceholder(trimmed) else { return .result(value: "剪贴板没有有效文本,未保存。") } try await ClipStore.shared.save(text: trimmed, source: source) return .result(value: "已保存到收集箱。") } private func isSystemClipboardPlaceholder(_ text: String) -> Bool { let lowercased = text.lowercased() if lowercased.hasPrefix("clipboard ") && lowercased.contains(" at ") { return true } if text == "获取剪贴板" { return true } return false } }