Skip to content

Commit

Permalink
Access webview only from main thread
Browse files Browse the repository at this point in the history
  • Loading branch information
yury committed Jul 7, 2017
1 parent 73c134a commit 90f35cb
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
6 changes: 4 additions & 2 deletions Blink/TermView.m
Original file line number Diff line number Diff line change
Expand Up @@ -343,8 +343,10 @@ - (void)write:(NSString *)data
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:@[ data ] options:0 error:nil];
NSString *jsString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
NSString *jsScript = [NSString stringWithFormat:@"write_to_term(%@[0])", jsString];

[_webView evaluateJavaScript:jsScript completionHandler:nil];

dispatch_async(dispatch_get_main_queue(), ^{
[_webView evaluateJavaScript:jsScript completionHandler:nil];
});
}

- (NSString *)title
Expand Down
6 changes: 4 additions & 2 deletions Sessions/MCPSession.m
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,10 @@ - (int)main:(int)argc argv:(char **)argv

- (void)showConfig
{
[[UIApplication sharedApplication]
sendAction:NSSelectorFromString(@"showConfig:") to:nil from:nil forEvent:nil];
dispatch_async(dispatch_get_main_queue(), ^{
[[UIApplication sharedApplication]
sendAction:NSSelectorFromString(@"showConfig:") to:nil from:nil forEvent:nil];
});
}

- (void)runSSHCopyIDWithArgs:(NSString *)args
Expand Down
11 changes: 9 additions & 2 deletions Sessions/MoshSession.m
Original file line number Diff line number Diff line change
Expand Up @@ -203,11 +203,18 @@ - (int)main:(int)argc argv:(char **)argv
setenv("PATH_LOCALE", [locales_path cStringUsingEncoding:1], 1);

// Mosh does not support scroll. Disable it to avoid problems.
[_stream.control.terminal setScrollEnabled:NO];
dispatch_async(dispatch_get_main_queue(), ^{
[_stream.control.terminal setScrollEnabled:NO];
});

BOOL mode = [_stream.control rawMode];
[_stream.control.terminal setRawMode:YES];
mosh_main(_stream.in, _stream.out, _stream.sz, [_moshParams.ip UTF8String], [_moshParams.port UTF8String], [_moshParams.key UTF8String], [_moshParams.predictionMode UTF8String]);
[_stream.control.terminal setScrollEnabled:YES];

dispatch_async(dispatch_get_main_queue(), ^{
[_stream.control.terminal setScrollEnabled:YES];
});

[_stream.control setRawMode:mode];

fprintf(_stream.out, "\r\nMosh session finished!\r\n");
Expand Down

0 comments on commit 90f35cb

Please sign in to comment.