appium-xcuitest-driver
Version:
Appium driver for iOS using XCUITest for backend
64 lines • 2.04 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.mobileSetAppearance = mobileSetAppearance;
exports.mobileGetAppearance = mobileGetAppearance;
const support_1 = require("appium/support");
/**
* Set the device's UI appearance style
*
* @since iOS 12.0
* @param style - The appearance style to set
* @throws If the current platform does not support UI appearance changes
*/
async function mobileSetAppearance(style) {
if (!['light', 'dark'].includes(String(style).toLowerCase())) {
throw new Error(`The 'style' value is expected to equal either 'light' or 'dark'`);
}
if (support_1.util.compareVersions(this.opts.platformVersion, '<', '12.0')) {
throw new Error('Changing appearance is only supported since iOS 12');
}
if (this.isSimulator()) {
try {
await this.device.setAppearance(style);
return;
}
catch (e) {
this.log.debug(e.stack);
}
}
try {
await this.proxyCommand('/wda/device/appearance', 'POST', { name: style }, false);
return;
}
catch (e) {
this.log.debug(e.stack);
}
// Fall back to the ugly Siri workaround if the current SDK is too old
await this.mobileSiriCommand(`Turn ${String(style).toLowerCase() === 'dark' ? 'on' : 'off'} dark mode`);
}
/**
* Get the device's UI appearance style.
*
* @since Xcode SDK 11
* @returns The current appearance style
*/
async function mobileGetAppearance() {
if (support_1.util.compareVersions(this.opts.platformVersion, '<', '12.0')) {
return { style: 'unsupported' };
}
let style;
if (this.isSimulator()) {
try {
style = (await this.device.getAppearance());
}
catch { }
}
if (!style) {
const deviceInfo = await this.proxyCommand('/wda/device/info', 'GET');
style = (deviceInfo?.userInterfaceStyle ?? 'unknown');
}
return {
style: style,
};
}
//# sourceMappingURL=appearance.js.map