Skip to content

Commit

Permalink
Save window appState into windowState when closing a window
Browse files Browse the repository at this point in the history
Resolves brave#8600
Resolves brave#9709

Auditors:

Test Plan:
  • Loading branch information
NejcZdovc committed Aug 13, 2017
1 parent 36d9141 commit b37fdfe
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 4 deletions.
19 changes: 18 additions & 1 deletion app/common/state/windowState.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,14 @@ const api = {
index = parseInt(index)
assert.ok(index >= 0, 'index must be positive')
state = validateState(state)
return state.set('windows', state.get('windows').delete(index))
const window = state.getIn(['windows', index])

if (window == null) {
return state
}

state = state.set('windows', state.get('windows').delete(index))
return state.set('lastClosedWindow', window)
},

removeWindow: (state, action) => {
Expand Down Expand Up @@ -182,6 +189,16 @@ const api = {
!windowState.getIn(['ui', 'noScriptInfo', 'isVisible']) &&
frame && !frame.getIn(['security', 'loginRequiredDetail']) &&
!windowState.getIn(['ui', 'menubar', 'selectedIndex'])
},

getLastClosedWindow: (state, windowId) => {
state = validateState(state)

if (state.getIn(['lastClosedWindow', 'windowId']) === windowId) {
return state.get('lastClosedWindow')
}

return null
}
}

Expand Down
1 change: 0 additions & 1 deletion app/renderer/components/main/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,6 @@ class Main extends React.Component {
}
}, { passive: true })


// disable dnd by default
window.addEventListener('dragover', function (event) {
// allow webviews to handle dnd
Expand Down
8 changes: 6 additions & 2 deletions js/entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,12 @@ ipc.on(messages.CLEAR_CLOSED_FRAMES, () => {
windowActions.clearClosedFrames()
})

window.addEventListener('beforeunload', function (e) {
ipc.send(messages.LAST_WINDOW_STATE, windowStore.getState().toJS())
window.addEventListener('beforeunload', function () {
const windowState = require('../app/common/state/windowState')
const window = windowState.getLastClosedWindow(appStoreRenderer.state, currentWindow.getCurrentWindowId())
const state = windowStore.getState()
state.set('appData', window)
ipc.send(messages.LAST_WINDOW_STATE, state.toJS())
})

ipc.on(messages.INITIALIZE_WINDOW, (e, mem) => {
Expand Down
11 changes: 11 additions & 0 deletions js/stores/appStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,16 @@ const setWindowPosition = (browserOpts, defaults, immutableWindowState) => {
}

const createWindow = (action) => {
// debugger
const frameOpts = (action.frameOpts && action.frameOpts.toJS()) || {}
let browserOpts = (action.browserOpts && action.browserOpts.toJS()) || {}
const immutableWindowState = action.restoredState || Immutable.Map()
const defaults = windowDefaults()

console.log(frameOpts)
console.log(browserOpts)
console.log(immutableWindowState.toJS())

browserOpts = setWindowDimensions(browserOpts, defaults, immutableWindowState)
browserOpts = setWindowPosition(browserOpts, defaults, immutableWindowState)

Expand Down Expand Up @@ -202,6 +207,9 @@ const createWindow = (action) => {
const startupSetting = getSetting(settings.STARTUP_MODE)
const toolbarUserInterfaceScale = getSetting(settings.TOOLBAR_UI_SCALE)

console.log('create')
console.log(browserOpts)

setImmediate(() => {
let mainWindow = new BrowserWindow(Object.assign(windowProps, browserOpts, {disposition: frameOpts.disposition}))
let restoredImmutableWindowState = action.restoredState
Expand Down Expand Up @@ -233,10 +241,13 @@ const createWindow = (action) => {
frames = Immutable.fromJS([{}])
}

// TODO refactor
if (immutableWindowState.getIn(['ui', 'isMaximized'])) {
console.log('max')
mainWindow.maximize()
}

// TODO refactor
if (immutableWindowState.getIn(['ui', 'isFullScreen'])) {
mainWindow.setFullScreen(true)
}
Expand Down

0 comments on commit b37fdfe

Please sign in to comment.