now with some toast notifications for logging

This commit is contained in:
R. Aidan Campbell 2016-03-11 12:20:55 -05:00
parent 8bb359714d
commit b2cbd36ec4
3 changed files with 25 additions and 4 deletions

View File

@ -94,6 +94,9 @@
<button type="button" class="mdl-button mdl-js-button mdl-button--raised mdl-button--colored" id="CancelPairingDialog">Cancel</button> <button type="button" class="mdl-button mdl-js-button mdl-button--raised mdl-button--colored" id="CancelPairingDialog">Cancel</button>
</div> </div>
</dialog> </dialog>
<div id="snackbar" class="mdl-js-snackbar mdl-snackbar">
<button class="mdl-snackbar__action" type="button"></button> <!-- this button exists to suppress the snackbar warning. we're really using a toast. -->
<div class="mdl-snackbar__text"></div>
</div>
</body> </body>
</html> </html>

View File

@ -18,7 +18,10 @@
padding: 20px 24px 24px 24px; padding: 20px 24px 24px 24px;
color: rgba(0,0,0, 0.54); color: rgba(0,0,0, 0.54);
} }
.mdl-snackbar {
max-width:50%;
left: 25%;
}
main { main {
padding: 50px 100px; padding: 50px 100px;
} }

View File

@ -19,12 +19,20 @@ function attachListeners() {
$(window).resize(fullscreenNaclModule); $(window).resize(fullscreenNaclModule);
} }
function snackbarLog(givenMessage) {
var data = {
message: givenMessage,
timeout: 5000
};
document.querySelector('#snackbar').MaterialSnackbar.showSnackbar(data);
}
function updateBitrateField() { function updateBitrateField() {
$('#bitrateField').html($('#bitrateSlider')[0].value + " Mbps"); $('#bitrateField').html($('#bitrateSlider')[0].value + " Mbps");
} }
function moduleDidLoad() { function moduleDidLoad() {
console.log("NaCl module loaded."); snackbarLog("NaCl module loaded.");
if(!pairingCert) { // we couldn't load a cert. Make one. if(!pairingCert) { // we couldn't load a cert. Make one.
console.log("Failed to load local cert. Generating new one"); console.log("Failed to load local cert. Generating new one");
@ -67,6 +75,7 @@ function pairPushed() {
return; return;
} }
$('#pairButton')[0].innerHTML = 'Pairing...'; $('#pairButton')[0].innerHTML = 'Pairing...';
snackbarLog('Pairing...');
updateTarget(); updateTarget();
console.log("Attempting to pair to: " + target); console.log("Attempting to pair to: " + target);
sendMessage('httpInit', [pairingCert.cert, pairingCert.privateKey, myUniqueid]).then(function (ret) { sendMessage('httpInit', [pairingCert.cert, pairingCert.privateKey, myUniqueid]).then(function (ret) {
@ -82,6 +91,7 @@ function pairPushed() {
sendMessage('pair', [target, randomNumber]).then(function (ret2) { sendMessage('pair', [target, randomNumber]).then(function (ret2) {
if (ret2 === 0) { // pairing was successful. save this host. if (ret2 === 0) { // pairing was successful. save this host.
$('#pairButton')[0].innerHTML = 'Paired'; $('#pairButton')[0].innerHTML = 'Paired';
snackbarLog('Pairing successful');
pairingDialog.close(); pairingDialog.close();
var hostSelect = $('#selectHost')[0]; var hostSelect = $('#selectHost')[0];
for(var i = 0; i < hostSelect.length; i++) { for(var i = 0; i < hostSelect.length; i++) {
@ -95,6 +105,7 @@ function pairPushed() {
hosts.push(target); hosts.push(target);
saveHosts(); saveHosts();
} else { } else {
snackbarLog('Pairing failed');
$('#pairButton')[0].innerHTML = 'Pairing Failed'; $('#pairButton')[0].innerHTML = 'Pairing Failed';
document.getElementById('pairingDialogText').innerHTML = 'Error: Pairing failed with code: ' + ret2; document.getElementById('pairingDialogText').innerHTML = 'Error: Pairing failed with code: ' + ret2;
} }
@ -199,7 +210,10 @@ function startSelectedGame() {
// then everyone's sad. So we won't do that. Because the only way to see the startGame button is to list the apps for the target anyways. // then everyone's sad. So we won't do that. Because the only way to see the startGame button is to list the apps for the target anyways.
if (api && api.paired) { if (api && api.paired) {
if(api.currentGame != 0) { if(api.currentGame != 0) {
console.log('ERROR! host is already in a game.'); api.getAppById(api.currentGame).then(function (currentApp) {
snackbarLog('Error: ' + target + ' is already in app: ' + currentApp.title);
});
console.log('ERROR! host is already in an app.');
return; return;
} }
var appID = $("#selectGame")[0].options[$("#selectGame")[0].selectedIndex].value; var appID = $("#selectGame")[0].options[$("#selectGame")[0].selectedIndex].value;
@ -262,6 +276,7 @@ function fullscreenNaclModule() {
// user pushed the stop button. we should stop. // user pushed the stop button. we should stop.
function stopPushed() { function stopPushed() {
sendMessage('stopRequested'); sendMessage('stopRequested');
snackbarLog('stopRequested');
} }
function stopGame() { function stopGame() {