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

Default window position now recorded and used for new windows #5102

Merged
merged 1 commit into from
Oct 26, 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
4 changes: 3 additions & 1 deletion app/sessionStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ module.exports.cleanPerWindowData = (perWindowData, isShutdown) => {
}
frame.key = newKey
// Full history is not saved yet
// TODO (bsclifton): remove this when https://github.com/brave/browser-laptop/issues/963 is complete
frame.canGoBack = false
frame.canGoForward = false

Expand Down Expand Up @@ -473,6 +474,7 @@ module.exports.defaultAppState = () => {
ignoredTopSites: [],
pinnedTopSites: []
}
}
},
defaultWindowParams: {}
}
}
6 changes: 4 additions & 2 deletions docs/appActions.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,16 @@ Dispatches a message to clear all completed downloads



### setDefaultWindowSize(size)
### defaultWindowParamsChanged(size, position)

Sets the default window size
Sets the default window size / position

**Parameters**

**size**: `Array`, [width, height]

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



### setResourceETag(resourceName, etag)
Expand Down
10 changes: 8 additions & 2 deletions docs/state.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,14 @@ AppStore
enabled: boolean, // true if widevine is installed and enabled
ready: boolean // true if widevine is in a ready state
},
defaultWindowHeight: number,
defaultWindowWidth: number,
defaultWindowHeight: number, // DEPRECATED (0.12.7); replaced w/ defaultWindowParams.height
defaultWindowWidth: number, // DEPRECATED (0.12.7); replaced w/ defaultWindowParams.width
defaultWindowParams: {
height: number,
width: number,
x: number,
y: number
},
updates: {
status: string, // UpdateStatus from js/constants/updateStatus.js
metadata: {
Expand Down
10 changes: 6 additions & 4 deletions js/actions/appActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,15 @@ const appActions = {
},

/**
* Sets the default window size
* Sets the default window size / position
* @param {Array} size - [width, height]
* @param {Array} position - [x, y]
*/
setDefaultWindowSize: function (size) {
defaultWindowParamsChanged: function (size, position) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

++ on declarative event naming

AppDispatcher.dispatch({
actionType: AppConstants.APP_SET_DEFAULT_WINDOW_SIZE,
size
actionType: AppConstants.APP_DEFAULT_WINDOW_PARAMS_CHANGED,
size,
position
})
},

Expand Down
38 changes: 20 additions & 18 deletions js/components/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const ipc = electron.ipcRenderer
const systemPreferences = electron.remote.systemPreferences

// Actions
const appActions = require('../actions/appActions')
const windowActions = require('../actions/windowActions')
const webviewActions = require('../actions/webviewActions')
const contextMenus = require('../contextMenus')
Expand Down Expand Up @@ -479,40 +480,41 @@ class Main extends ImmutableComponent {

// Handlers for saving window state
// TODO: revisit this code when window state moves to appStore
const slidingTimerMilliseconds = 1000

const onWindowResize = debounce(function (event) {
const size = event.sender.getSize()
// NOTE: the default window size is whatever the last window resize was
appActions.defaultWindowParamsChanged(size)
windowActions.saveSize(size)
}, slidingTimerMilliseconds)

const onWindowMove = debounce(function (event) {
const position = event.sender.getPosition()
// NOTE: the default window position is whatever the last window move was
appActions.defaultWindowParamsChanged(undefined, position)
windowActions.savePosition(position)
}, slidingTimerMilliseconds)

currentWindow.on('maximize', function () {
windowActions.setMaximizeState(true)
})

currentWindow.on('unmaximize', function () {
windowActions.setMaximizeState(false)
})

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

currentWindow.on('resize', onWindowResize)
currentWindow.on('move', onWindowMove)
currentWindow.on('focus', function () {
windowActions.onFocusChanged(true)
})

currentWindow.on('blur', function () {
appActions.windowBlurred(currentWindow.id)
windowActions.onFocusChanged(false)
})

let moveTimeout = null
currentWindow.on('move', function (event) {
if (moveTimeout) {
clearTimeout(moveTimeout)
}
moveTimeout = setTimeout(function () {
windowActions.savePosition(event.sender.getPosition())
}, 1000)
})
// Full screen as in F11 (not full screen on a video)
currentWindow.on('enter-full-screen', function (event) {
windowActions.setWindowFullScreen(true)
})

currentWindow.on('leave-full-screen', function (event) {
windowActions.setWindowFullScreen(false)
})
Expand Down
2 changes: 1 addition & 1 deletion js/constants/appConstants.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const AppConstants = {
APP_ADD_PASSWORD: _, /** @param {Object} passwordDetail */
APP_REMOVE_PASSWORD: _, /** @param {Object} passwordDetail */
APP_CLEAR_PASSWORDS: _,
APP_SET_DEFAULT_WINDOW_SIZE: _,
APP_DEFAULT_WINDOW_PARAMS_CHANGED: _,
APP_SET_DATA_FILE_ETAG: _,
APP_SET_DATA_FILE_LAST_CHECK: _,
APP_SET_RESOURCE_ENABLED: _,
Expand Down
38 changes: 19 additions & 19 deletions js/stores/appStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ const createWindow = (browserOpts, defaults, frameOpts, windowState) => {
browserOpts.y = firstDefinedValue(browserOpts.y, windowState.ui.position[1])
}

browserOpts.x = firstDefinedValue(browserOpts.x, browserOpts.left, browserOpts.screenX)
browserOpts.y = firstDefinedValue(browserOpts.y, browserOpts.top, browserOpts.screenY)
browserOpts.x = firstDefinedValue(browserOpts.x, browserOpts.left, browserOpts.screenX, defaults.x)
browserOpts.y = firstDefinedValue(browserOpts.y, browserOpts.top, browserOpts.screenY, defaults.y)
delete browserOpts.left
delete browserOpts.top

Expand Down Expand Up @@ -167,15 +167,6 @@ const createWindow = (browserOpts, defaults, frameOpts, windowState) => {
mainWindow.setFullScreen(true)
}

mainWindow.on('blur', function () {
appActions.windowBlurred(mainWindow.id)
})

mainWindow.on('resize', function (evt) {
// the default window size is whatever the last window resize was
appActions.setDefaultWindowSize(evt.sender.getSize())
})

mainWindow.on('close', function () {
LocalShortcuts.unregister(mainWindow)
})
Expand Down Expand Up @@ -265,8 +256,10 @@ function windowDefaults () {

return {
show: false,
width: appState.get('defaultWindowWidth'),
height: appState.get('defaultWindowHeight'),
width: appState.getIn(['defaultWindowParams', 'width']) || appState.get('defaultWindowWidth'),
height: appState.getIn(['defaultWindowParams', 'height']) || appState.get('defaultWindowHeight'),
x: appState.getIn(['defaultWindowParams', 'x']),
y: appState.getIn(['defaultWindowParams', 'y']),
minWidth: 480,
minHeight: 300,
minModalHeight: 100,
Expand All @@ -291,9 +284,10 @@ function setDefaultWindowSize () {
}
const screen = electron.screen
const primaryDisplay = screen.getPrimaryDisplay()
if (!appState.get('defaultWindowWidth') && !appState.get('defaultWindowHeight')) {
appState = appState.set('defaultWindowWidth', primaryDisplay.workAreaSize.width)
appState = appState.set('defaultWindowHeight', primaryDisplay.workAreaSize.height)
if (!appState.getIn(['defaultWindowParams', 'width']) && !appState.get('defaultWindowWidth') &&
!appState.getIn(['defaultWindowParams', 'height']) && !appState.get('defaultWindowHeight')) {
appState = appState.setIn(['defaultWindowParams', 'width'], primaryDisplay.workAreaSize.width)
appState = appState.setIn(['defaultWindowParams', 'height'], primaryDisplay.workAreaSize.height)
}
}

Expand Down Expand Up @@ -458,9 +452,15 @@ const handleAppAction = (action) => {
case AppConstants.APP_CLEAR_HISTORY:
appState = appState.set('sites', siteUtil.clearHistory(appState.get('sites')))
break
case AppConstants.APP_SET_DEFAULT_WINDOW_SIZE:
appState = appState.set('defaultWindowWidth', action.size[0])
appState = appState.set('defaultWindowHeight', action.size[1])
case AppConstants.APP_DEFAULT_WINDOW_PARAMS_CHANGED:
if (action.size && action.size.size === 2) {
appState = appState.setIn(['defaultWindowParams', 'width'], action.size.get(0))
appState = appState.setIn(['defaultWindowParams', 'height'], action.size.get(1))
}
if (action.position && action.position.size === 2) {
appState = appState.setIn(['defaultWindowParams', 'x'], action.position.get(0))
appState = appState.setIn(['defaultWindowParams', 'y'], action.position.get(1))
}
break
case AppConstants.APP_SET_DATA_FILE_ETAG:
appState = appState.setIn([action.resourceName, 'etag'], action.etag)
Expand Down