fixed bug in replacing current app

- removed the feature. instead it will just quit the app
- added additional bit for material back icon
This commit is contained in:
R. Aidan Campbell 2016-07-09 19:05:28 -04:00
parent a7fea0051c
commit 88795bc126
2 changed files with 21 additions and 26 deletions

View File

@ -15,6 +15,8 @@
<span class="mdl-layout-title">Moonlight</span> <span class="mdl-layout-title">Moonlight</span>
<!-- Add spacer, to align navigation to the right --> <!-- Add spacer, to align navigation to the right -->
<div class="mdl-layout-spacer"></div> <div class="mdl-layout-spacer"></div>
<!-- Navigation on the right -->
<object type="image/svg+xml" data="static/res/ic_arrow_back_white_24px.svg" id='backIcon'></object>
</div> </div>
</header> </header>
<main id="main-content" class="mdl-layout__content"> <main id="main-content" class="mdl-layout__content">
@ -80,16 +82,16 @@
</div> </div>
</dialog> </dialog>
<dialog id="replaceAppDialog" class="mdl-dialog"> <dialog id="quitAppDialog" class="mdl-dialog">
<h3 class="mdl-dialog__title">Quit Running App?</h3> <h3 class="mdl-dialog__title">Quit Running App?</h3>
<div class="mdl-dialog__content"> <div class="mdl-dialog__content">
<p id="replaceAppDialogText"> <p id="quitAppDialogText">
Y is already running. Would you like to quit Y to start X? Y is already running. Would you like to quit Y?
</p> </p>
</div> </div>
<div class="mdl-dialog__actions"> <div class="mdl-dialog__actions">
<button type="button" class="mdl-button mdl-js-button mdl-button--raised mdl-button--colored" id="cancelReplaceApp">No</button> <button type="button" class="mdl-button mdl-js-button mdl-button--raised mdl-button--colored" id="cancelQuitApp">No</button>
<button type="button" class="mdl-button mdl-js-button mdl-button--raised mdl-button--colored" id="continueReplaceApp">Yes</button> <button type="button" class="mdl-button mdl-js-button mdl-button--raised mdl-button--colored" id="continueQuitApp">Yes</button>
</div> </div>
</dialog> </dialog>

View File

@ -19,8 +19,8 @@ function attachListeners() {
$('#continueAddHost').on('click', continueAddHost); $('#continueAddHost').on('click', continueAddHost);
$('#forgetHost').on('click', forgetHost); $('#forgetHost').on('click', forgetHost);
$('#cancelPairingDialog').on('click', pairingPopupCanceled); $('#cancelPairingDialog').on('click', pairingPopupCanceled);
$('#cancelReplaceApp').on('click', cancelReplaceApp); $('#cancelQuitApp').on('click', cancelQuitApp);
$('#continueReplaceApp').on('click', continueReplaceApp); $('#continueQuitApp').on('click', continueQuitApp);
$('#quitGameButton').on('click', stopGame); $('#quitGameButton').on('click', stopGame);
$(window).resize(fullscreenNaclModule); $(window).resize(fullscreenNaclModule);
chrome.app.window.current().onMaximized.addListener(fullscreenChromeWindow); chrome.app.window.current().onMaximized.addListener(fullscreenChromeWindow);
@ -258,8 +258,8 @@ function showAppsMode() {
$("#streamSettings").hide(); $("#streamSettings").hide();
$("#hostSettings").hide(); $("#hostSettings").hide();
// TODO: grab a material `back` icon to use here
$(".mdl-layout__header-row").append("<button class='mdl-button mdl-js-button mdl-button--fab mdl-button--mini-fab'><i class='material-icons'>arrow_back</i></button>") $('#backIcon').show();
$(".mdl-layout__header").show(); $(".mdl-layout__header").show();
$("#main-content").children().not("#listener, #loadingSpinner, #naclSpinner").show(); $("#main-content").children().not("#listener, #loadingSpinner, #naclSpinner").show();
$("#main-content").removeClass("fullscreen"); $("#main-content").removeClass("fullscreen");
@ -268,7 +268,7 @@ function showAppsMode() {
} }
// start the given appID. if another app is running, offer to quit it and start this one. // start the given appID. if another app is running, offer to quit it.
// if the given app is already running, just resume it. // if the given app is already running, just resume it.
function startGame(sourceEvent) { function startGame(sourceEvent) {
if(!api || !api.paired) { if(!api || !api.paired) {
@ -279,11 +279,6 @@ function startGame(sourceEvent) {
if(sourceEvent && sourceEvent.target) { if(sourceEvent && sourceEvent.target) {
appID = parseInt(sourceEvent.target.id.substring('game-'.length)); // parse the AppID from the ID of the grid icon. appID = parseInt(sourceEvent.target.id.substring('game-'.length)); // parse the AppID from the ID of the grid icon.
appName = sourceEvent.target.name; appName = sourceEvent.target.name;
if(!appID && appName) { // ugly hack to allow us to continue parsing the appID from the sourceEvent (part 2 of 2)
api.getAppByName(appName).then(function (appToPlay) {
appID = appToPlay.id;
});
}
} else { } else {
console.log('Error! failed to parse appID from grid icon! Failing...'); console.log('Error! failed to parse appID from grid icon! Failing...');
snackbarLog('An error occurred while parsing the appID from the grid icon.') snackbarLog('An error occurred while parsing the appID from the grid icon.')
@ -294,12 +289,11 @@ function startGame(sourceEvent) {
api.refreshServerInfo().then(function (ret) { api.refreshServerInfo().then(function (ret) {
if(api.currentGame != 0 && api.currentGame != appID) { if(api.currentGame != 0 && api.currentGame != appID) {
api.getAppById(api.currentGame).then(function (currentApp) { api.getAppById(api.currentGame).then(function (currentApp) {
var replaceAppDialog = document.querySelector('#replaceAppDialog'); var quitAppDialog = document.querySelector('#quitAppDialog');
document.getElementById('replaceAppDialogText').innerHTML = document.getElementById('quitAppDialogText').innerHTML =
currentApp.title + ' is already running. Would you like to quit ' + currentApp.title + ' is already running. Would you like to quit ' +
currentApp.title + ' to start ' + appName+ '?'; currentApp.title + '?';
replaceAppDialog.showModal(); quitAppDialog.showModal();
$('#continueReplaceApp').attr('name', appName);
return; return;
}, function (failedCurrentApp) { }, function (failedCurrentApp) {
console.log('ERROR: failed to get the current running app from host!'); console.log('ERROR: failed to get the current running app from host!');
@ -349,18 +343,17 @@ function startGame(sourceEvent) {
}); });
} }
function cancelReplaceApp() { function cancelQuitApp() {
showAppsMode(); showAppsMode();
document.querySelector('#replaceAppDialog').close(); document.querySelector('#quitAppDialog').close();
console.log('closing app dialog, and returning'); console.log('closing app dialog, and returning');
} }
function continueReplaceApp(sourceEvent) { function continueQuitApp(sourceEvent) {
// I want the sourceEvent's sourceEvent // I want the sourceEvent's sourceEvent
console.log('stopping game, and closing app dialog, and returning'); console.log('stopping game, and closing app dialog, and returning');
stopGame(); // stop the game, then start the selected game once it's done. stopGame();
startGame(sourceEvent); document.querySelector('#quitAppDialog').close();
document.querySelector('#replaceAppDialog').close();
} }
function playGameMode() { function playGameMode() {