From 49960ea74bb6985007d4d6146bf8d0f996bb081d Mon Sep 17 00:00:00 2001 From: NejcZdovc Date: Fri, 18 Aug 2017 11:36:49 +0200 Subject: [PATCH] Adds z-index for windows when restoring from the session Resolves #10473 Auditors: Test Plan: --- app/browser/windows.js | 10 +++++++++- app/common/lib/windowUtil.js | 9 +++++++++ app/index.js | 21 ++++++++++++++++++--- js/actions/windowActions.js | 10 ++++++++++ js/constants/windowConstants.js | 3 ++- js/stores/windowStore.js | 18 ++++++++++++++++-- 6 files changed, 64 insertions(+), 7 deletions(-) create mode 100644 app/common/lib/windowUtil.js diff --git a/app/browser/windows.js b/app/browser/windows.js index 9cd26606ce1..e32b1d844c5 100644 --- a/app/browser/windows.js +++ b/app/browser/windows.js @@ -64,6 +64,14 @@ const updateWindow = (windowId, updateDefault = false) => { } } +const updateWindowFocus = (windowId) => { + const windowValue = getWindowValue(windowId) + if (windowValue) { + appActions.windowUpdated(windowValue) + windowActions.onWindowFocus(windowId, windowValue) + } +} + const updatePinnedTabs = (win) => { if (win.webContents.browserWindowOptions.disposition === 'new-popup') { return @@ -201,7 +209,7 @@ const api = { updateWindowDebounce(windowId) }) win.on('focus', () => { - updateWindowDebounce(windowId, true) + updateWindowFocus(windowId) }) win.on('show', () => { updateWindowDebounce(windowId) diff --git a/app/common/lib/windowUtil.js b/app/common/lib/windowUtil.js new file mode 100644 index 00000000000..a44675ad0c7 --- /dev/null +++ b/app/common/lib/windowUtil.js @@ -0,0 +1,9 @@ +const sortWindows = (windows, focusedIndex) => { + const newWindows = windows.get(focusedIndex).set('order', -10) + + return newWindows +} + +module.exports = { + sortWindows +} diff --git a/app/index.js b/app/index.js index 3cc89d1706c..536f2cecc77 100644 --- a/app/index.js +++ b/app/index.js @@ -188,9 +188,24 @@ app.on('ready', () => { appActions.newWindow() } } else { - loadedPerWindowImmutableState.forEach((wndState) => { - appActions.newWindow(undefined, undefined, wndState) - }) + loadedPerWindowImmutableState + .sort((a, b) => { + let comparison = 0 + const aTime = a.getIn(['appData', 'focusTime'], 0) + const bTime = b.getIn(['appData', 'focusTime'], 0) + + if (aTime > bTime) { + comparison = 1 + } else if (aTime < bTime) { + comparison = -1 + } + + return comparison + }) + .forEach((wndState) => { + console.log(wndState.getIn(['frames', 0, 'src'])) + appActions.newWindow(undefined, undefined, wndState) + }) } process.emit(messages.APP_INITIALIZED) diff --git a/js/actions/windowActions.js b/js/actions/windowActions.js index 21a001542ee..82e793889a4 100644 --- a/js/actions/windowActions.js +++ b/js/actions/windowActions.js @@ -1211,6 +1211,16 @@ const windowActions = { }, windowValue }) + }, + + onWindowFocus: function (windowId, windowValue) { + dispatch({ + actionType: windowConstants.WINDOW_ON_WINDOW_FOCUS, + queryInfo: { + windowId + }, + windowValue + }) } } diff --git a/js/constants/windowConstants.js b/js/constants/windowConstants.js index 1f6ce8db614..32e2d6f7c66 100644 --- a/js/constants/windowConstants.js +++ b/js/constants/windowConstants.js @@ -109,7 +109,8 @@ const windowConstants = { WINDOW_ON_ADD_BOOKMARK_FOLDER: _, WINDOW_ON_EDIT_BOOKMARK_FOLDER: _, WINDOW_ON_BOOKMARK_FOLDER_CLOSE: _, - WINDOW_ON_WINDOW_UPDATE: _ + WINDOW_ON_WINDOW_UPDATE: _, + WINDOW_ON_WINDOW_FOCUS: _ } module.exports = mapValuesByKeys(windowConstants) diff --git a/js/stores/windowStore.js b/js/stores/windowStore.js index ccf4ce0882d..fef3ee61f35 100644 --- a/js/stores/windowStore.js +++ b/js/stores/windowStore.js @@ -2,6 +2,8 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at http://mozilla.org/MPL/2.0/. */ +/* global performance */ + const AppDispatcher = require('../dispatcher/appDispatcher') const EventEmitter = require('events').EventEmitter const appActions = require('../actions/appActions') @@ -816,8 +818,20 @@ const doAction = (action) => { break } case windowConstants.WINDOW_ON_WINDOW_UPDATE: - windowState = windowState.set('windowInfo', action.windowValue) - break + { + const oldInfo = windowState.get('windowInfo') + windowState = windowState.set('windowInfo', oldInfo.merge(action.windowValue)) + break + } + case windowConstants.WINDOW_ON_WINDOW_FOCUS: + { + let value = makeImmutable(action.windowValue) + if (value) { + value = value.set('focusTime', performance.timing.navigationStart + performance.now()) + windowState = windowState.set('windowInfo', value) + } + break + } default: break }