-
-
Notifications
You must be signed in to change notification settings - Fork 210
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add support of UiModeManager service commands
- Loading branch information
1 parent
5d70ff0
commit ea97349
Showing
4 changed files
with
73 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import {mixin} from './mixins'; | ||
import {requireArgs} from '../utils'; | ||
|
||
const RESPONSE_PATTERN = /:\s+(\w+)/; | ||
|
||
/** | ||
* @type {import('./mixins').AppearanceMixin & ThisType<import('../driver').AndroidDriver>} | ||
* @satisfies {import('@appium/types').ExternalDriver} | ||
*/ | ||
const AppearanceMixin = { | ||
/** | ||
* Set the Ui appearance. | ||
* | ||
* @since Android 10 | ||
*/ | ||
async mobileSetUiMode(opts) { | ||
const {mode, value} = requireArgs(['mode', 'value'], opts); | ||
await this.adb.shell(['cmd', 'uimode', mode, value]); | ||
}, | ||
|
||
/** | ||
* Get the Ui appearance. | ||
* | ||
* @since Android 10 | ||
* @returns {Promise<string>} The actual state for the queried UI mode, | ||
* for example 'yes' or 'no' | ||
*/ | ||
async mobileGetUiMode(opts) { | ||
const {mode} = requireArgs(['mode'], opts); | ||
const response = await this.adb.shell(['cmd', 'uimode', mode]); | ||
// response looks like 'Night mode: no' | ||
const match = RESPONSE_PATTERN.exec(response); | ||
if (!match) { | ||
throw new Error(`Cannot parse the command response: ${response}`); | ||
} | ||
return match[1]; | ||
}, | ||
|
||
}; | ||
|
||
export default AppearanceMixin; | ||
|
||
mixin(AppearanceMixin); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters