Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove concurrency from iOS code #1891

Merged
merged 6 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading