Merge pull request #158 from mandrichenko/master

Several fixes about chrome application window (size and state)
This commit is contained in:
R. Aidan Campbell 2017-01-22 10:12:50 -05:00 committed by GitHub
commit 497b450054
3 changed files with 73 additions and 7 deletions

View File

@ -1,8 +1,32 @@
chrome.app.runtime.onLaunched.addListener(function() {
function createWindow(state) {
chrome.app.window.create('index.html', {
state: "normal",
state: state,
bounds: {
width: 850, height: 500
}
width: 960,
height: 540
}
}, function(window) {
// workaround:
// state = 'normal' in some cases not work (e.g. starting app from 'chrome://extensions' always open window in fullscreen mode)
// it requires manually restoring window state to 'normal'
if (state == 'normal') {
setTimeout(function() { window.restore(); }, 1000);
}
});
}
chrome.app.runtime.onLaunched.addListener(function() {
var windowState = 'normal';
if (chrome.storage) {
// load stored window state
chrome.storage.sync.get('windowState', function(item) {
windowState = (item && item.windowState)
? item.windowState
: windowState;
createWindow(windowState);
});
} else {
createWindow(windowState);
}
});

View File

@ -3,6 +3,9 @@ var activePolls = {}; // hosts currently being polled. An associated array of
var pairingCert;
var myUniqueid;
var api; // `api` should only be set if we're in a host-specific screen. on the initial screen it should always be null.
var isInGame = false; // flag indicating whether the game stream started
var windowState = 'normal'; // chrome's windowState, possible values: 'normal' or 'fullscreen'
// Called by the common.js module.
function attachListeners() {
@ -31,6 +34,35 @@ function fullscreenChromeWindow() {
chrome.app.window.current().fullscreen();
}
function loadWindowState() {
if (!chrome.storage) { return; }
chrome.storage.sync.get('windowState', function(item) {
// load stored window state
windowState = (item && item.windowState)
? item.windowState
: windowState;
// subscribe to chrome's windowState events
chrome.app.window.current().onFullscreened.addListener(onFullscreened);
chrome.app.window.current().onBoundsChanged.addListener(onBoundsChanged);
});
}
function onFullscreened() {
if (!isInGame && windowState == 'normal') {
storeData('windowState', 'fullscreen', null);
windowState = 'fullscreen';
}
}
function onBoundsChanged() {
if (!isInGame && windowState == 'fullscreen') {
storeData('windowState', 'normal', null);
windowState = 'normal';
}
}
function changeUiModeForNaClLoad() {
$('.mdl-layout__header').children().hide();
$("#main-content").children().not("#listener, #naclSpinner").hide();
@ -529,6 +561,8 @@ function startGame(host, appID) {
function playGameMode() {
console.log("entering play game mode");
isInGame = true;
$(".mdl-layout__header").hide();
$("#main-content").children().not("#listener, #loadingSpinner").hide();
$("#main-content").addClass("fullscreen");
@ -585,6 +619,8 @@ function stopGameWithConfirmation() {
}
function stopGame(host, callbackFunction) {
isInGame = false;
if (!host.paired) {
return;
}
@ -695,6 +731,8 @@ function onWindowLoad(){
// don't show the game selection div
$('#gameSelection').css('display', 'none');
loadWindowState();
if(chrome.storage) {
// load stored resolution prefs
chrome.storage.sync.get('resolution', function(previousValue) {

View File

@ -30,7 +30,11 @@ function handleMessage(msg) {
});
});
showApps(api);
chrome.app.window.current().restore();
isInGame = false;
// restore main window from 'fullscreen' to 'normal' mode (if required)
(windowState == 'normal') && chrome.app.window.current().restore();
});
} else if(msg.data === 'Connection Established') {