Don't call resize several times on instance creation.

Fix a few race conditions for terminal resize and terminal buffer
writing.
This commit is contained in:
Jonathan Leibiusky @xetorthio
2017-08-30 16:36:38 -03:00
parent ed3492eb38
commit e079517803

View File

@@ -116,8 +116,7 @@
url: '/sessions/' + $scope.sessionId + '/instances', url: '/sessions/' + $scope.sessionId + '/instances',
data : { ImageName : InstanceService.getDesiredImage(), type: instanceType } data : { ImageName : InstanceService.getDesiredImage(), type: instanceType }
}).then(function(response) { }).then(function(response) {
var i = $scope.upsertInstance(response.data); $scope.upsertInstance(response.data);
$scope.showInstance(i);
}, function(response) { }, function(response) {
if (response.status == 409) { if (response.status == 409) {
$scope.showAlert('Max instances reached', 'Maximum number of instances reached') $scope.showAlert('Max instances reached', 'Maximum number of instances reached')
@@ -195,11 +194,9 @@
}); });
socket.on('instance new', function(name, ip, hostname, proxyHost) { socket.on('instance new', function(name, ip, hostname, proxyHost) {
$scope.upsertInstance({ name: name, ip: ip, hostname: hostname, proxy_host: proxyHost}); var instance = $scope.upsertInstance({ name: name, ip: ip, hostname: hostname, proxy_host: proxyHost});
$scope.$apply(function() { $scope.$apply(function() {
if ($scope.instances.length == 1) { $scope.showInstance(instance);
$scope.showInstance($scope.instances[0]);
}
}); });
}); });
@@ -209,10 +206,18 @@
}); });
socket.on('instance viewport resize', function(cols, rows) { socket.on('instance viewport resize', function(cols, rows) {
if (cols == 0 || rows == 0) {
return
}
// viewport has changed, we need to resize all terminals // viewport has changed, we need to resize all terminals
$scope.instances.forEach(function(instance) { $scope.instances.forEach(function(instance) {
instance.term.resize(cols, rows); if (instance.term) {
instance.term.resize(cols, rows);
if (instance.buffer) {
instance.term.write(instance.buffer);
instance.buffer = '';
}
}
}); });
}); });
@@ -276,19 +281,16 @@
$scope.showInstance = function(instance) { $scope.showInstance = function(instance) {
$scope.selectedInstance = instance; $scope.selectedInstance = instance;
$location.hash(instance.name); $location.hash(instance.name);
if (!instance.creatingTerminal) { if (!instance.term) {
if (!instance.term) {
$timeout(function() { $timeout(function() {
createTerminal(instance); createTerminal(instance);
TerminalService.setFontSize(TerminalService.getFontSize()); TerminalService.setFontSize(TerminalService.getFontSize());
instance.term.focus(); instance.term.focus();
$timeout(function() {
}, 0, false);
}, 0, false); }, 0, false);
return return
}
} }
$timeout(function() {
instance.term.focus();
}, 0, false);
} }
$scope.removeInstance = function(name) { $scope.removeInstance = function(name) {
@@ -365,9 +367,12 @@
term.open(terminalContainer); term.open(terminalContainer);
// Set geometry during the next tick, to avoid race conditions. // Set geometry during the next tick, to avoid race conditions.
/*
setTimeout(function() { setTimeout(function() {
$scope.resize(term.proposeGeometry()); $scope.resize(term.proposeGeometry());
}, 4); }, 4);
*/
instance.terminalBuffer = ''; instance.terminalBuffer = '';
instance.terminalBufferInterval = setInterval(function() { instance.terminalBufferInterval = setInterval(function() {
@@ -382,11 +387,6 @@
instance.term = term; instance.term = term;
if (instance.buffer) {
term.write(instance.buffer);
instance.buffer = '';
}
if (cb) { if (cb) {
cb(); cb();
} }