From 7e255ce71b762853865dae9d2de8ed8de5315419 Mon Sep 17 00:00:00 2001 From: Joshua Granick Date: Mon, 17 Oct 2016 14:34:44 -0700 Subject: [PATCH] Improve iOS simulator behavior --- lime/tools/helpers/IOSHelper.hx | 48 ++++++++++++++++++++--------- lime/tools/helpers/ProcessHelper.hx | 10 ++++-- 2 files changed, 40 insertions(+), 18 deletions(-) diff --git a/lime/tools/helpers/IOSHelper.hx b/lime/tools/helpers/IOSHelper.hx index 29f27e8af..9d6bca2e0 100644 --- a/lime/tools/helpers/IOSHelper.hx +++ b/lime/tools/helpers/IOSHelper.hx @@ -263,26 +263,21 @@ class IOSHelper { } - ProcessHelper.runCommand ("", "open", [ "-a", "Simulator", "--args", "-CurrentDeviceUDID", currentDeviceID ], true, true); - ProcessHelper.runCommand ("", "open", [ "-a", "iOS Simulator", "--args", "-CurrentDeviceUDID", currentDeviceID ], true, true); - - while (true) { + try { - output = ProcessHelper.runProcess ("", "xcrun", [ "simctl", "install", currentDeviceID, applicationPath ], true, true, true); + ProcessHelper.runProcess ("", "open", [ "-Ra", "iOS Simulator" ], true, false); + ProcessHelper.runCommand ("", "open", [ "-a", "iOS Simulator", "--args", "-CurrentDeviceUDID", currentDeviceID ]); - if (output != null && output.toLowerCase ().indexOf ("invalid device state") > -1) { - - Sys.sleep (3); - - } else { - - break; - - } + } catch (e:Dynamic) { + + ProcessHelper.runCommand ("", "open", [ "-a", "Simulator", "--args", "-CurrentDeviceUDID", currentDeviceID ]); } - ProcessHelper.runProcess ("", "xcrun", [ "simctl", "launch", currentDeviceID, project.meta.packageName ]); + waitForDeviceState ("xcrun", [ "simctl", "uninstall", currentDeviceID, project.meta.packageName ]); + waitForDeviceState ("xcrun", [ "simctl", "install", currentDeviceID, applicationPath ]); + waitForDeviceState ("xcrun", [ "simctl", "launch", currentDeviceID, project.meta.packageName ]); + ProcessHelper.runCommand ("", "tail", [ "-f", "~/Library/Logs/CoreSimulator/" + currentDeviceID + "/system.log"]); } else { @@ -349,4 +344,27 @@ class IOSHelper { } + private static function waitForDeviceState (command:String, args:Array):Void { + + var output; + + while (true) { + + output = ProcessHelper.runProcess ("", command, args, true, true, true); + + if (output != null && output.toLowerCase ().indexOf ("invalid device state") > -1) { + + Sys.sleep (3); + + } else { + + break; + + } + + } + + } + + } \ No newline at end of file diff --git a/lime/tools/helpers/ProcessHelper.hx b/lime/tools/helpers/ProcessHelper.hx index 9c2739291..5c5474e39 100644 --- a/lime/tools/helpers/ProcessHelper.hx +++ b/lime/tools/helpers/ProcessHelper.hx @@ -284,7 +284,7 @@ class ProcessHelper { } - return _runProcess (path, command, args, waitForOutput, ignoreErrors); + return _runProcess (path, command, args, waitForOutput, safeExecute, ignoreErrors); } catch (e:Dynamic) { @@ -300,14 +300,14 @@ class ProcessHelper { } else { - return _runProcess (path, command, args, waitForOutput, ignoreErrors); + return _runProcess (path, command, args, waitForOutput, safeExecute, ignoreErrors); } } - private static function _runProcess (path:String, command:String, args:Array, waitForOutput:Bool, ignoreErrors:Bool):String { + private static function _runProcess (path:String, command:String, args:Array, waitForOutput:Bool, safeExecute:Bool, ignoreErrors:Bool):String { var oldPath:String = ""; @@ -390,6 +390,10 @@ class ProcessHelper { output = error; + } else if (!safeExecute) { + + throw error; + } else { LogHelper.error (error);