Skip to main content
Glama
InputTextRouteHandler.swift1.4 kB
import FlyingFox import XCTest import os @MainActor struct InputTextRouteHandler : HTTPHandler { private let logger = Logger( subsystem: Bundle.main.bundleIdentifier!, category: String(describing: Self.self) ) func handleRequest(_ request: FlyingFox.HTTPRequest) async throws -> FlyingFox.HTTPResponse { guard let requestBody = try? await JSONDecoder().decode(InputTextRequest.self, from: request.bodyData) else { return AppError(type: .precondition, message: "incorrect request body provided for input text").httpResponse } do { let start = Date() await waitUntilKeyboardIsPresented() try await TextInputHelper.inputText(requestBody.text) let duration = Date().timeIntervalSince(start) logger.info("Text input duration took \(duration)") return HTTPResponse(statusCode: .ok) } catch { return AppError(message: "Error inputting text: \(error.localizedDescription)").httpResponse } } private func waitUntilKeyboardIsPresented() async { try? await TimeoutHelper.repeatUntil(timeout: 1, delta: 0.2) { let app = RunningApp.getForegroundApp() ?? XCUIApplication(bundleIdentifier: RunningApp.springboardBundleId) return app.keyboards.firstMatch.exists } } }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/mobile-dev-inc/Maestro'

If you have feedback or need assistance with the MCP directory API, please join our Discord server