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 #3393 from brave/about-actions
Browse files Browse the repository at this point in the history
don't send unnecessary ipc messages
  • Loading branch information
bbondy authored Aug 25, 2016
2 parents 25d0a72 + 08eb21f commit f0b4e27
Show file tree
Hide file tree
Showing 8 changed files with 98 additions and 100 deletions.
37 changes: 0 additions & 37 deletions app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -460,18 +460,6 @@ app.on('ready', () => {
}
})

ipcMain.on(messages.CHANGE_SETTING, (e, key, value) => {
appActions.changeSetting(key, value)
})

ipcMain.on(messages.CHANGE_SITE_SETTING, (e, hostPattern, key, value, temp) => {
appActions.changeSiteSetting(hostPattern, key, value, temp)
})

ipcMain.on(messages.REMOVE_SITE_SETTING, (e, hostPattern, key) => {
appActions.removeSiteSetting(hostPattern, key)
})

ipcMain.on(messages.SET_CLIPBOARD, (e, text) => {
electron.clipboard.writeText(text)
})
Expand All @@ -483,20 +471,12 @@ app.on('ready', () => {
}
})

ipcMain.on(messages.SET_RESOURCE_ENABLED, (e, resourceName, enabled) => {
appActions.setResourceEnabled(resourceName, enabled)
})

ipcMain.on(messages.CHECK_FLASH_INSTALLED, (e) => {
flash.checkFlashInstalled((installed) => {
e.sender.send(messages.FLASH_UPDATED, installed)
})
})

ipcMain.on(messages.MOVE_SITE, (e, sourceDetail, destinationDetail, prepend, destinationIsParent) => {
appActions.moveSite(Immutable.fromJS(sourceDetail), Immutable.fromJS(destinationDetail), prepend, destinationIsParent)
})

ipcMain.on(messages.OPEN_DOWNLOAD_PATH, (e, download) => {
downloadActions.openDownloadPath(Immutable.fromJS(download))
})
Expand Down Expand Up @@ -553,15 +533,6 @@ app.on('ready', () => {
})

let masterKey
ipcMain.on(messages.DELETE_PASSWORD, (e, password) => {
appActions.deletePassword(password)
})
ipcMain.on(messages.DELETE_PASSWORD_SITE, (e, origin) => {
appActions.changeSiteSetting(origin, 'savePasswords', undefined)
})
ipcMain.on(messages.CLEAR_PASSWORDS, () => {
appActions.clearPasswords()
})
ipcMain.on(messages.DECRYPT_PASSWORD, (e, encrypted, authTag, iv, id) => {
masterKey = masterKey || getMasterKey()
if (!masterKey) {
Expand Down Expand Up @@ -743,14 +714,6 @@ app.on('ready', () => {
}
})

ipcMain.on(messages.REMOVE_AUTOFILL_ADDRESS, (e, address) => {
appActions.removeAutofillAddress(address)
})

ipcMain.on(messages.REMOVE_AUTOFILL_CREDIT_CARD, (e, card) => {
appActions.removeAutofillCreditCard(card)
})

// Setup the crash handling
CrashHerald.init()

Expand Down
20 changes: 14 additions & 6 deletions app/ledger.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ const underscore = require('underscore')
const uuid = require('node-uuid')

const appActions = require('../js/actions/appActions')
const appConstants = require('../js/constants/appConstants')
const appDispatcher = require('../js/dispatcher/appDispatcher')
const messages = require('../js/constants/messages')
const settings = require('../js/constants/settings')
const request = require('../js/lib/request')
Expand Down Expand Up @@ -94,12 +96,23 @@ let addFundsMessage
let suppressNotifications = false
let notificationTimeout = null

// TODO(bridiver) - create a better way to get setting changes
const doAction = (action) => {
switch (action.actionType) {
case appConstants.APP_CHANGE_SETTING:
if (action.key === settings.PAYMENTS_ENABLED) return initialize(action.value)
if (action.key === settings.PAYMENTS_CONTRIBUTION_AMOUNT) return setPaymentInfo(action.value)
break
default:
}
}

/*
* module entry points
*/

var init = () => {
try {
appDispatcher.register(doAction)
initialize(getSetting(settings.PAYMENTS_ENABLED))
} catch (ex) { console.log('initialization failed: ' + ex.toString() + '\n' + ex.stack) }
}
Expand Down Expand Up @@ -170,11 +183,6 @@ if (ipc) {
event.returnValue = { context: ctx, rules: publisherInfo._internal.ruleset.cooked }
})

ipc.on(messages.CHANGE_SETTING, (event, key, value) => {
if (key === settings.PAYMENTS_ENABLED) return initialize(value)
if (key === settings.PAYMENTS_CONTRIBUTION_AMOUNT) return setPaymentInfo(value)
})

ipc.on(messages.NOTIFICATION_RESPONSE, (e, message, buttonIndex) => {
if (message === addFundsMessage) {
appActions.hideMessageBox(message)
Expand Down
4 changes: 4 additions & 0 deletions app/sessionStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,10 @@ module.exports.defaultAppState = () => {
dictionary: {
addedWords: [],
ignoredWords: []
},
autofill: {
addresses: [],
creditCards: []
}
}
}
90 changes: 75 additions & 15 deletions js/about/aboutActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

const messages = require('../constants/messages')
const serializer = require('../dispatcher/serializer')
const WindowConstants = require('../constants/windowConstants')
const AppConstants = require('../constants/appConstants')
const ipc = window.chrome.ipc

const AboutActions = {
Expand All @@ -23,7 +25,11 @@ const AboutActions = {
* @param {string} value - The value of the setting to set
*/
changeSetting: function (key, value) {
ipc.send(messages.CHANGE_SETTING, key, value)
AboutActions.dispatchAction({
actionType: AppConstants.APP_CHANGE_SETTING,
key,
value
})
},

/**
Expand All @@ -34,7 +40,12 @@ const AboutActions = {
* @param {string} value - The value of the setting to set
*/
changeSiteSetting: function (hostPattern, key, value) {
ipc.send(messages.CHANGE_SITE_SETTING, hostPattern, key, value)
AboutActions.dispatchAction({
actionType: AppConstants.APP_CHANGE_SITE_SETTING,
hostPattern,
key,
value
})
},

/**
Expand All @@ -44,7 +55,11 @@ const AboutActions = {
* @param {string} key - The settings key to change the value on
*/
removeSiteSetting: function (hostPattern, key) {
ipc.send(messages.REMOVE_SITE_SETTING, hostPattern, key)
AboutActions.dispatchAction({
actionType: AppConstants.APP_REMOVE_SITE_SETTING,
hostPattern,
key
})
},

/**
Expand All @@ -53,7 +68,11 @@ const AboutActions = {
* preserve the about preload script. See #672
*/
newFrame: function (frameOpts, openInForeground = true) {
ipc.sendToHost(messages.NEW_FRAME, frameOpts, openInForeground)
AboutActions.dispatchAction({
actionType: WindowConstants.WINDOW_NEW_FRAME,
frameOpts,
openInForeground
})
},

/**
Expand Down Expand Up @@ -84,7 +103,13 @@ const AboutActions = {
},

moveSite: function (sourceDetail, destinationDetail, prepend, destinationIsParent) {
ipc.send(messages.MOVE_SITE, sourceDetail, destinationDetail, prepend, destinationIsParent)
AboutActions.dispatchAction({
actionType: AppConstants.APP_MOVE_SITE,
sourceDetail,
destinationDetail,
prepend,
destinationIsParent
})
},

openDownloadPath: function (download) {
Expand All @@ -100,15 +125,24 @@ const AboutActions = {
},

deletePassword: function (password) {
ipc.send(messages.DELETE_PASSWORD, password)
AboutActions.dispatchAction({
actionType: AppConstants.APP_REMOVE_PASSWORD,
password
})
},

deletePasswordSite: function (origin) {
ipc.send(messages.DELETE_PASSWORD_SITE, origin)
AboutActions.dispatchAction({
actionType: AppConstants.APP_CHANGE_SITE_SETTING,
hostPattern: origin,
key: 'savePasswords'
})
},

clearPasswords: function () {
ipc.send(messages.CLEAR_PASSWORDS)
AboutActions.dispatchAction({
actionType: AppConstants.APP_CLEAR_PASSWORDS
})
},

checkFlashInstalled: function () {
Expand All @@ -120,7 +154,11 @@ const AboutActions = {
},

setResourceEnabled: function (resourceName, enabled) {
ipc.send(messages.SET_RESOURCE_ENABLED, resourceName, enabled)
AboutActions.dispatchAction({
actionType: AppConstants.APP_SET_RESOURCE_ENABLED,
resourceName,
enabled
})
},

clearBrowsingDataNow: function (clearBrowsingDataDetail) {
Expand All @@ -139,7 +177,11 @@ const AboutActions = {
* Open a adding address dialog
*/
addAutofillAddress: function () {
ipc.sendToHost(messages.ADD_AUTOFILL_ADDRESS)
AboutActions.dispatchAction({
actionType: WindowConstants.WINDOW_SET_AUTOFILL_ADDRESS_DETAIL,
currentDetail: {},
originalDetail: {}
})
},

/**
Expand All @@ -148,7 +190,10 @@ const AboutActions = {
* @param {object} address - address to remove as per doc/state.md's autofillAddressDetail
*/
removeAutofillAddress: function (address) {
ipc.send(messages.REMOVE_AUTOFILL_ADDRESS, address)
AboutActions.dispatchAction({
actionType: AppConstants.APP_REMOVE_AUTOFILL_ADDRESS,
detail: address
})
},

/**
Expand All @@ -157,14 +202,22 @@ const AboutActions = {
* @param {object} address - address to edit as per doc/state.md's autofillAddressDetail
*/
editAutofillAddress: function (address) {
ipc.sendToHost(messages.EDIT_AUTOFILL_ADDRESS, address)
AboutActions.dispatchAction({
actionType: WindowConstants.WINDOW_SET_AUTOFILL_ADDRESS_DETAIL,
currentDetail: address,
originalDetail: address
})
},

/**
* Open a adding credit card dialog
*/
addAutofillCreditCard: function () {
ipc.sendToHost(messages.ADD_AUTOFILL_CREDIT_CARD)
AboutActions.dispatchAction({
actionType: WindowConstants.WINDOW_SET_AUTOFILL_CREDIT_CARD_DETAIL,
currentDetail: {month: '01', year: new Date().getFullYear().toString()},
originalDetail: {}
})
},

/**
Expand All @@ -173,7 +226,10 @@ const AboutActions = {
* @param {object} card - credit card to remove as per doc/state.md's autofillCreditCardDetail
*/
removeAutofillCreditCard: function (card) {
ipc.send(messages.REMOVE_AUTOFILL_CREDIT_CARD, card)
AboutActions.dispatchAction({
actionType: AppConstants.APP_REMOVE_AUTOFILL_CREDIT_CARD,
detail: card
})
},

/**
Expand All @@ -182,7 +238,11 @@ const AboutActions = {
* @param {object} card - credit card to edit as per doc/state.md's autofillCreditCardDetail
*/
editAutofillCreditCard: function (card) {
ipc.sendToHost(messages.EDIT_AUTOFILL_CREDIT_CARD, card)
AboutActions.dispatchAction({
actionType: WindowConstants.WINDOW_SET_AUTOFILL_CREDIT_CARD_DETAIL,
currentDetail: card,
originalDetail: card
})
}
}
module.exports = AboutActions
17 changes: 0 additions & 17 deletions js/components/frame.js
Original file line number Diff line number Diff line change
Expand Up @@ -694,27 +694,10 @@ class Frame extends ImmutableComponent {
case messages.CAN_SWIPE_FORWARD:
currentWindow.webContents.send(messages.CAN_SWIPE_FORWARD)
break
case messages.NEW_FRAME:
method = (frameOpts, openInForeground) => {
windowActions.newFrame(frameOpts, openInForeground)
}
break
case messages.CLEAR_BROWSING_DATA_NOW:
method = (clearBrowsingDataDetail) =>
windowActions.setClearBrowsingDataDetail(clearBrowsingDataDetail)
break
case messages.ADD_AUTOFILL_ADDRESS:
windowActions.setAutofillAddressDetail({}, {})
break
case messages.EDIT_AUTOFILL_ADDRESS:
windowActions.setAutofillAddressDetail(e.args[0], e.args[0])
break
case messages.ADD_AUTOFILL_CREDIT_CARD:
windowActions.setAutofillCreditCardDetail({month: '01', year: new Date().getFullYear().toString()}, {})
break
case messages.EDIT_AUTOFILL_CREDIT_CARD:
windowActions.setAutofillCreditCardDetail(e.args[0], e.args[0])
break
}
method.apply(this, e.args)
})
Expand Down
15 changes: 0 additions & 15 deletions js/constants/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ const messages = {
SET_CLIPBOARD: _,
GOT_CANVAS_FINGERPRINTING: _,
SHOW_NOTIFICATION: _, /** @arg {string} l10n id of desktop notification message */
SET_RESOURCE_ENABLED: _,
GO_BACK: _,
GO_FORWARD: _,
RELOAD: _,
Expand All @@ -98,9 +97,6 @@ const messages = {
PASSWORD_SITE_DETAILS_UPDATED: _, /** @arg {Object} passwords app state */
DECRYPT_PASSWORD: _, /** @arg {string} encrypted pw, @arg {string} iv, @arg {string} authTag, @arg {number} id */
DECRYPTED_PASSWORD: _, /** @arg {number} decrypted pw, @arg {number} id */
DELETE_PASSWORD: _, /** @arg {Object} password */
DELETE_PASSWORD_SITE: _, /** @arg {string} site */
CLEAR_PASSWORDS: _,
// Init
INITIALIZE_WINDOW: _,
INITIALIZE_PARTITION: _, /** @arg {string} name of partition */
Expand All @@ -126,24 +122,13 @@ const messages = {
DOWNLOADS_UPDATED: _,
FLASH_UPDATED: _,
// About pages from contentScript
CHANGE_SETTING: _,
CHANGE_SITE_SETTING: _,
REMOVE_SITE_SETTING: _,
NEW_FRAME: _,
MOVE_SITE: _,
OPEN_DOWNLOAD_PATH: _,
RELOAD_URL: _,
DISPATCH_ACTION: _,
CHECK_FLASH_INSTALLED: _,
ABOUT_COMPONENT_INITIALIZED: _,
CLEAR_BROWSING_DATA_NOW: _,
// Autofill
ADD_AUTOFILL_ADDRESS: _,
REMOVE_AUTOFILL_ADDRESS: _,
EDIT_AUTOFILL_ADDRESS: _,
ADD_AUTOFILL_CREDIT_CARD: _,
REMOVE_AUTOFILL_CREDIT_CARD: _,
EDIT_AUTOFILL_CREDIT_CARD: _,
AUTOFILL_ADDRESSES_UPDATED: _,
AUTOFILL_CREDIT_CARDS_UPDATED: _,
// HTTPS
Expand Down
Loading

0 comments on commit f0b4e27

Please sign in to comment.