From 379c9332687d51b08f04553f28ef51ee3f2ec927 Mon Sep 17 00:00:00 2001 From: Kazuaki Matsuo Date: Sun, 26 Jan 2025 12:25:56 -0800 Subject: [PATCH] feat: add content_size and increase_contrast commands for ui (#262) * feat: add content_size and increase_contrast commands for ui * add acceptable/possible return value in param side as well * add since --- lib/subcommands/ui.js | 102 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) diff --git a/lib/subcommands/ui.js b/lib/subcommands/ui.js index b645ca0..e9ee982 100644 --- a/lib/subcommands/ui.js +++ b/lib/subcommands/ui.js @@ -36,4 +36,106 @@ 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. + * + * @since Xcode 15 (but lower xcode could have this command) + * @this {import('../simctl').Simctl} + * @return {Promise} the contrast configuration value. + * Possible return value is 'enabled', 'disabled', + * 'unsupported' or 'unknown' with Xcode 16.2. + * @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. + * + * @since Xcode 15 (but lower xcode could have this command) + * @this {import('../simctl').Simctl} + * @param {string} increaseContrast valid increase constrast configuration value. + * Acceptable value is 'enabled' or 'disabled' with Xcode 16.2. + * @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. + * + * @since Xcode 15 (but lower xcode could have this command) + * @this {import('../simctl').Simctl} + * @return {Promise} the content size value. Possible return value is + * extra-small, small, medium, large, extra-large, extra-extra-large, + * extra-extra-extra-large, accessibility-medium, accessibility-large, + * accessibility-extra-large, accessibility-extra-extra-large, + * accessibility-extra-extra-extra-large, + * unknown or unsupported with Xcode 16.2. + * @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. + * + * @since Xcode 15 (but lower xcode could have this command) + * @this {import('../simctl').Simctl} + * @param {string} contentSizeAction valid content size or action value. Acceptable value is + * extra-small, small, medium, large, extra-large, extra-extra-large, + * extra-extra-extra-large, accessibility-medium, accessibility-large, + * accessibility-extra-large, accessibility-extra-extra-large, + * accessibility-extra-extra-extra-large with Xcode 16.2. + * @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;