Skip to content

Commit

Permalink
feat: add increase contrast and content size commands
Browse files Browse the repository at this point in the history
  • Loading branch information
KazuCocoa committed Jan 27, 2025
1 parent 5d1a240 commit dcccafb
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 1 deletion.
51 changes: 51 additions & 0 deletions lib/extensions/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,57 @@ export async function getAppearance () {
throw new Error(`Xcode SDK '${this.xcodeVersion}' is too old to get UI appearance`);
}

/**
* Sets content size for the given simulator.
* This function can only be called on a booted simulator.
*
* @this {CoreSimulatorWithSettings}
* @param {string} value
* @since Xcode SDK 15 (but lower xcode could have this command)
* @returns {Promise<void>}
*/
export async function setIncreaseContrast (value) {
throw new Error(`Xcode SDK '${this.xcodeVersion}' is too old to set content size`);
}

/**
* Retrieves the current content size value from the given simulator.
* This function can only be called on a booted simulator.
*
* @this {CoreSimulatorWithSettings}
* @returns {Promise<string>}
* @since Xcode SDK 15 (but lower xcode could have this command)
*/
export async function getIncreaseContrast () {
throw new Error(`Xcode SDK '${this.xcodeVersion}' is too old to get content size`);
}


/**
* Sets content size for the given simulator.
* This function can only be called on a booted simulator.
*
* @this {CoreSimulatorWithSettings}
* @param {string} value
* @since Xcode SDK 15 (but lower xcode could have this command)
* @returns {Promise<void>}
*/
export async function setContentSize (value) {
throw new Error(`Xcode SDK '${this.xcodeVersion}' is too old to set content size`);
}

/**
* Retrieves the current content size value from the given simulator.
* This function can only be called on a booted simulator.
*
* @this {CoreSimulatorWithSettings}
* @returns {Promise<string>}
* @since Xcode SDK 15 (but lower xcode could have this command)
*/
export async function getContentSize () {
throw new Error(`Xcode SDK '${this.xcodeVersion}' is too old to get content size`);
}

/**
* Change localization settings on the currently booted simulator
*
Expand Down
4 changes: 4 additions & 0 deletions lib/simulator-xcode-10.js
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,10 @@ export class SimulatorXcode10 extends EventEmitter {
updateSettings = settingsExtensions.updateSettings;
setAppearance = settingsExtensions.setAppearance;
getAppearance = settingsExtensions.getAppearance;
setIncreaseContrast = settingsExtensions.setIncreaseContrast;
getIncreaseContrast = settingsExtensions.getIncreaseContrast;
setContentSize = settingsExtensions.setContentSize;
getContentSize = settingsExtensions.getContentSize;
configureLocalization = settingsExtensions.configureLocalization;
setAutoFillPasswords = settingsExtensions.setAutoFillPasswords;
setReduceMotion = settingsExtensions.setReduceMotion;
Expand Down
58 changes: 58 additions & 0 deletions lib/simulator-xcode-15.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,62 @@ export class SimulatorXcode15 extends SimulatorXcode14 {

return path.resolve(await this._getSystemRoot(), 'System/Library/LaunchDaemons');
}

/**
* Sets the increase contrast configuration for the given simulator.
* This function can only be called on a booted simulator.
*
* @override
* @since Xcode SDK 15 (but lower xcode could have this command)
* @param {string} value valid increase constrast configuration value.
* Acceptable value is 'enabled' or 'disabled' with Xcode 16.2.
* @returns {Promise<void>}
*/
setIncreaseContrast = async (value) => {
await this.simctl.setIncreaseContrast(value);
};

/**
* Retrieves the current increase contrast configuration value from the given simulator.
* This function can only be called on a booted simulator.
*
* @override
* @since Xcode SDK 15 (but lower xcode could have this command)
* @return {Promise<string>} the contrast configuration value.
* Possible return value is 'enabled', 'disabled',
* 'unsupported' or 'unknown' with Xcode 16.2.
*/
getIncreaseContrast = async () => await this.simctl.getIncreaseContrast();

/**
* Sets content size for the given simulator.
* This function can only be called on a booted simulator.
*
* @override
* @since Xcode SDK 15 (but lower xcode could have this command)
* @param {string} value 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.
* @returns {Promise<void>}
*/
setContentSize = async (value) => {
await this.simctl.setContentSize(value);
};

/**
* Retrieves the current content size value from the given simulator.
* This function can only be called on a booted simulator.
*
* @override
* @since Xcode SDK 15 (but lower xcode could have this command)
* @return {Promise<string>} 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.
*/
getContentSize = async () => await this.simctl.getContentSize();
}
4 changes: 4 additions & 0 deletions lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,10 @@ export interface HasSettings {
updateSettings(domain: string, updates: StringRecord): Promise<boolean>;
setAppearance(value: string): Promise<void>;
getAppearance(): Promise<string>;
setContentSize(value: string): Promise<void>;
getContentSize(): Promise<string>;
setIncreaseContrast(value: string): Promise<void>;
getIncreaseContrast(): Promise<string>;
disableKeyboardIntroduction(): Promise<boolean>;
configureLocalization(opts?: LocalizationOptions): Promise<boolean>;
setAutoFillPasswords(isEnabled: boolean): Promise<boolean>;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"asyncbox": "^3.0.0",
"bluebird": "^3.5.1",
"lodash": "^4.2.1",
"node-simctl": "^7.4.1",
"node-simctl": "^7.7.1",
"semver": "^7.0.0",
"source-map-support": "^0.x",
"teen_process": "^2.0.0"
Expand Down

0 comments on commit dcccafb

Please sign in to comment.