/**
 * Minified by jsDelivr using Terser v5.39.0.
 * Original file: /npm/appium-flutter-driver@3.6.0/build/lib/driver.js
 *
 * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files
 */
"use strict";var __importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.FlutterDriver=void 0;const lodash_1=__importDefault(require("lodash")),driver_1=require("appium/driver"),logger_1=require("./logger"),observatory_1=require("./sessions/observatory"),platform_1=require("./platform"),session_1=require("./sessions/session"),context_1=require("./commands/context"),element_1=require("./commands/element"),execute_1=require("./commands/execute"),gesture_1=require("./commands/gesture"),screen_1=require("./commands/screen"),clipboard_1=require("./commands/clipboard"),desired_caps_1=require("./desired-caps"),appium_xcuitest_driver_1=require("appium-xcuitest-driver"),WEBVIEW_NO_PROXY=[["GET",new RegExp("^/session/[^/]+/appium")],["GET",new RegExp("^/session/[^/]+/context")],["GET",new RegExp("^/session/[^/]+/element/[^/]+/rect")],["GET",new RegExp("^/session/[^/]+/log/types$")],["GET",new RegExp("^/session/[^/]+/orientation")],["POST",new RegExp("^/session/[^/]+/appium")],["POST",new RegExp("^/session/[^/]+/context")],["POST",new RegExp("^/session/[^/]+/log$")],["POST",new RegExp("^/session/[^/]+/orientation")],["POST",new RegExp("^/session/[^/]+/touch/multi/perform")],["POST",new RegExp("^/session/[^/]+/touch/perform")]];class FlutterDriver extends driver_1.BaseDriver{socket;locatorStrategies=["key","css selector"];proxydriver;device;portForwardLocalPort;localServer;_logmon;internalCaps;receiveAsyncResponse;proxyWebViewActive=!1;executeElementCommand=observatory_1.executeElementCommand;executeGetVMCommand=observatory_1.executeGetVMCommand;executeGetIsolateCommand=observatory_1.executeGetIsolateCommand;execute=execute_1.execute;executeAsync=execute_1.execute;getText=element_1.getText;setValue=element_1.setValue;clear=element_1.clear;getScreenshot=screen_1.getScreenshot;click=gesture_1.click;longTap=gesture_1.longTap;tapEl=gesture_1.tapEl;tap=gesture_1.tap;performTouch=gesture_1.performTouch;getContexts=context_1.getContexts;getCurrentContext=context_1.getCurrentContext;setContext=context_1.setContext;currentContext=context_1.FLUTTER_CONTEXT_NAME;driverShouldDoProxyCmd=context_1.driverShouldDoProxyCmd;getClipboard=clipboard_1.getClipboard;setClipboard=clipboard_1.setClipboard;constructor(e,t){super(e,t),this.socket=null,this.device=null,this._logmon=null,this.desiredCapConstraints=desired_caps_1.desiredCapConstraints,this.portForwardLocalPort=null,this.localServer=null}async createSession(...e){const[t,r]=await super.createSession(...JSON.parse(JSON.stringify(e)));return this.internalCaps=r,session_1.createSession.bind(this)(t,r,...JSON.parse(JSON.stringify(e)))}async deleteSession(){switch(this.log.info("Deleting Flutter Driver session"),this._logmon?.stop(),this._logmon=null,this.proxydriver?.eventEmitter?.removeAllListeners("syslogStarted"),this.log.info("Cleanup the port forward"),lodash_1.default.toLower(this.internalCaps.platformName)){case platform_1.PLATFORM.IOS:this.localServer?.close(),this.localServer=null;break;case platform_1.PLATFORM.ANDROID:this.portForwardLocalPort&&this.proxydriver&&await(this.proxydriver.adb?.removePortForward(this.portForwardLocalPort))}if(this.proxydriver){this.log.info("Deleting the proxy driver session.");try{await this.proxydriver.deleteSession(this.sessionId||void 0)}catch(e){this.log.warn(e.message)}this.proxydriver=null}await super.deleteSession()}async installApp(e,t={}){this.proxydriver?.installApp(e,t)}async activateApp(e){this.proxydriver?.activateApp(e),await session_1.reConnectFlutterDriver.bind(this)(this.internalCaps)}async terminateApp(e){return await(this.proxydriver?.terminateApp(e))}async back(){return await(this.proxydriver?.back())}async getOrientation(){return this.proxydriver?lodash_1.default.toLower(this.internalCaps.platformName)===platform_1.PLATFORM.IOS?await this.proxydriver.proxyCommand("/orientation","GET"):await this.proxydriver.getOrientation():null}async setOrientation(e){return lodash_1.default.toLower(this.internalCaps.platformName)===platform_1.PLATFORM.IOS?await this.proxydriver.proxyCommand("/orientation","POST",{orientation:e}):await this.proxydriver.setOrientation(e)}validateLocatorStrategy(e){if("NATIVE_APP"===this.currentContext)return this.proxydriver?.validateLocatorStrategy(e);super.validateLocatorStrategy(e,!1)}validateDesiredCaps(e){const t=super.validateDesiredCaps(e);return!!t||t}async proxyCommand(e,t,r=null){return await(this.proxydriver?.proxyCommand(e,t,r))}async executeCommand(e,...t){if(!new RegExp(/^[\s]*mobile:[\s]*activateApp$/).test(t[0])){if(new RegExp(/^[\s]*mobile:[\s]*terminateApp$/).test(t[0]))return await(this.proxydriver?.executeCommand(e,...t));if("receiveAsyncResponse"===e)return logger_1.log.debug(`Executing FlutterDriver response '${e}'`),await this.receiveAsyncResponse(...t);if(["setOrientation","getOrientation","back"].includes(e))return logger_1.log.debug(`Executing FlutterDriver command '${e}'`),await super.executeCommand(e,...t);if(this.driverShouldDoProxyCmd(e)){logger_1.log.debug(`Executing proxied driver command '${e}'`),this.clearNewCommandTimeout();const r=await(this.proxydriver?.executeCommand(e,...t));return this.startNewCommandTimeout(),r}return logger_1.log.debug(`Executing Flutter driver command '${e}'`),await super.executeCommand(e,...t)}{const{skipAttachObservatoryUrl:r=!1}=t[1][0];if(await(this.proxydriver?.executeCommand(e,...t)),r)return;await session_1.reConnectFlutterDriver.bind(this)(this.internalCaps)}}getProxyAvoidList(){return[context_1.FLUTTER_CONTEXT_NAME,context_1.NATIVE_CONTEXT_NAME].includes(this.currentContext)?[]:WEBVIEW_NO_PROXY}proxyActive(){return this.proxyWebViewActive&&this.proxydriver?.constructor.name!==appium_xcuitest_driver_1.XCUITestDriver.name}canProxy(){return this.proxyWebViewActive}}exports.FlutterDriver=FlutterDriver;
//# sourceMappingURL=/sm/767095f01ae1ef837c0eec231f1c0479326810d813c55d1e100c75faaeb3c26f.map