Skip to content

Commit

Permalink
feat: disable pasteboard sync in launching time to improve the perfor…
Browse files Browse the repository at this point in the history
…mance (#262)

* feat: improve launching simulator performance with disabling pasteboard sync

* make disablePasteboardAutomaticSync configuable

* fix review

* tweak docstring

* allow to set pasteboardAutomaticSync as on, off or system

* tweak warning message
  • Loading branch information
KazuCocoa committed Feb 13, 2020
1 parent 936b87b commit a235e03
Showing 1 changed file with 35 additions and 8 deletions.
43 changes: 35 additions & 8 deletions lib/simulator-xcode-6.js
Original file line number Diff line number Diff line change
Expand Up @@ -424,22 +424,32 @@ class SimulatorXcode6 extends EventEmitter {
return indicator;
}


/**
* Start the Simulator UI client with the given arguments
*
* @param {object} opts - One or more of available Simulator UI client options:
* - {string} scaleFactor: can be one of ['1.0', '0.75', '0.5', '0.33', '0.25'].
* Defines the window scale value for the UI client window for the current Simulator.
* @typedef {Object} SimulatorOptions
* @property {?string} scaleFactor [null] - Defines the window scale value for the UI client window for the current Simulator.
* Equals to null by default, which keeps the current scale unchanged.
* - {boolean} connectHardwareKeyboard: whether to connect the hardware keyboard to the
* Simulator UI client. Equals to false by default.
* - {number} startupTimeout: number of milliseconds to wait until Simulator booting
* It should be one of ['1.0', '0.75', '0.5', '0.33', '0.25'].
* @property {boolean} connectHardwareKeyboard [false] - Whether to connect the hardware keyboard to the
* Simulator UI client. Defaults to false.
* @property {string} pasteboardAutomaticSync ['off'] - Whether to disable pasteboard sync with the
* Simulator UI client or respect the system wide preference. 'on', 'off', or 'system' is available.
* The sync increases launching simulator process time, but it allows system to sync pasteboard
* with simulators. Follows system-wide preference if the value is 'system'.
* Defaults to 'off'.
* @property {number} startupTimeout [60000] - Number of milliseconds to wait until Simulator booting
* process is completed. The default timeout will be used if not set explicitly.
*/

/**
* Start the Simulator UI client with the given arguments
* @param {SimulatorOptions} opts - Simulator launching options
*/
async startUIClient (opts = {}) {
opts = Object.assign({
scaleFactor: null,
connectHardwareKeyboard: false,
pasteboardAutomaticSync: 'off',
startupTimeout: this.startupTimeout,
}, opts);

Expand All @@ -457,6 +467,23 @@ class SimulatorXcode6 extends EventEmitter {
args.push('-ConnectHardwareKeyboard', opts.connectHardwareKeyboard ? '1' : '0');
}

switch (_.lowerCase(opts.pasteboardAutomaticSync)) {
case 'on':
args.push('-PasteboardAutomaticSync', '1');
break;
case 'off':
// Improve launching simulator performance
// https://github.com/WebKit/webkit/blob/master/Tools/Scripts/webkitpy/xcode/simulated_device.py#L413
args.push('-PasteboardAutomaticSync', '0');
break;
case 'system':
// Do not add -PasteboardAutomaticSync
break;
default:
log.warn(`['on', 'off' or 'system'] are available as the pasteboard automatic sync option. Defaulting to 'off'.`);
args.push('-PasteboardAutomaticSync', '0');
}

log.info(`Starting Simulator UI with command: open ${args.join(' ')}`);
try {
await exec('open', args, {timeout: opts.startupTimeout});
Expand Down

0 comments on commit a235e03

Please sign in to comment.