添加收集箱与快捷指令保存功能
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
//
|
||||
// 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 {
|
||||
let trimmed = text.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
guard !trimmed.isEmpty else {
|
||||
return .result(dialog: "文案为空,未保存。")
|
||||
}
|
||||
|
||||
try await ClipStore.shared.save(text: trimmed, source: source)
|
||||
return .result(dialog: "已保存到收集箱。")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user