From 9401443c4f35c7271b3e450850553f485b100f7f Mon Sep 17 00:00:00 2001 From: "R. Aidan Campbell" Date: Sat, 27 Aug 2016 10:15:47 -0400 Subject: [PATCH] quitting apps now has a confirmation dialog --- static/js/index.js | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/static/js/index.js b/static/js/index.js index a4f4e7b..53e5f99 100644 --- a/static/js/index.js +++ b/static/js/index.js @@ -23,7 +23,7 @@ function attachListeners() { $('#cancelQuitApp').on('click', cancelQuitApp); $('#backIcon').on('click', showHostsAndSettingsMode); $('#continueQuitApp').on('click', continueQuitApp); - $('#quitGameButton').on('click', stopGame); + $('#quitCurrentApp').on('click', stopGameWithConfirmation); $(window).resize(fullscreenNaclModule); chrome.app.window.current().onMaximized.addListener(fullscreenChromeWindow); } @@ -470,7 +470,6 @@ function cancelQuitApp() { } function continueQuitApp(sourceEvent) { - // I want the sourceEvent's sourceEvent console.log('stopping game, and closing app dialog, and returning'); stopGame( function() { @@ -479,7 +478,6 @@ function continueQuitApp(sourceEvent) { // wants to set it again. var event = relaunchSourceEvent; relaunchSourceEvent = null; - startGame(event); } } @@ -518,6 +516,20 @@ function fullscreenNaclModule() { module.style.paddingTop = ((screenHeight - module.height) / 2) + "px"; } +function stopGameWithConfirmation() { + if (api.currentGame === 0) { + snackbarLog('Nothing was running'); + } else { + api.getAppById(api.currentGame).then(function (currentGame) { + var quitAppDialog = document.querySelector('#quitAppDialog'); + document.getElementById('quitAppDialogText').innerHTML = + ' Are you sure you would like to quit ' + + currentGame.title + '? Unsaved progress will be lost.'; + quitAppDialog.showModal(); + }); + } +} + function stopGame(callbackFunction) { api.refreshServerInfo().then(function (ret) { api.getAppById(api.currentGame).then(function (runningApp) { @@ -530,10 +542,12 @@ function stopGame(callbackFunction) { api.quitApp().then(function (ret2) { api.refreshServerInfo().then(function (ret3) { // refresh to show no app is currently running. showAppsMode(); + stylizeBoxArt(api, runningApp.id); if (typeof(callbackFunction) === "function") callbackFunction(); }, function (failedRefreshInfo2) { console.log('ERROR: failed to refresh server info!'); console.log('Returned error was: ' + failedRefreshInfo2); + console.log('failed server was: ' + api.toString()); }); }, function (failedQuitApp) { console.log('ERROR: failed to quit app!');