Fix hosts not persisting in the grid and duplicating when returning to the PC screen

This commit is contained in:
Cameron Gutman 2016-07-10 21:47:28 -07:00
parent 3767990bb0
commit 237fcdeef8

View File

@ -130,15 +130,6 @@ function pairTo(host, onSuccess, onFailure) {
snackbarLog('Pairing successful'); snackbarLog('Pairing successful');
pairingDialog.close(); pairingDialog.close();
var cell = document.createElement('div');
cell.className += 'mdl-cell mdl-cell--3-col';
cell.id = 'hostgrid-' + host;
cell.innerHTML = host;
$('#host-grid').append(cell);
cell.onclick = hostChosen;
saveHosts();
onSuccess(); onSuccess();
}, function (failedPairing) { }, function (failedPairing) {
@ -162,17 +153,10 @@ function hostChosen(sourceEvent) {
api = new NvHTTP(host, myUniqueid); api = new NvHTTP(host, myUniqueid);
api.refreshServerInfo().then(function (ret) { api.refreshServerInfo().then(function (ret) {
if(!api.paired) { if(!api.paired) {
pairTo(host); pairTo(host, function(){ showApps(); }, function(){});
} else {
showApps();
} }
if(hosts.indexOf(host) < 0) { // we don't have this host in our list. add it, and save it.
var cell = document.createElement('div');
cell.className += 'mdl-cell mdl-cell--3-col';
cell.id = 'hostgrid-' + host;
cell.innerHTML = host;
$('#host-grid').append(cell);
cell.onclick = hostChosen;
}
showApps();
}, function (failedRefreshInfo) { }, function (failedRefreshInfo) {
snackbarLog('Failed to connect to ' + host + '! Are you sure the host is on?'); snackbarLog('Failed to connect to ' + host + '! Are you sure the host is on?');
console.log('Returned error was: ' + failedRefreshInfo); console.log('Returned error was: ' + failedRefreshInfo);
@ -190,14 +174,30 @@ function cancelAddHost() {
document.querySelector('#addHostDialog').close(); document.querySelector('#addHostDialog').close();
} }
function addHostToGrid(host) {
if(hosts.indexOf(host) < 0) { // we don't have this host in our list. add it, and save it.
var cell = document.createElement('div');
cell.className += 'mdl-cell mdl-cell--3-col';
cell.id = 'hostgrid-' + host;
cell.innerHTML = host;
$('#host-grid').append(cell);
cell.onclick = hostChosen;
hosts.push(host);
saveHosts();
}
}
function continueAddHost() { function continueAddHost() {
var inputHost = $('#dialogInputHost').val(); var inputHost = $('#dialogInputHost').val();
pairTo(inputHost, pairTo(inputHost,
function() { document.querySelector('#addHostDialog').close() }, function() {
function() {snackbarLog('pairing to ' + inputHost + ' failed!');} addHostToGrid(inputHost);
); document.querySelector('#addHostDialog').close();
},
function() {
snackbarLog('pairing to ' + inputHost + ' failed!');
});
} }
// locally remove the hostname/ip from the saved `hosts` array. // locally remove the hostname/ip from the saved `hosts` array.
@ -535,12 +535,7 @@ function onWindowLoad(){
var ips = Object.keys(finder.byService_['_nvstream._tcp']); var ips = Object.keys(finder.byService_['_nvstream._tcp']);
for (var ip in ips) { for (var ip in ips) {
if (finder.byService_['_nvstream._tcp'][ip]) { if (finder.byService_['_nvstream._tcp'][ip]) {
var cell = document.createElement('div'); addHostToGrid(ip);
cell.className += 'mdl-cell mdl-cell--3-col';
cell.id = 'hostgrid-' + ip;
cell.innerHTML = ip;
$('#host-grid').append(cell);
cell.onclick = hostChosen;
} }
} }
} }