mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-09-30 23:18:36 +00:00
36 lines
993 B
Swift
36 lines
993 B
Swift
import AppKit
|
|
import AppIntents
|
|
import GhosttyKit
|
|
|
|
struct FocusTerminalIntent: AppIntent {
|
|
static var title: LocalizedStringResource = "Focus Terminal"
|
|
static var description = IntentDescription("Move focus to an existing terminal.")
|
|
|
|
@Parameter(
|
|
title: "Terminal",
|
|
description: "The terminal to focus.",
|
|
)
|
|
var terminal: TerminalEntity
|
|
|
|
@available(macOS 26.0, *)
|
|
static var supportedModes: IntentModes = .background
|
|
|
|
@MainActor
|
|
func perform() async throws -> some IntentResult {
|
|
guard await requestIntentPermission() else {
|
|
throw GhosttyIntentError.permissionDenied
|
|
}
|
|
|
|
guard let surfaceView = terminal.surfaceView else {
|
|
throw GhosttyIntentError.surfaceNotFound
|
|
}
|
|
|
|
guard let controller = surfaceView.window?.windowController as? BaseTerminalController else {
|
|
return .result()
|
|
}
|
|
|
|
controller.focusSurface(surfaceView)
|
|
return .result()
|
|
}
|
|
}
|