-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Simplify get simulator command + reduce launch time #31
Changes from 10 commits
362e6ee
0b68fbb
6b7f5cc
eee7560
fc1568d
8ad4589
7cea75f
e3a46d0
80da3e1
15337fe
2286a26
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,14 +4,8 @@ import CommandsCore | |
class InspectorViewController: NSViewController, NSTableViewDataSource { | ||
let commands = CommandsCore.CommandExecutor() | ||
let applicationStateHandler = ApplicationStateHandler() | ||
var runDeviceTask:Process! | ||
var runDeviceTask1:Process! | ||
var runDeviceTask2:Process! | ||
var buildTaskNew558:Process! | ||
var textViewPrinter: TextViewPrinter! | ||
@objc dynamic var isRunning = false | ||
var outputPipe:Pipe! | ||
let defaults = UserDefaults.standard | ||
let env = ProcessInfo.processInfo.environment as [String: String] | ||
let fileManager = FileManager.default | ||
var uiElements: [String] = [] | ||
var parentCollection: [String] = [] | ||
|
@@ -218,28 +212,15 @@ class InspectorViewController: NSViewController, NSTableViewDataSource { | |
} | ||
|
||
func getElementsByOffset(_ arguments:[String]) { | ||
let taskQueue6 = DispatchQueue.global(qos: .background) | ||
taskQueue6.async { | ||
let path = Constants.FilePaths.Bash.elementsByOffset | ||
self.runDeviceTask = Process() | ||
self.runDeviceTask.launchPath = path | ||
self.runDeviceTask.arguments = arguments | ||
self.runDeviceTask.launch() | ||
} | ||
commands.executeCommand(at: Constants.FilePaths.Bash.elementsByOffset ?? "", arguments: arguments) | ||
} | ||
|
||
func getElements() { | ||
let taskQueue7 = DispatchQueue.global(qos: .background) | ||
|
||
taskQueue7.async { | ||
let path = Constants.FilePaths.Bash.elements | ||
self.runDeviceTask1 = Process() | ||
self.runDeviceTask1.launchPath = path | ||
if let filePath = self.applicationStateHandler.filePath { | ||
self.runDeviceTask1.arguments = [filePath.absoluteString] | ||
} | ||
self.runDeviceTask1.launch() | ||
var arguments: [String] = [] | ||
if let filePath = self.applicationStateHandler.filePath { | ||
arguments = [filePath.absoluteString] | ||
} | ||
commands.executeCommand(at: Constants.FilePaths.Bash.elements ?? "", arguments: arguments) | ||
} | ||
|
||
|
||
|
@@ -250,18 +231,23 @@ class InspectorViewController: NSViewController, NSTableViewDataSource { | |
|
||
func startDevice() { | ||
try? fileManager.removeItem(atPath: "/tmp/screenshot_0.png") | ||
let taskQueue8 = DispatchQueue.global(qos: .background) | ||
|
||
taskQueue8.async { | ||
let path = Constants.FilePaths.Bash.startDevice | ||
self.runDeviceTask2 = Process() | ||
self.runDeviceTask2.launchPath = path | ||
if let launchPath = Constants.FilePaths.Bash.startDevice { | ||
let outputStream = CommandsCore.CommandTextOutputStream() | ||
outputStream.textHandler = { text in | ||
if !text.isEmpty { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe make this |
||
DispatchQueue.main.async { | ||
self.textViewPrinter.printToTextView(text) | ||
} | ||
} | ||
} | ||
var arguments: [String] = [] | ||
if let phoneUDID = self.applicationStateHandler.phoneUDID { | ||
self.runDeviceTask2.arguments = [phoneUDID] | ||
arguments = [phoneUDID] | ||
} | ||
DispatchQueue.global(qos: .background).async { | ||
self.commands.executeCommand(at: launchPath, arguments: arguments, outputStream: outputStream) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this run on a background thread (but eg. https://github.com/JoeSSS/calabash-launcher/pull/31/files#diff-8622fb2ab735c45bc8f54aee4b135938R223 isn't?) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are some methods like running tests or this one that takes a lot of time to continue. If I do it in the main thread, it will freeze the whole APP, but we actually can use the APP while these commands are executing in background |
||
} | ||
self.captureStandardOutputAndRouteToTextView(self.runDeviceTask2) | ||
self.runDeviceTask2.launch() | ||
self.runDeviceTask2.waitUntilExit() | ||
} | ||
|
||
self.waitingForFile(fileName: "/tmp/screenshot_0.png", numberOfRetries: 9999) { | ||
|
@@ -274,34 +260,6 @@ class InspectorViewController: NSViewController, NSTableViewDataSource { | |
} | ||
} | ||
|
||
func captureStandardOutputAndRouteToTextView(_ task:Process) { | ||
|
||
outputPipe = Pipe() | ||
task.standardOutput = outputPipe | ||
|
||
outputPipe.fileHandleForReading.waitForDataInBackgroundAndNotify() | ||
|
||
NotificationCenter.default.addObserver(forName: .NSFileHandleDataAvailable, object: outputPipe.fileHandleForReading, queue: nil) { notification in | ||
|
||
let output = self.outputPipe.fileHandleForReading.availableData | ||
let outputString = String(data: output, encoding: .utf8) ?? "" | ||
|
||
DispatchQueue.main.async { | ||
let previousOutput = self.outputText.string | ||
|
||
if !outputString.isEmpty { | ||
|
||
let nextOutput = previousOutput + "\n" + outputString | ||
self.outputText.string = nextOutput | ||
|
||
let range = NSRange(location: nextOutput.count, length: 0) | ||
self.outputText.scrollRangeToVisible(range) | ||
} | ||
} | ||
self.outputPipe.fileHandleForReading.waitForDataInBackgroundAndNotify() | ||
} | ||
} | ||
|
||
@objc func getScreenProcsLoop() { | ||
syncScreen() | ||
waitingForFile(fileName: "/tmp/screenshot_0.png", numberOfRetries: 50, enableSpinner: false) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@q231950 Not sure why it is needed. Sometimes we get a lot of empty strings after actual result.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess somewhere in the script an empty line is generated.