From a0891717b809adb29c0173e37069f7624d70e563 Mon Sep 17 00:00:00 2001 From: Piotr Maszota <37781044+piotruela@users.noreply.github.com> Date: Mon, 13 Nov 2023 10:26:15 +0100 Subject: [PATCH] Remove concurrency from iOS code (#1891) * Remove concurrency from iOS code * Format Co-authored-by: Bartek Pacia Co-authored-by: Mateusz Wojtczak --- .../Classes/AutomatorServer/Automator.swift | 38 ++++++++++--------- .../AutomatorServer/AutomatorServer.swift | 10 ++--- .../AutomatorServer/ElementTypeUtils.swift | 15 ++++---- 3 files changed, 32 insertions(+), 31 deletions(-) diff --git a/packages/patrol/ios/Classes/AutomatorServer/Automator.swift b/packages/patrol/ios/Classes/AutomatorServer/Automator.swift index d62def8cc..0dc94fa45 100644 --- a/packages/patrol/ios/Classes/AutomatorServer/Automator.swift +++ b/packages/patrol/ios/Classes/AutomatorServer/Automator.swift @@ -395,27 +395,27 @@ return views } } - - func getUITreeRoots(installedApps: [String]) async throws -> [NativeView] { - try await runAction("getting ui tree roots") { - let foregroundApp = self.getForegroundApp(installedApps: installedApps) - let snapshot = try foregroundApp.snapshot() - return [NativeView.fromXCUIElementSnapshot(snapshot, foregroundApp.identifier)] + + func getUITreeRoots(installedApps: [String]) throws -> [NativeView] { + try runAction("getting ui tree roots") { + let foregroundApp = self.getForegroundApp(installedApps: installedApps) + let snapshot = try foregroundApp.snapshot() + return [NativeView.fromXCUIElementSnapshot(snapshot, foregroundApp.identifier)] } } - + private func getForegroundApp(installedApps: [String]) -> XCUIApplication { let app = XCUIApplication() if app.state == .runningForeground { - return app + return app } else { - for bundleIdentifier in installedApps { - let app = XCUIApplication(bundleIdentifier: bundleIdentifier) - if app.state == .runningForeground { - return app - } + for bundleIdentifier in installedApps { + let app = XCUIApplication(bundleIdentifier: bundleIdentifier) + if app.state == .runningForeground { + return app } - return self.springboard + } + return self.springboard } } @@ -849,12 +849,14 @@ return NativeView.fromXCUIElement(child, bundleId) }) } - - static func fromXCUIElementSnapshot(_ xcuielement: XCUIElementSnapshot, _ bundleId: String) -> NativeView { + + static func fromXCUIElementSnapshot(_ xcuielement: XCUIElementSnapshot, _ bundleId: String) + -> NativeView + { return NativeView( className: getElementTypeName(elementType: xcuielement.elementType), text: xcuielement.label, - contentDescription: "", // TODO: Separate request + contentDescription: "", // TODO: Separate request focused: xcuielement.hasFocus, enabled: xcuielement.isEnabled, resourceName: xcuielement.identifier, @@ -863,6 +865,6 @@ return NativeView.fromXCUIElementSnapshot(child, bundleId) }) } -} + } #endif diff --git a/packages/patrol/ios/Classes/AutomatorServer/AutomatorServer.swift b/packages/patrol/ios/Classes/AutomatorServer/AutomatorServer.swift index 8127664af..e28e4b3a0 100644 --- a/packages/patrol/ios/Classes/AutomatorServer/AutomatorServer.swift +++ b/packages/patrol/ios/Classes/AutomatorServer/AutomatorServer.swift @@ -2,7 +2,7 @@ import Foundation -final class AutomatorServer: NativeAutomatorServer { + final class AutomatorServer: NativeAutomatorServer { private let automator: Automator private let onAppReady: (Bool) -> Void @@ -70,11 +70,11 @@ final class AutomatorServer: NativeAutomatorServer { return GetNativeViewsResponse(nativeViews: nativeViews) } } - - func getNativeUITree(request: GetNativeUITreeRequest) async throws -> GetNativeUITreeRespone { - let roots = try await automator.getUITreeRoots(installedApps: request.iosInstalledApps ?? []) - return GetNativeUITreeRespone(roots: roots) + func getNativeUITree(request: GetNativeUITreeRequest) throws -> GetNativeUITreeRespone { + let roots = try automator.getUITreeRoots(installedApps: request.iosInstalledApps ?? []) + + return GetNativeUITreeRespone(roots: roots) } func tap(request: TapRequest) throws { diff --git a/packages/patrol/ios/Classes/AutomatorServer/ElementTypeUtils.swift b/packages/patrol/ios/Classes/AutomatorServer/ElementTypeUtils.swift index 7dfc6aec9..ecfe11b68 100644 --- a/packages/patrol/ios/Classes/AutomatorServer/ElementTypeUtils.swift +++ b/packages/patrol/ios/Classes/AutomatorServer/ElementTypeUtils.swift @@ -1,9 +1,9 @@ #if PATROL_ENABLED -import Foundation -import XCTest + import Foundation + import XCTest -private let elementTypeNames = [ + private let elementTypeNames = [ XCUIElement.ElementType.any: "any", XCUIElement.ElementType.other: "other", XCUIElement.ElementType.application: "application", @@ -86,12 +86,11 @@ private let elementTypeNames = [ XCUIElement.ElementType.stepper: "stepper", XCUIElement.ElementType.tab: "tab", XCUIElement.ElementType.touchBar: "touchBar", - XCUIElement.ElementType.statusItem: "statusItem" -] - + XCUIElement.ElementType.statusItem: "statusItem", + ] -func getElementTypeName(elementType: XCUIElement.ElementType) -> String? { + func getElementTypeName(elementType: XCUIElement.ElementType) -> String? { return elementTypeNames[elementType] -} + } #endif