Skip to content

Commit

Permalink
fix race condition on task output window
Browse files Browse the repository at this point in the history
  • Loading branch information
amitailanciano committed Jan 31, 2015
1 parent d3121e8 commit ba8a171
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions Vagrant Manager/TaskOutputWindow.m
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ - (void)taskCompletion:(NSNotification*)notif {
- (void)windowWillClose:(NSNotification *)notification {
AppDelegate *app = [Util getApp];

_isClosed = YES;
@synchronized(self) {
_isClosed = YES;
}

[app removeTaskOutputWindow:self];
}
Expand All @@ -96,19 +98,21 @@ - (void)receivedOutput:(NSNotification*)notif {
NSData *data = [fh availableData];
NSString *str = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding];

if (!_isClosed) {
//smart scrolling logic for command output
BOOL scroll = (NSMaxY(self.outputTextView.visibleRect) == NSMaxY(self.outputTextView.bounds));
[self.outputTextView.textStorage appendAttributedString:[[NSAttributedString alloc] initWithString:str]];
if([NSFont fontWithName:@"Menlo" size:11]) {
[self.outputTextView.textStorage setFont:[NSFont fontWithName:@"Menlo" size:11]];
}
if (scroll) {
[self.outputTextView scrollRangeToVisible: NSMakeRange(self.outputTextView.string.length, 0)];
}

if(self.task.isRunning) {
[fh waitForDataInBackgroundAndNotify];
@synchronized(self) {
if (!_isClosed) {
//smart scrolling logic for command output
BOOL scroll = (NSMaxY(self.outputTextView.visibleRect) == NSMaxY(self.outputTextView.bounds));
[self.outputTextView.textStorage appendAttributedString:[[NSAttributedString alloc] initWithString:str]];
if([NSFont fontWithName:@"Menlo" size:11]) {
[self.outputTextView.textStorage setFont:[NSFont fontWithName:@"Menlo" size:11]];
}
if (scroll) {
[self.outputTextView scrollRangeToVisible: NSMakeRange(self.outputTextView.string.length, 0)];
}

if(self.task.isRunning) {
[fh waitForDataInBackgroundAndNotify];
}
}
}
}
Expand Down

0 comments on commit ba8a171

Please sign in to comment.