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

Commit

Permalink
Merge pull request #10305 from brave/beach-bawler
Browse files Browse the repository at this point in the history
Stop beach balling with this one simple trick
  • Loading branch information
bbondy committed Aug 9, 2017
1 parent 5fc8b19 commit cccb3dd
Show file tree
Hide file tree
Showing 10 changed files with 545 additions and 395 deletions.
9 changes: 9 additions & 0 deletions app/common/state/immutableUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ const api = {

makeImmutable: (obj) => {
return api.isImmutable(obj) ? obj : Immutable.fromJS(obj)
},

deleteImmutablePaths: (obj, paths) => {
return paths.reduce((result, path) => {
if (path.constructor === Array) {
return result.deleteIn(path)
}
return result.delete(path)
}, obj)
}
}

Expand Down
2 changes: 1 addition & 1 deletion app/common/state/tabState.js
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ const tabState = {
state = tabState.removeTabField(state, 'messageBoxDetail')
state = tabState.removeTabField(state, 'frame')
state = state.delete('tabsInternal')
return state.delete('tabs')
return state.set('tabs', Immutable.List())
},

setNavigationState: (state, tabId, navigationState) => {
Expand Down
3 changes: 2 additions & 1 deletion app/common/state/windowState.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* You can obtain one at http://mozilla.org/MPL/2.0/. */

const { makeImmutable, isMap, isList } = require('./immutableUtil')
const Immutable = require('immutable')
const assert = require('assert')

// TODO(bridiver) - make these generic validation functions
Expand Down Expand Up @@ -154,7 +155,7 @@ const api = {
getPersistentState: (state) => {
// TODO(bridiver) handle restoring state
state = makeImmutable(state)
return state.delete('windows')
return state.set('windows', Immutable.List())
},

// TODO (nejc) we should only pass in one state
Expand Down
31 changes: 15 additions & 16 deletions app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,19 +95,19 @@ const defaultProtocols = ['http', 'https']
let loadAppStatePromise = SessionStore.loadAppState()

// Some settings must be set right away on startup, those settings should be handled here.
loadAppStatePromise.then((initialState) => {
loadAppStatePromise.then((initialImmutableState) => {
telemetry.setCheckpointAndReport('state-loaded')
const {HARDWARE_ACCELERATION_ENABLED, SMOOTH_SCROLL_ENABLED, SEND_CRASH_REPORTS} = require('../js/constants/settings')
if (initialState.settings[HARDWARE_ACCELERATION_ENABLED] === false) {
if (initialImmutableState.getIn('settings', HARDWARE_ACCELERATION_ENABLED) === false) {
app.disableHardwareAcceleration()
}
if (initialState.settings[SEND_CRASH_REPORTS] !== false) {
if (initialImmutableState.getIn(['settings', SEND_CRASH_REPORTS]) !== false) {
console.log('Crash reporting enabled')
CrashHerald.init()
} else {
console.log('Crash reporting disabled')
}
if (initialState.settings[SMOOTH_SCROLL_ENABLED] === false) {
if (initialImmutableState.getIn(['settings', SMOOTH_SCROLL_ENABLED]) === false) {
app.commandLine.appendSwitch('disable-smooth-scrolling')
}
})
Expand Down Expand Up @@ -159,19 +159,18 @@ app.on('ready', () => {
appActions.networkDisconnected()
})

loadAppStatePromise.then((initialState) => {
loadAppStatePromise.then((initialImmutableState) => {
// Do this after loading the state
// For tests we always want to load default app state
const loadedPerWindowState = initialState.perWindowState
delete initialState.perWindowState
const loadedPerWindowImmutableState = initialImmutableState.get('perWindowState')
initialImmutableState = initialImmutableState.delete('perWindowState')
// Retore map order after load
let state = Immutable.fromJS(initialState)
state = state.set('sites', state.get('sites').sort(siteUtil.siteSort))
appActions.setState(state)
setImmediate(() => perWindowStateLoaded(loadedPerWindowState))
initialImmutableState = initialImmutableState.set('sites', initialImmutableState.get('sites').sort(siteUtil.siteSort))
appActions.setState(initialImmutableState)
setImmediate(() => perWindowStateLoaded(loadedPerWindowImmutableState))
})

const perWindowStateLoaded = (loadedPerWindowState) => {
const perWindowStateLoaded = (loadedPerWindowImmutableState) => {
// TODO(bridiver) - this shold be refactored into reducers
// DO NOT ADD ANYHING TO THIS LIST
// See tabsReducer.js for app state init example
Expand All @@ -186,12 +185,12 @@ app.on('ready', () => {
AdInsertion.init()
PDFJS.init()

if (!loadedPerWindowState || loadedPerWindowState.length === 0) {
if (!loadedPerWindowImmutableState || loadedPerWindowImmutableState.size === 0) {
if (!CmdLine.newWindowURL()) {
appActions.newWindow()
}
} else {
loadedPerWindowState.forEach((wndState) => {
loadedPerWindowImmutableState.forEach((wndState) => {
appActions.newWindow(undefined, undefined, wndState)
})
}
Expand Down Expand Up @@ -306,12 +305,12 @@ app.on('ready', () => {
// DO NOT TO THIS LIST - see above

// We need the initial state to read the UPDATE_TO_PREVIEW_RELEASES preference
loadAppStatePromise.then((initialState) => {
loadAppStatePromise.then((initialImmutableState) => {
updater.init(
process.platform,
process.arch,
process.env.BRAVE_UPDATE_VERSION || app.getVersion(),
initialState.settings[settings.UPDATE_TO_PREVIEW_RELEASES]
initialImmutableState.getIn('settings', settings.UPDATE_TO_PREVIEW_RELEASES)
)

// This is fired by a menu entry
Expand Down
Loading

0 comments on commit cccb3dd

Please sign in to comment.