-
-
Notifications
You must be signed in to change notification settings - Fork 212
/
Copy pathime.js
64 lines (58 loc) · 1.7 KB
/
ime.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import {errors} from 'appium/driver';
/**
* @this {import('../driver').AndroidDriver}
* @returns {Promise<boolean>}
*/
export async function isIMEActivated() {
// IME is always activated on Android devices
return true;
}
/**
* @this {import('../driver').AndroidDriver}
* @returns {Promise<string[]>}
*/
export async function availableIMEEngines() {
this.log.debug('Retrieving available IMEs');
let engines = await this.adb.availableIMEs();
this.log.debug(`Engines: ${JSON.stringify(engines)}`);
return engines;
}
/**
* @this {import('../driver').AndroidDriver}
* @returns {Promise<string>}
*/
export async function getActiveIMEEngine() {
this.log.debug('Retrieving current default IME');
return String(await this.adb.defaultIME());
}
/**
* @this {import('../driver').AndroidDriver}
* @param {string} imeId
* @returns {Promise<void>}
*/
export async function activateIMEEngine(imeId) {
this.log.debug(`Attempting to activate IME ${imeId}`);
let availableEngines = await this.adb.availableIMEs();
if (availableEngines.indexOf(imeId) === -1) {
this.log.debug('IME not found, failing');
throw new errors.IMENotAvailableError();
}
this.log.debug('Found installed IME, attempting to activate');
await this.adb.enableIME(imeId);
await this.adb.setIME(imeId);
}
/**
* @this {import('../driver').AndroidDriver}
* @returns {Promise<void>}
*/
export async function deactivateIMEEngine() {
let currentEngine = await this.getActiveIMEEngine();
// XXX: this allowed 'null' to be passed into `adb.shell`
if (currentEngine) {
this.log.debug(`Attempting to deactivate ${currentEngine}`);
await this.adb.disableIME(currentEngine);
}
}
/**
* @typedef {import('appium-adb').ADB} ADB
*/