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

Save the window size (width, height) and use it when restoring from s… #4482

Merged
merged 1 commit into from
Oct 4, 2016
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
3 changes: 2 additions & 1 deletion docs/state.md
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,8 @@ WindowStore
closedFrames: [], // holds the same type of frame objects as above
ui: {
isMaximized: boolean, // true if window is maximized
position: array, // last known window position
position: array, // last known window position [x, y]
size: array, // last known window size [x, y]
isFullScreen: boolean, // true if window is fullscreen
mouseInTitlebar: boolean, //Whether or not the mouse is in the titlebar
dragging: {
Expand Down
10 changes: 10 additions & 0 deletions docs/windowActions.md
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,16 @@ Saves the position of the window in the window state



### saveSize(size)

Saves the size (width, height) of the window in the window state

**Parameters**

**size**: `Array`, [x, y]



### setWindowFullScreen(isFullScreen)

Sets the fullscreen state of the window
Expand Down
11 changes: 11 additions & 0 deletions js/actions/windowActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -807,6 +807,17 @@ const windowActions = {
})
},

/**
* Saves the size (width, height) of the window in the window state
* @param {Array} size - [x, y]
*/
saveSize: function (size) {
dispatch({
actionType: WindowConstants.WINDOW_SAVE_SIZE,
size
})
},

/**
* Sets the fullscreen state of the window
* @param {boolean} isFullScreen - true if window is fullscreen
Expand Down
5 changes: 5 additions & 0 deletions js/components/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,7 @@ class Main extends ImmutableComponent {
}

// Handlers for saving window state
// TODO: revisit this code when window state moves to appStore
currentWindow.on('maximize', function () {
windowActions.setMaximizeState(true)
})
Expand All @@ -492,6 +493,10 @@ class Main extends ImmutableComponent {
windowActions.setMaximizeState(false)
})

currentWindow.on('resize', function (event) {
windowActions.saveSize(event.sender.getSize())
})

let moveTimeout = null
currentWindow.on('move', function (event) {
if (moveTimeout) {
Expand Down
1 change: 1 addition & 0 deletions js/constants/windowConstants.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ const windowConstants = {
WINDOW_SET_FAVICON: _,
WINDOW_SET_MAXIMIZE_STATE: _,
WINDOW_SAVE_POSITION: _,
WINDOW_SAVE_SIZE: _,
WINDOW_SET_FULLSCREEN_STATE: _,
WINDOW_SET_MOUSE_IN_TITLEBAR: _,
WINDOW_SET_FINDBAR_SHOWN: _, // whether the findbar is shown
Expand Down
5 changes: 5 additions & 0 deletions js/stores/appStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ function navbarHeight () {
const createWindow = (browserOpts, defaults, frameOpts, windowState) => {
const parentWindowKey = browserOpts.parentWindowKey

if (windowState.ui && windowState.ui.size) {
browserOpts.width = firstDefinedValue(browserOpts.width, windowState.ui.size[0])
browserOpts.height = firstDefinedValue(browserOpts.height, windowState.ui.size[1])
}

browserOpts.width = firstDefinedValue(browserOpts.width, browserOpts.innerWidth, defaults.width)
// height and innerHeight are the frame webview size
browserOpts.height = firstDefinedValue(browserOpts.height, browserOpts.innerHeight)
Expand Down
3 changes: 3 additions & 0 deletions js/stores/windowStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,9 @@ const doAction = (action) => {
case WindowConstants.WINDOW_SAVE_POSITION:
windowState = windowState.setIn(['ui', 'position'], action.position)
break
case WindowConstants.WINDOW_SAVE_SIZE:
windowState = windowState.setIn(['ui', 'size'], action.size)
break
case WindowConstants.WINDOW_SET_FULLSCREEN_STATE:
windowState = windowState.setIn(['ui', 'isFullScreen'], action.isFullScreen)
break
Expand Down