Skip to content

Commit

Permalink
Remove concurrency from iOS code (#1891)
Browse files Browse the repository at this point in the history
* Remove concurrency from iOS code

* Format

Co-authored-by: Bartek Pacia <[email protected]>
Co-authored-by: Mateusz Wojtczak <[email protected]>
  • Loading branch information
3 people authored Nov 13, 2023
1 parent 08a11b6 commit a089171
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 31 deletions.
38 changes: 20 additions & 18 deletions packages/patrol/ios/Classes/AutomatorServer/Automator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down Expand Up @@ -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,
Expand All @@ -863,6 +865,6 @@
return NativeView.fromXCUIElementSnapshot(child, bundleId)
})
}
}
}

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import Foundation

final class AutomatorServer: NativeAutomatorServer {
final class AutomatorServer: NativeAutomatorServer {
private let automator: Automator

private let onAppReady: (Bool) -> Void
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -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

0 comments on commit a089171

Please sign in to comment.