From 5ebcc58ae31b4ad3c7ead44d51e2be82d19a32cf Mon Sep 17 00:00:00 2001 From: Dmitry Mandrichenko Date: Wed, 21 Dec 2016 08:32:50 +0200 Subject: [PATCH] Window state restored with previous saved window state (fullscreen or normal). Window startup size changed to 16:9 aspect ratio = 960x540. After closing the game, window restored in previous state. --- static/js/background.js | 47 ++++++++++++++++++++++++++++++++++++----- static/js/messages.js | 1 - 2 files changed, 42 insertions(+), 6 deletions(-) diff --git a/static/js/background.js b/static/js/background.js index 02c2dd6..ed880e1 100644 --- a/static/js/background.js +++ b/static/js/background.js @@ -1,8 +1,45 @@ +var windowState = 'normal'; + chrome.app.runtime.onLaunched.addListener(function() { + if (chrome.storage) { + // load stored window settings + chrome.storage.sync.get('windowState', function(item) { + windowState = (item && item.windowState) + ? item.windowState + : windowState; + createWindow(windowState); + }); + } else { + createWindow(windowState); + } +}); + +function createWindow(state) { chrome.app.window.create('index.html', { - state: "normal", - bounds: { - width: 850, height: 500 - } + state: state, + bounds: { + width: 960, + height: 540 + } + }, function(window) { + window.onFullscreened.addListener(onFullscreened); + window.onBoundsChanged.addListener(onBoundsChanged); }); -}); \ No newline at end of file +} + + +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); +} \ No newline at end of file diff --git a/static/js/messages.js b/static/js/messages.js index 5cfcea6..d524a62 100644 --- a/static/js/messages.js +++ b/static/js/messages.js @@ -30,7 +30,6 @@ function handleMessage(msg) { }); }); showApps(api); - chrome.app.window.current().restore(); }); } else if(msg.data === 'Connection Established') {