Skip to content

Commit

Permalink
Fix shell crash (#297)
Browse files Browse the repository at this point in the history
* Updated README

Added explanation for missing parameters (background, title and image)

* Implemented changable icons for AppleScriptTouchBarItem

AppleScriptTouchBarItem now allow to specify any number of icons which can be changed from the script. You cannot change icon from touch event. To change icon, you need to return array from your script with 2 values - title and icn name. More info in readme

* 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)

Co-authored-by: Fedor Zaitsev <lobster@Fedors-MacBook-Pro.local>
  • Loading branch information
FedorZaytsev and Fedor Zaitsev authored Apr 21, 2020
1 parent 502f989 commit 52758f9
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions MTMR/ShellScriptTouchBarItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down

0 comments on commit 52758f9

Please sign in to comment.