Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 30 additions & 29 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,30 +1,31 @@
.DS_Store

*.js
*.d.ts
!/*.js
!bin/ios-sim-portable.js
!scripts/*.js
*.js.map

lib-cov
*.seed
*.log
*.csv
*.dat
*.out
*.pid
*.gz
*.tgz
*.tmp
tscommand*.tmp.txt
.tscache/
/lib/.d.ts

.idea/

test-reports.xml

npm-debug.log
node_modules
.DS_Store

*.js
*.d.ts
!/*.js
!bin/ios-sim-portable.js
!scripts/*.js
!test/*.js
*.js.map

lib-cov
*.seed
*.log
*.csv
*.dat
*.out
*.pid
*.gz
*.tgz
*.tmp
tscommand*.tmp.txt
.tscache/
/lib/.d.ts

.idea/

test-reports.xml

npm-debug.log
node_modules
package-lock.json
2 changes: 2 additions & 0 deletions lib/declarations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ interface ISkipErrorComposition {
interface ISimctl {
launch(deviceId: string, applicationIdentifier: string, options: IOptions): Promise<string>;
boot(deviceId: string): Promise<void>;
bootAndWait(deviceId: string): Promise<void>;
getAppPid(deviceId: string, appIdentifier: string): Promise<number | null>;
terminate(deviceId: string, appIdentifier: string): Promise<string>;
install(deviceId: string, applicationPath: string): Promise<void>;
uninstall(deviceId: string, applicationIdentifier: string, opts?: ISkipErrorComposition): Promise<void>;
Expand Down
80 changes: 15 additions & 65 deletions lib/ios-sim.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as _ from "lodash";
import { delay } from "./utils";

function getSimulator(): ISimulator {
let libraryPath = require("./iphone-simulator");
Expand All @@ -10,80 +11,29 @@ const publicApi = {};

Object.defineProperty(publicApi, "getRunningSimulator", {
get: () => {
return (...args: any[]) => {
let isResolved = false;

return new Promise<any>((resolve, reject) => {
let libraryPath = require("./iphone-simulator-xcode-simctl");
let simulator = new libraryPath.XCodeSimctlSimulator();

const tryGetBootedDevice = () => {
try {
return simulator.getBootedDevice.apply(simulator, args);
} catch (err) {
if (!isResolved) {
isResolved = true;
reject(err);
}
}
return async (...args: any[]) => {
const libraryPath = require("./iphone-simulator-xcode-simctl");
const simulator = new libraryPath.XCodeSimctlSimulator();

for (let attempt = 0; attempt < 30; attempt++) {
const device = await simulator.getBootedDevice(...args);
if (device) {
return device;
}
await delay(500);
}

let result = tryGetBootedDevice();

if (!isResolved && !result) {
let repeatCount = 30;
let timer = setInterval(() => {
result = tryGetBootedDevice();
if ((result || !repeatCount) && !isResolved) {
isResolved = true;
clearInterval(timer);
resolve(result);
}
repeatCount--;
}, 500);
}
});
return simulator.getBootedDevice(...args);
}
}
});

Object.defineProperty(publicApi, "getRunningSimulators", {
get: () => {
return (...args: any[]) => {
let isResolved = false;

return new Promise<any>(async (resolve, reject) => {
const libraryPath = require("./iphone-simulator-xcode-simctl");
const simulator = new libraryPath.XCodeSimctlSimulator();

const tryGetBootedDevices = async () => {
try {
return await simulator.getBootedDevices.apply(simulator, args);
} catch (err) {
if (!isResolved) {
isResolved = true;
reject(err);
}
}
}

let result = await tryGetBootedDevices();
if (result && result.length) {
isResolved = true;
resolve(result);
return;
}

if (!isResolved && (!result || !result.length)) {
const timer = setTimeout(async () => {
result = await tryGetBootedDevices();
if (!isResolved) {
isResolved = true;
resolve(result);
}
}, 500);
}
});
const libraryPath = require("./iphone-simulator-xcode-simctl");
const simulator = new libraryPath.XCodeSimctlSimulator();
return simulator.getBootedDevices(...args);
}
}
});
Expand Down
33 changes: 11 additions & 22 deletions lib/iphone-simulator-common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ export function getInstalledApplications(deviceId: string): IApplication[] {
applicationDirContents,
(fileName) => path.extname(fileName) === ".app"
);
// Left behind by an install that didn't finish.
if (!applicationName) {
return;
}
let plistFilePath = path.join(
fullApplicationPath,
applicationName,
Expand All @@ -51,28 +55,13 @@ export function getInstalledApplications(deviceId: string): IApplication[] {
return result;
}

export function startSimulator(xcodeVersion: number, deviceId?: string
): void {
let args = ["open"];
if(xcodeVersion<27) {
let simulatorPath = path.resolve(
xcode.getPathFromXcodeSelect(),
"Applications",
"Simulator.app"
);
args.push(simulatorPath);
if (deviceId) {
args.push("--args", "-CurrentDeviceUDID", deviceId);
}
} else {
let simulatorPath = path.resolve(
xcode.getPathFromXcodeSelect(),"..",
"Applications",
"DeviceHub.app"
);
args.push(simulatorPath);
}
childProcess.execSync(args.join(" "));
export async function startSimulatorApp(xcodeVersion: number): Promise<void> {
const xcodePath = await xcode.getPathFromXcodeSelect();
await childProcess.spawn("open", [
xcodeVersion >= 27
? path.resolve(xcodePath, "..", "Applications", "DeviceHub.app")
: path.resolve(xcodePath, "Applications", "Simulator.app"),
]);
}

function parsePlist(fileNameOrBuffer: string | Buffer) {
Expand Down
Loading
Loading