预置快捷指令自动读取剪贴板
This commit is contained in:
@@ -6,13 +6,14 @@
|
||||
//
|
||||
|
||||
import AppIntents
|
||||
import UIKit
|
||||
|
||||
struct SaveClipIntent: AppIntent {
|
||||
|
||||
static var title: LocalizedStringResource = "保存剪贴板到 Note"
|
||||
static var description: IntentDescription? = "将一段文本保存到 Note App 的收集箱,稍后统一处理。"
|
||||
|
||||
@Parameter(title: "文案", description: "要保存的文本内容", requestValueDialog: "请提供要保存的文案")
|
||||
@Parameter(title: "文案", description: "要保存的文本内容", default: "")
|
||||
var text: String
|
||||
|
||||
@Parameter(title: "来源", description: "文案来源,例如应用名称", default: "快捷指令")
|
||||
@@ -26,7 +27,14 @@ struct SaveClipIntent: AppIntent {
|
||||
}
|
||||
|
||||
func perform() async throws -> some IntentResult & ReturnsValue<String> {
|
||||
let trimmed = text.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
var inputText = text
|
||||
if inputText.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty {
|
||||
inputText = await MainActor.run {
|
||||
UIPasteboard.general.string ?? ""
|
||||
}
|
||||
}
|
||||
|
||||
let trimmed = inputText.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
guard !trimmed.isEmpty else {
|
||||
return .result(value: "文案为空,未保存。")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user