diff --git a/app/common/state/windowState.js b/app/common/state/windowState.js index 8b9505b7c78..39301c6d000 100644 --- a/app/common/state/windowState.js +++ b/app/common/state/windowState.js @@ -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) => { @@ -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 } } diff --git a/app/renderer/components/main/main.js b/app/renderer/components/main/main.js index 3276e4b0649..ca5c1daf4eb 100644 --- a/app/renderer/components/main/main.js +++ b/app/renderer/components/main/main.js @@ -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 diff --git a/js/entry.js b/js/entry.js index 12e060b627b..6e41ce1faf7 100644 --- a/js/entry.js +++ b/js/entry.js @@ -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) => { diff --git a/js/stores/appStore.js b/js/stores/appStore.js index eeefc8a2455..67bca0a62fa 100644 --- a/js/stores/appStore.js +++ b/js/stores/appStore.js @@ -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) @@ -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 @@ -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) }