Bugfix: window state not restored in normal mode after streaming.

Bugfix: window always run in fullscreen mode when app launched from chrome://apps or chrome://extensions
This commit is contained in:
Dmitry Mandrichenko 2017-01-21 04:04:58 +02:00
parent 5ebcc58ae3
commit e9ccbb08d3
3 changed files with 62 additions and 32 deletions

View File

@ -1,8 +1,25 @@
var windowState = 'normal';
function createWindow(state) {
chrome.app.window.create('index.html', {
state: state,
bounds: {
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 settings
// load stored window state
chrome.storage.sync.get('windowState', function(item) {
windowState = (item && item.windowState)
? item.windowState
@ -13,33 +30,3 @@ chrome.app.runtime.onLaunched.addListener(function() {
createWindow(windowState);
}
});
function createWindow(state) {
chrome.app.window.create('index.html', {
state: state,
bounds: {
width: 960,
height: 540
}
}, function(window) {
window.onFullscreened.addListener(onFullscreened);
window.onBoundsChanged.addListener(onBoundsChanged);
});
}
function onFullscreened() {
// save windowState: 'fullscreen'
windowState != 'fullscreen' && saveItem('windowState', 'fullscreen', null);
}
function onBoundsChanged() {
// save windowState: 'normal'
windowState != 'normal' && saveItem('windowState', 'normal', null);
}
function saveItem(key, value, callback) {
var item = { };
item[key] = value;
chrome.storage && chrome.storage.sync.set(item, callback);
}

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,6 +30,11 @@ function handleMessage(msg) {
});
});
showApps(api);
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') {