Skip to content

Commit

Permalink
feat: Perform device init steps in parallel (#912)
Browse files Browse the repository at this point in the history
  • Loading branch information
mykola-mokhnach authored Feb 1, 2024
1 parent 39c0ea0 commit 3bdebbc
Showing 1 changed file with 31 additions and 23 deletions.
54 changes: 31 additions & 23 deletions lib/commands/device/common.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import semver from 'semver';
import _ from 'lodash';
import B from 'bluebird';
import {resetMockLocation, setMockLocationApp} from '../geolocation';
import {SETTINGS_HELPER_ID} from 'io.appium.settings';
import {hideKeyboardCompletely, initUnicodeKeyboard} from '../keyboard';
Expand Down Expand Up @@ -177,7 +178,7 @@ export async function getLaunchInfo() {

/**
* @this {AndroidDriver}
* @returns
* @returns {Promise<void>}
*/
export async function initDevice() {
const {
Expand Down Expand Up @@ -220,40 +221,47 @@ export async function initDevice() {
await pushSettingsApp.bind(this)(shouldThrowError);
}

/** @type {Promise[]} */
const promises = [];

if (!this.isEmulator()) {
if (mockLocationApp || _.isUndefined(mockLocationApp)) {
await setMockLocationApp.bind(this)(mockLocationApp || SETTINGS_HELPER_ID);
} else {
await resetMockLocation.bind(this)();
}
promises.push((async () => {
if (mockLocationApp || _.isUndefined(mockLocationApp)) {
await setMockLocationApp.bind(this)(mockLocationApp || SETTINGS_HELPER_ID);
} else {
await resetMockLocation.bind(this)();
}
})());
}

if (language && locale) {
await this.ensureDeviceLocale(language, locale, localeScript);
promises.push(this.ensureDeviceLocale(language, locale, localeScript));
}

if (skipLogcatCapture) {
this.log.info(`'skipLogcatCapture' is set. Skipping starting logcat capture.`);
} else {
await this.adb.startLogcat({
promises.push(this.adb.startLogcat({
format: logcatFormat,
filterSpecs: logcatFilterSpecs,
});
}));
}

if (hideKeyboard) {
await hideKeyboardCompletely.bind(this)();
} else if (hideKeyboard === false) {
await this.adb.shell(['ime', 'reset']);
}

promises.push((async () => {
if (hideKeyboard) {
await hideKeyboardCompletely.bind(this)();
} else if (hideKeyboard === false) {
await this.adb.shell(['ime', 'reset']);
}
})());
if (unicodeKeyboard) {
this.log.warn(
`The 'unicodeKeyboard' capability has been deprecated and will be removed. ` +
`Set the 'hideKeyboard' capability to 'true' in order to make the on-screen keyboard invisible.`,
);
return await initUnicodeKeyboard.bind(this)();
promises.push((async () => {
this.log.warn(
`The 'unicodeKeyboard' capability has been deprecated and will be removed. ` +
`Set the 'hideKeyboard' capability to 'true' in order to make the on-screen keyboard invisible.`,
);
await initUnicodeKeyboard.bind(this)();
})());
}

await B.all(promises);
}

/**
Expand Down

0 comments on commit 3bdebbc

Please sign in to comment.