我正在尝试将语音控制(通过 Siri)添加到 MacOS 项目中。所以我可以说“向左叠加 10”之类的东西
对框架的期望:
实际上它是如何工作的:
我的问题是 AppIntent 可以直接从命令中识别参数吗?没有确认每个参数?非常感谢!
enum Direction:String{
case left, right, up, down
}
extension Direction: AppEnum{
static var caseDisplayRepresentations: [Direction : DisplayRepresentation] = [
.down: "down",
.up: "up",
.left: "to the left",
.right: "to the right",
]
static var typeDisplayName: LocalizedStringResource = "Direction"
static var typeDisplayRepresentation: TypeDisplayRepresentation = "Direction"
}
struct MoveGridIntent: AppIntent {
static var title: LocalizedStringResource = "Overlay Direction"
static var description = IntentDescription("In luxCamMac move the grid overlay")
static var openAppWhenRun: Bool = true
@Parameter(title: "Direction", description: "the direction the overlay is going to move", requestValueDialog: IntentDialog("Which direction"))
var direction: Direction
@Parameter(title: "pixels", inclusiveRange: (1, 50))
var pixels: Int
static var parameterSummary: some ParameterSummary {
Summary("Overlay \(\.$direction) \(\.$pixels)")
}
@MainActor
func perform() async throws -> some IntentResult {
print("MoveGridIntent", "move overlay", direction, "for \(pixels) pixels !!")
return .result()
}
}