1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.ensureSimulatorAppRunningAsync = ensureSimulatorAppRunningAsync;
|
7 | exports.isSimulatorAppRunningAsync = isSimulatorAppRunningAsync;
|
8 | exports.killAllAsync = killAllAsync;
|
9 | exports.openSimulatorAppAsync = openSimulatorAppAsync;
|
10 | exports.waitForSimulatorAppToStart = waitForSimulatorAppToStart;
|
11 | function osascript() {
|
12 | const data = _interopRequireWildcard(require("@expo/osascript"));
|
13 | osascript = function () {
|
14 | return data;
|
15 | };
|
16 | return data;
|
17 | }
|
18 | function _spawnAsync() {
|
19 | const data = _interopRequireDefault(require("@expo/spawn-async"));
|
20 | _spawnAsync = function () {
|
21 | return data;
|
22 | };
|
23 | return data;
|
24 | }
|
25 | function _child_process() {
|
26 | const data = require("child_process");
|
27 | _child_process = function () {
|
28 | return data;
|
29 | };
|
30 | return data;
|
31 | }
|
32 | function _util() {
|
33 | const data = require("util");
|
34 | _util = function () {
|
35 | return data;
|
36 | };
|
37 | return data;
|
38 | }
|
39 | function _internal() {
|
40 | const data = require("../../internal");
|
41 | _internal = function () {
|
42 | return data;
|
43 | };
|
44 | return data;
|
45 | }
|
46 | function _waitForActionAsync() {
|
47 | const data = require("./waitForActionAsync");
|
48 | _waitForActionAsync = function () {
|
49 | return data;
|
50 | };
|
51 | return data;
|
52 | }
|
53 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
54 | function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
55 | function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
56 | const execAsync = (0, _util().promisify)(_child_process().exec);
|
57 | async function waitForSimulatorAppToStart() {
|
58 | return (0, _waitForActionAsync().waitForActionAsync)({
|
59 | interval: 50,
|
60 | action: isSimulatorAppRunningAsync
|
61 | });
|
62 | }
|
63 |
|
64 |
|
65 |
|
66 |
|
67 | async function isSimulatorAppRunningAsync() {
|
68 | try {
|
69 | const zeroMeansNo = (await osascript().execAsync('tell app "System Events" to count processes whose name is "Simulator"')).trim();
|
70 | if (zeroMeansNo === '0') {
|
71 | return false;
|
72 | }
|
73 | } catch (error) {
|
74 | if (error.message.includes('Application isn’t running')) {
|
75 | return false;
|
76 | }
|
77 | throw error;
|
78 | }
|
79 | return true;
|
80 | }
|
81 | async function ensureSimulatorAppRunningAsync({
|
82 | udid
|
83 | }) {
|
84 |
|
85 | if (!(await isSimulatorAppRunningAsync())) {
|
86 | _internal().Logger.global.info(`\u203A Opening the iOS simulator, this might take a moment.`);
|
87 |
|
88 |
|
89 |
|
90 | await openSimulatorAppAsync({
|
91 | udid
|
92 | });
|
93 | if (!(await waitForSimulatorAppToStart())) {
|
94 | throw new (_waitForActionAsync().TimeoutError)(`Simulator app did not open fast enough. Try opening Simulator first, then running your app.`);
|
95 | }
|
96 | }
|
97 | }
|
98 | async function openSimulatorAppAsync({
|
99 | udid
|
100 | }) {
|
101 | const args = ['open', '-a', 'Simulator'];
|
102 | if (udid) {
|
103 |
|
104 | args.push('--args', '-CurrentDeviceUDID', udid);
|
105 | }
|
106 | await execAsync(args.join(' '));
|
107 | }
|
108 | async function killAllAsync() {
|
109 | return await (0, _spawnAsync().default)('killAll', ['Simulator']);
|
110 | }
|
111 |
|
\ | No newline at end of file |