mirror of
https://github.com/moonlight-stream/moonlight-chrome.git
synced 2025-08-17 16:46:31 +00:00
added popup for auto-canceling currently running app
This commit is contained in:
parent
53b29aad69
commit
1a4ea5daf4
14
index.html
14
index.html
@ -89,6 +89,20 @@
|
||||
<button type="button" class="mdl-button mdl-js-button mdl-button--raised mdl-button--colored" id="CancelPairingDialog">Cancel</button>
|
||||
</div>
|
||||
</dialog>
|
||||
|
||||
<dialog id="replaceAppDialog" class="mdl-dialog">
|
||||
<h3 class="mdl-dialog__title">Pairing</h3>
|
||||
<div class="mdl-dialog__content">
|
||||
<p id="replaceAppDialogText">
|
||||
You wanted to start game X. Game Y is already running. Would you like to stop Game Y to start Game X?
|
||||
</p>
|
||||
</div>
|
||||
<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="ContinueReplaceApp">Yes</button>
|
||||
</div>
|
||||
</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>
|
||||
|
@ -6,15 +6,18 @@ var api;
|
||||
|
||||
// Called by the common.js module.
|
||||
function attachListeners() {
|
||||
$('#pairButton').on('click', pairPushed);
|
||||
$('#showAppsButton').on('click', showAppsPushed);
|
||||
$('#selectResolution').on('change', saveResolution);
|
||||
$('#selectFramerate').on('change', saveFramerate);
|
||||
$('#bitrateSlider').on('input', updateBitrateField); // input occurs every notch you slide
|
||||
$('#bitrateSlider').on('change', saveBitrate); // change occurs once the mouse lets go.
|
||||
$('#startGameButton').on('click', startSelectedGame);
|
||||
$('#quitGameButton').on('click', stopGame);
|
||||
$('#pairButton').on('click', pairPushed);
|
||||
$('#cancelPairingDialog').on('click', pairingPopupCanceled);
|
||||
$('#showAppsButton').on('click', showAppsPushed);
|
||||
$('#selectGame').on('change', gameSelectUpdated);
|
||||
$('#startGameButton').on('click', startSelectedGame);
|
||||
$('#CancelReplaceApp').on('click', cancelReplaceApp);
|
||||
$('#ContinueReplaceApp').on('click', continueReplaceApp);
|
||||
$('#quitGameButton').on('click', stopGame);
|
||||
$(window).resize(fullscreenNaclModule);
|
||||
}
|
||||
|
||||
@ -90,9 +93,6 @@ function pairPushed() {
|
||||
document.getElementById('pairingDialogText').innerHTML =
|
||||
'Please enter the number ' + randomNumber + ' on the GFE dialog on the computer. This dialog will be dismissed once complete';
|
||||
pairingDialog.showModal();
|
||||
pairingDialog.querySelector('#CancelPairingDialog').addEventListener('click', function() {
|
||||
pairingDialog.close();
|
||||
});
|
||||
console.log('sending pairing request to ' + target + ' with random number ' + randomNumber);
|
||||
sendMessage('pair', [target, randomNumber]).then(function (ret3) {
|
||||
console.log('"pair" call returned.');
|
||||
@ -123,6 +123,10 @@ function pairPushed() {
|
||||
});
|
||||
}
|
||||
|
||||
function pairingPopupCanceled() {
|
||||
document.querySelector('#pairingDialog').close();
|
||||
}
|
||||
|
||||
// someone pushed the "show apps" button.
|
||||
// if they entered something in the GFEHostIPField, use that.
|
||||
// otherwise, we assume they selected from the host history dropdown.
|
||||
@ -160,6 +164,7 @@ function showAppsMode() {
|
||||
// every time the user selects an app from the select menu,
|
||||
// we want to check if that's the currently running app
|
||||
// and if it is, we want the "run" button to change to "resume"
|
||||
// in theory we should be able to cache the api.currentGame to prevent another call.
|
||||
function gameSelectUpdated() {
|
||||
var currentApp = $("#selectGame").val();
|
||||
api.refreshServerInfo().then(function (ret) {
|
||||
@ -179,17 +184,26 @@ function startSelectedGame() {
|
||||
if(!api || !api.paired) {
|
||||
api = new NvHTTP(target, myUniqueid);
|
||||
}
|
||||
var appID = $("#selectGame")[0].options[$("#selectGame")[0].selectedIndex].value;
|
||||
var appID = $("#selectGame")[0].options[$("#selectGame")[0].selectedIndex].value; // app that the user wants to play
|
||||
// refresh the server info, because the user might have quit the game.
|
||||
api.refreshServerInfo().then(function (ret) {
|
||||
if(api.currentGame != 0 && api.currentGame != appID) {
|
||||
api.getAppById(api.currentGame).then(function (currentApp) {
|
||||
snackbarLog('Error: ' + target + ' is already in app: ' + currentApp.title);
|
||||
|
||||
var replaceAppDialog = document.querySelector('#replaceAppDialog');
|
||||
document.getElementById('replaceAppDialogText').innerHTML =
|
||||
'You wanted to start a new game. ' + currentApp.title + ' is already running. Would you like to stop ' + currentApp.title + ', then start the new game?';
|
||||
replaceAppDialog.showModal();
|
||||
console.log('finished getAppById promise. returning.');
|
||||
return;
|
||||
});
|
||||
console.log('ERROR! host is already in an app.');
|
||||
console.log('finished api being in another game. returning out of startSelectedGame');
|
||||
return;
|
||||
}
|
||||
|
||||
api.getAppById(appID).then(function (requestedApp) {
|
||||
snackbarLog('Starting app: ' + requestedApp.title);
|
||||
});
|
||||
var frameRate = $("#selectFramerate").val();
|
||||
var streamWidth = $('#selectResolution option:selected').val().split(':')[0];
|
||||
var streamHeight = $('#selectResolution option:selected').val().split(':')[1];
|
||||
@ -215,9 +229,22 @@ function startSelectedGame() {
|
||||
sendMessage('startRequest', [target, streamWidth, streamHeight, frameRate, bitrate.toString(), api.serverMajorVersion.toString()]);
|
||||
});
|
||||
});
|
||||
console.log('finished startSelectedGame.');
|
||||
playGameMode();
|
||||
}
|
||||
|
||||
function cancelReplaceApp() {
|
||||
showAppsMode();
|
||||
document.querySelector('#replaceAppDialog').close();
|
||||
console.log('closing app dialog, and returning');
|
||||
}
|
||||
|
||||
function continueReplaceApp() {
|
||||
console.log('stopping game, and closing app dialog, and returning');
|
||||
stopGame(startSelectedGame); // stop the game, then start the selected game once it's done.
|
||||
document.querySelector('#replaceAppDialog').close();
|
||||
}
|
||||
|
||||
function playGameMode() {
|
||||
console.log("entering play game mode");
|
||||
$(".mdl-layout__header").hide();
|
||||
@ -246,17 +273,21 @@ function fullscreenNaclModule() {
|
||||
module.style.paddingTop = ((screenHeight - module.height) / 2) + "px";
|
||||
}
|
||||
|
||||
function stopGame() {
|
||||
function stopGame(callbackFunction) {
|
||||
api.refreshServerInfo().then(function (ret) {
|
||||
api.getAppById(api.currentGame).then(function (runningApp) {
|
||||
if (!runningApp) {
|
||||
snackbarLog('Nothing was running');
|
||||
return;
|
||||
}
|
||||
var appName = runningApp.title;
|
||||
snackbarLog('Stopping ' + appName);
|
||||
return api.quitApp().then(function (ret2) {
|
||||
gameSelectUpdated(); // once we quit the app, refresh the button text
|
||||
api.quitApp().then(function (ret2) {
|
||||
showAppsMode();
|
||||
if (typeof(callbackFunction) === "function") callbackFunction();
|
||||
});
|
||||
});
|
||||
});
|
||||
showAppsMode();
|
||||
}
|
||||
|
||||
function storeData(key, data, callbackFunction) {
|
||||
@ -349,7 +380,7 @@ function onWindowLoad(){
|
||||
if (savedUniqueid.uniqueid != null) { // we have a saved uniqueid
|
||||
myUniqueid = savedUniqueid.uniqueid;
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user