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

Commit

Permalink
Hide windows until they are either rendered or a timeout expires
Browse files Browse the repository at this point in the history
Fix #8121
  • Loading branch information
petemill authored and bsclifton committed Nov 20, 2017
1 parent 93d7a77 commit ad50233
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 7 deletions.
57 changes: 51 additions & 6 deletions app/browser/reducers/windowsReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ const appDispatcher = require('../../../js/dispatcher/appDispatcher')
const isDarwin = platformUtil.isDarwin()
const isWindows = platformUtil.isWindows()

const TIMEOUT_WINDOW_SHOW_MS = 5000

// TODO cleanup all this createWindow crap
function isModal (browserOpts) {
// this needs some better checks
Expand Down Expand Up @@ -108,7 +110,6 @@ const setMaximized = (state, browserOpts, immutableWindowState) => {

function windowDefaults (state) {
return {
show: false,
width: state.getIn(['defaultWindowParams', 'width']) || state.get('defaultWindowWidth'),
height: state.getIn(['defaultWindowParams', 'height']) || state.get('defaultWindowHeight'),
x: state.getIn(['defaultWindowParams', 'x']) || undefined,
Expand Down Expand Up @@ -245,7 +246,52 @@ const createWindow = (state, action) => {
const toolbarUserInterfaceScale = getSetting(settings.TOOLBAR_UI_SCALE)

setImmediate(() => {
const win = new BrowserWindow(Object.assign(windowProps, browserOpts, {disposition: frameOpts.disposition}))
// normally macOS will open immediately-created windows from fullscreen
// parent windows as fullscreen
// but since we are showing the window async, we will set the window
// fullscreen once it is ready to be shown
// (browserOpts.fullscreen may already be set when loading from saved state,
// so this just sets it for other scenarios)
if (isDarwin && parentWindow && parentWindow.isFullScreen()) {
windowProps.fullscreen = true
}

const defaultArgs = {
// hide the window until the window reports that it is rendered
show: false,
fullscreenable: true
}
const enforcedArgs = {
disposition: frameOpts.disposition
}
const windowArgs = Object.assign(
defaultArgs,
windowProps,
browserOpts,
enforcedArgs
)
// remember if the window should be opened fullscreen once it is rendered
// and remove the fullscreen property for now
// (otherwise the window will be shown immediately by the OS / muon)
let shouldFullscreen = false
if (!windowArgs.show && windowArgs.fullscreen) {
windowArgs.fullscreen = false
shouldFullscreen = true
}
const win = new BrowserWindow(windowArgs)
// let the windowReady handler know to set the window to fullscreen
win.__shouldFullscreen = shouldFullscreen
if (!windowArgs.show) {
// the window is hidden until render, but we'll check to see
// if it is shown in a timeout as if the window errors it won't send
// the message to ask to be shown
// in those cases, we want to still show it, so that the user can find the error message
setTimeout(() => {
if (win && !win.isDestroyed() && !win.isVisible()) {
win.show()
}
}, TIMEOUT_WINDOW_SHOW_MS)
}
let restoredImmutableWindowState = action.get('restoredState')
initWindowCacheState(win.id, restoredImmutableWindowState)

Expand Down Expand Up @@ -308,10 +354,6 @@ const createWindow = (state, action) => {
}
})

win.on('ready-to-show', () => {
win.show()
})

win.loadURL(appUrlUtil.getBraveExtIndexHTML())
})

Expand All @@ -330,6 +372,9 @@ const windowsReducer = (state, action, immutableAction) => {
case appConstants.APP_WINDOW_READY:
windows.windowReady(action.get('windowId'))
break
case appConstants.APP_WINDOW_RENDERED:
windows.windowRendered(action.get('windowId'))
break
case appConstants.APP_TAB_UPDATED:
if (immutableAction.getIn(['changeInfo', 'pinned']) != null) {
setImmediate(() => {
Expand Down
21 changes: 21 additions & 0 deletions app/browser/windows.js
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,27 @@ const api = {
})
},

windowRendered: (windowId) => {
setImmediate(() => {
const win = currentWindows[windowId]
if (win && !win.isDestroyed() && !win.isVisible()) {
// window is hidden by default until we receive 'ready' message,
// so show it now
win.show()
if (win.__shouldFullscreen) {
// this timeout helps with an issue that
// when a user is loading from state, and
// has many full screen windows and non fullscreen windows
// the non fullscreen windows can get opened on top of the fullscreen
// spaces because macOS has switched away from the desktop space
setTimeout(() => {
win.setFullScreen(true)
}, 100)
}
}
})
},

closeWindow: (windowId) => {
let win = api.getWindow(windowId)
try {
Expand Down
10 changes: 10 additions & 0 deletions js/actions/appActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,16 @@ const appActions = {
})
},

windowRendered: function (windowId) {
dispatch({
actionType: appConstants.APP_WINDOW_RENDERED,
windowId,
queryInfo: {
windowId
}
})
},

closeWindow: function (windowId) {
dispatch({
actionType: appConstants.APP_CLOSE_WINDOW,
Expand Down
1 change: 1 addition & 0 deletions js/constants/appConstants.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const _ = null
const appConstants = {
APP_NEW_WINDOW: _,
APP_WINDOW_READY: _,
APP_WINDOW_RENDERED: _,
APP_CLOSE_WINDOW: _,
APP_WINDOW_CLOSED: _,
APP_WINDOW_CREATED: _,
Expand Down
6 changes: 5 additions & 1 deletion js/entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,13 @@ ipc.on(messages.INITIALIZE_WINDOW, (e, mem) => {
windowStore.state = newState
generateTabs(newState, message.frames, windowValue.id)
appActions.windowReady(windowValue.id, windowValue)
ReactDOM.render(<Window />, document.getElementById('appContainer'))
ReactDOM.render(<Window />, document.getElementById('appContainer'), fireOnReactRender.bind(null, windowValue))
})

const fireOnReactRender = (windowValue) => {
appActions.windowRendered(windowValue.id)
}

const generateTabs = (windowState, frames, windowId) => {
const activeFrameKey = windowState.get('activeFrameKey')

Expand Down

0 comments on commit ad50233

Please sign in to comment.