Skip to content
This repository has been archived by the owner on Dec 11, 2019. It is now read-only.

Windows are restored with the correct z-index #10580

Merged
merged 1 commit into from
Sep 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions app/browser/reducers/windowsReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,14 +278,23 @@ const createWindow = (state, action) => {
const appStore = require('../../../js/stores/appStore')
win.webContents.setZoomLevel(zoomLevel[toolbarUserInterfaceScale] || 0.0)

const position = win.getPosition()
const size = win.getSize()

const mem = muon.shared_memory.create({
windowValue: {
disposition: frameOpts.disposition,
id: win.id
id: win.id,
focused: win.isFocused(),
left: position[0],
top: position[1],
height: size[1],
width: size[0]
},
appState: appStore.getLastEmittedState().toJS(),
frames: frames.toJS(),
windowState: (restoredImmutableWindowState && restoredImmutableWindowState.toJS()) || undefined})
windowState: (restoredImmutableWindowState && restoredImmutableWindowState.toJS()) || undefined
})

e.sender.sendShared(messages.INITIALIZE_WINDOW, mem)
if (action.cb) {
Expand Down
1 change: 0 additions & 1 deletion app/browser/windows.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,6 @@ const api = {
LocalShortcuts.register(win)

appActions.windowCreated(windowValue)
windowActions.onWindowUpdate(windowId, windowValue)
})
win.once('closed', () => {
})
Expand Down
20 changes: 17 additions & 3 deletions app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,23 @@ app.on('ready', () => {
appActions.newWindow()
}
} else {
loadedPerWindowImmutableState.forEach((wndState) => {
appActions.newWindow(undefined, undefined, wndState)
})
loadedPerWindowImmutableState
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe as a follow up, it would be good to pull out the sorting into something which can easily be unit tested. Maybe a new method determineZindex or similar (maybe in app/commmon/state/windowState)

then the below would be like:

const sortedList = windowState.determineZindex(loadedPerWindowImmutableStore)
sortedList.forEach((wndState) => {
  appActions.newWindow(undefined, undefined, wndState)
})

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

++!

.sort((a, b) => {
let comparison = 0
const aTime = a.getIn(['windowInfo', 'focusTime'], 0)
const bTime = b.getIn(['windowInfo', 'focusTime'], 0)

if (aTime > bTime) {
comparison = 1
} else if (aTime < bTime) {
comparison = -1
}

return comparison
})
.forEach((wndState) => {
appActions.newWindow(undefined, undefined, wndState)
})
}
process.emit(messages.APP_INITIALIZED)

Expand Down
8 changes: 6 additions & 2 deletions js/actions/appActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,14 @@ const appActions = {
})
},

windowReady: function (windowId) {
windowReady: function (windowId, windowValue) {
dispatch({
actionType: appConstants.APP_WINDOW_READY,
windowId
windowId,
windowValue,
queryInfo: {
windowId
}
})
},

Expand Down
2 changes: 1 addition & 1 deletion js/entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ ipc.on(messages.INITIALIZE_WINDOW, (e, mem) => {
appStoreRenderer.state = Immutable.fromJS(message.appState)
windowStore.state = newState
generateTabs(newState, message.frames, windowValue.id)
appActions.windowReady(windowValue.id)
appActions.windowReady(windowValue.id, windowValue)
ReactDOM.render(<Window />, document.getElementById('appContainer'))
})

Expand Down
15 changes: 13 additions & 2 deletions js/stores/windowStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can just use window.performance and avoid this.


const appDispatcher = require('../dispatcher/appDispatcher')
const EventEmitter = require('events').EventEmitter
const appActions = require('../actions/appActions')
Expand Down Expand Up @@ -769,8 +771,17 @@ const doAction = (action) => {
break
}
case windowConstants.WINDOW_ON_WINDOW_UPDATE:
windowState = windowState.set('windowInfo', action.windowValue)
break
case appConstants.APP_WINDOW_READY:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you did a follow up, this would be fairly easy to add a unit test for too 😄 Basically checking that focusTime gets added to windowInfo

{
const oldInfo = windowState.get('windowInfo', Immutable.Map())
let windowValue = makeImmutable(action.windowValue)

if (windowValue.get('focused')) {
windowValue = windowValue.set('focusTime', performance.timing.navigationStart + performance.now())
}
windowState = windowState.set('windowInfo', oldInfo.merge(windowValue))
break
}
default:
break
}
Expand Down