mirror of
https://github.com/Toxblh/MTMR.git
synced 2026-01-10 17:08:39 +00:00
Fixed error related to ShellButton
When you execute Process from swift you cannot relay solely on pipe.fileHandleForReading.readDataToEndOfFile() Sometimes when I close notebook I get exception saying that you cannot access process.terminationStatus variable while process is running. Apparently it seems that this call can be finished when OS X put disks into sleep mode(?) What I did: 1. Added Process.waitUntilExit() call 2. Added timeout (equal to the update interval)
This commit is contained in:
parent
c51b6acdf1
commit
542f70d189
@ -62,11 +62,19 @@ class ShellScriptTouchBarItem: CustomButtonTouchBarItem {
|
||||
|
||||
let pipe = Pipe()
|
||||
task.standardOutput = pipe
|
||||
|
||||
// kill process if it is over update interval
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + interval) { [weak task] in
|
||||
task?.terminate()
|
||||
}
|
||||
|
||||
task.launch()
|
||||
|
||||
let data = pipe.fileHandleForReading.readDataToEndOfFile()
|
||||
var output: String = NSString(data: data, encoding: String.Encoding.utf8.rawValue) as String? ?? ""
|
||||
|
||||
//always wait until task end or you can catch "task still running" error while accessing task.terminationStatus variable
|
||||
task.waitUntilExit()
|
||||
if (output == "" && task.terminationStatus != 0) {
|
||||
output = "error"
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user