UNPKG

appium-xcuitest-driver

Version:

Appium driver for iOS using XCUITest for backend

81 lines 3.5 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.ConnectedDevicesClient = void 0; const lodash_1 = __importDefault(require("lodash")); const node_devicectl_1 = require("node-devicectl"); const appium_ios_device_1 = require("appium-ios-device"); const logger_1 = require("../logger"); const utils_1 = require("../utils"); const remotexpc_utils_1 = require("./remotexpc-utils"); class ConnectedDevicesClient { services; constructor(services) { this.services = services; } /** * Create a connected devices client instance. * When opts indicate iOS/tvOS 18+, loads and stores the remotexpc Services * instance for tunnel registry listing; otherwise uses legacy listing only. */ static async create(opts) { let services = null; if ((0, utils_1.isIos18OrNewer)(opts)) { services = await (0, remotexpc_utils_1.tryGetRemoteXPCServices)(); if (!services) { logger_1.log.warn('Could not load appium-ios-remotexpc, using legacy devices listing instead'); } } return new ConnectedDevicesClient(services); } /** * Returns the list of connected real device UDIDs. * Only considers tunnel registry UDIDs when remotexpc is loaded and tunnels are running; * otherwise returns the legacy list only. */ async getConnectedDevices() { const [tunnelSettled, legacySettled] = await Promise.allSettled([ this.listUdidsFromTunnelsRegistry(), this.listLegacyUdids(), ]); // Tunnels succeeded → short-circuit: return tunnel UDIDs only (legacy not used) if (tunnelSettled.status === 'fulfilled') { return tunnelSettled.value; } // Tunnels rejected (only other status after fulfilled) → use legacy; throw if legacy failed const err = tunnelSettled.reason; logger_1.log.info('Tunnel registry unavailable; using legacy devices listing instead. ' + `Original error: ${err instanceof Error ? err.message : String(err)}`); if (legacySettled.status === 'rejected') { throw legacySettled.reason instanceof Error ? legacySettled.reason : new Error(String(legacySettled.reason)); } return legacySettled.value; } isPreferDevicectlEnabled() { return ['yes', 'true', '1'].includes(lodash_1.default.toLower(process.env.APPIUM_XCUITEST_PREFER_DEVICECTL ?? '')); } /** * Fetches UDIDs from the tunnel registry. * @throws When remotexpc is not loaded or when the tunnel registry is unreachable. */ async listUdidsFromTunnelsRegistry() { if (!this.services) { throw new Error('appium-ios-remotexpc module cannot be loaded'); } return await this.services.getAvailableDevices(); } async listLegacyUdids() { if (this.isPreferDevicectlEnabled()) { return (await new node_devicectl_1.Devicectl('').listDevices()) .map(({ hardwareProperties }) => hardwareProperties?.udid) .filter(Boolean); } return await appium_ios_device_1.utilities.getConnectedDevices(); } } exports.ConnectedDevicesClient = ConnectedDevicesClient; //# sourceMappingURL=connected-devices-client.js.map