Skip to content

Commit

Permalink
feat: add content_size and increase_contrast commands for ui
Browse files Browse the repository at this point in the history
  • Loading branch information
KazuCocoa committed Jan 26, 2025
1 parent a8d51e4 commit af7f0f0
Showing 1 changed file with 87 additions and 0 deletions.
87 changes: 87 additions & 0 deletions lib/subcommands/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,91 @@ commands.setAppearance = async function setAppearance (appearance) {
});
};

/**
* Retrieves the current increase contrast configuration value from the given simulator.
* The value could be:
* - enabled: Increase Contrast is enabled.
* - disabled: Increase Contrast is disabled.
* - unsupported: The platform or runtime version do not support the Increase Contrast setting.
* - unknown: The current setting is unknown or there was an error detecting it.
*
* @this {import('../simctl').Simctl}
* @return {Promise<string>} the contrast configuration value.
* @throws {Error} if the current SDK version does not support the command
* or there was an error while getting the value.
* @throws {Error} If the `udid` instance property is unset
*/
commands.getIncreaseContrast = async function getIncreaseContrast () {
const {stdout} = await this.exec('ui', {
args: [this.requireUdid('ui'), 'increase_contrast'],
});
return _.trim(stdout);
};

/**
* Sets the increase constrast configuration for the given simulator.
* Acceptable values (with Xcode 16.2, iOS 18.1) are 'enabled' or 'disabled'
* They would change in the future version, so please validate the given value
* in the caller side.
*
* @this {import('../simctl').Simctl}
* @param {string} increaseContrast valid increase constrast configuration value.
* @throws {Error} if the current SDK version does not support the command
* or the given value was invalid for the command.
* @throws {Error} If the `udid` instance property is unset
*/
commands.setIncreaseContrast = async function setIncreaseContrast (increaseContrast) {
await this.exec('ui', {
args: [this.requireUdid('ui'), 'increase_contrast', increaseContrast],
});
};

/**
* Retrieves the current content size value from the given simulator.
* The value could be:
* Standard sizes: extra-small, small, medium, large, extra-large,
* extra-extra-large, extra-extra-extra-large
* Extended range sizes: accessibility-medium, accessibility-large,
* accessibility-extra-large, accessibility-extra-extra-large,
* accessibility-extra-extra-extra-large
* Other values: unknown, unsupported.
*
* @this {import('../simctl').Simctl}
* @return {Promise<string>} the content size value.
* @throws {Error} if the current SDK version does not support the command
* or there was an error while getting the value.
* @throws {Error} If the `udid` instance property is unset
*/
commands.getContentSize = async function getContentSize () {
const {stdout} = await this.exec('ui', {
args: [this.requireUdid('ui'), 'content_size'],
});
return _.trim(stdout);
};

/**
* Sets content size for the given simulator.
* Acceptable values (with Xcode 16.2, iOS 18.1) are below:
* Standard sizes: extra-small, small, medium, large, extra-large,
* extra-extra-large, extra-extra-extra-large
* Extended range sizes: accessibility-medium, accessibility-large,
* accessibility-extra-large, accessibility-extra-extra-large,
* accessibility-extra-extra-extra-large
* Or 'increment' or 'decrement'
* They would change in the future version, so please validate the given value
* in the caller side.
*
* @this {import('../simctl').Simctl}
* @param {string} contentSizeAction valid content size or action value.
* The example is in the description avobe.
* @throws {Error} if the current SDK version does not support the command
* or the given value was invalid for the command.
* @throws {Error} If the `udid` instance property is unset
*/
commands.setContentSize = async function setContentSize (contentSizeAction) {
await this.exec('ui', {
args: [this.requireUdid('ui'), 'content_size', contentSizeAction],
});
};

export default commands;

0 comments on commit af7f0f0

Please sign in to comment.