diff --git a/app/index.js b/app/index.js index cc9870e8eb9..6884cd673dd 100644 --- a/app/index.js +++ b/app/index.js @@ -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) }) @@ -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)) }) @@ -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) { @@ -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() diff --git a/app/ledger.js b/app/ledger.js index a0c692127bc..7a5cba0ce1f 100644 --- a/app/ledger.js +++ b/app/ledger.js @@ -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') @@ -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) } } @@ -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) diff --git a/app/sessionStore.js b/app/sessionStore.js index 44885cb0b95..e793ff7708a 100644 --- a/app/sessionStore.js +++ b/app/sessionStore.js @@ -365,6 +365,10 @@ module.exports.defaultAppState = () => { dictionary: { addedWords: [], ignoredWords: [] + }, + autofill: { + addresses: [], + creditCards: [] } } } diff --git a/js/about/aboutActions.js b/js/about/aboutActions.js index 09e579e7486..ec2d053e6e3 100644 --- a/js/about/aboutActions.js +++ b/js/about/aboutActions.js @@ -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 = { @@ -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 + }) }, /** @@ -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 + }) }, /** @@ -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 + }) }, /** @@ -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 + }) }, /** @@ -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) { @@ -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 () { @@ -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) { @@ -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: {} + }) }, /** @@ -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 + }) }, /** @@ -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: {} + }) }, /** @@ -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 + }) }, /** @@ -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 diff --git a/js/components/frame.js b/js/components/frame.js index a4840a2df2b..06b5ad12efa 100644 --- a/js/components/frame.js +++ b/js/components/frame.js @@ -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) }) diff --git a/js/constants/messages.js b/js/constants/messages.js index 36e39f8ce88..335a44d2f30 100644 --- a/js/constants/messages.js +++ b/js/constants/messages.js @@ -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: _, @@ -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 */ @@ -126,11 +122,6 @@ 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: _, @@ -138,12 +129,6 @@ const messages = { 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 diff --git a/js/stores/appStore.js b/js/stores/appStore.js index 53aececae4d..f8a5a2f9144 100644 --- a/js/stores/appStore.js +++ b/js/stores/appStore.js @@ -545,9 +545,6 @@ const handleAppAction = (action) => { case AppConstants.APP_ADD_AUTOFILL_ADDRESS: { const Filtering = require('../../app/filtering') - if (appState.getIn(['autofill', 'addresses']) === undefined) { - appState = appState.setIn(['autofill', 'addresses'], new Immutable.List()) - } appState = appState.setIn(['autofill', 'addresses'], appState.getIn(['autofill', 'addresses']).filterNot((address) => { return Immutable.is(address, action.originalDetail.get('guid')) @@ -566,17 +563,14 @@ const handleAppAction = (action) => { const Filtering = require('../../app/filtering') appState = appState.setIn(['autofill', 'addresses'], appState.getIn(['autofill', 'addresses']).filterNot((address) => { - return Immutable.is(address, Immutable.fromJS(action.detail.guid)) + return Immutable.is(address, Immutable.fromJS(action.detail.get('guid'))) })) - Filtering.removeAutofillAddress(action.detail.guid) + Filtering.removeAutofillAddress(action.detail.get('guid').toJS()) break } case AppConstants.APP_ADD_AUTOFILL_CREDIT_CARD: { const Filtering = require('../../app/filtering') - if (appState.getIn(['autofill', 'creditCards']) === undefined) { - appState = appState.setIn(['autofill', 'creditCards'], new Immutable.List()) - } appState = appState.setIn(['autofill', 'creditCards'], appState.getIn(['autofill', 'creditCards']).filterNot((card) => { return Immutable.is(card, action.originalDetail.get('guid')) @@ -595,9 +589,9 @@ const handleAppAction = (action) => { const Filtering = require('../../app/filtering') appState = appState.setIn(['autofill', 'creditCards'], appState.getIn(['autofill', 'creditCards']).filterNot((card) => { - return Immutable.is(card, Immutable.fromJS(action.detail.guid)) + return Immutable.is(card, action.detail.get('guid')) })) - Filtering.removeAutofillCreditCard(action.detail.guid) + Filtering.removeAutofillCreditCard(action.detail.get('guid').toJS()) break } default: diff --git a/js/stores/windowStore.js b/js/stores/windowStore.js index acc9585c75c..5a3bf74414e 100644 --- a/js/stores/windowStore.js +++ b/js/stores/windowStore.js @@ -165,6 +165,7 @@ const addToHistory = (frameProps) => { const newFrame = (frameOpts, openInForeground, insertionIndex) => { const frames = windowState.get('frames') + frameOpts = frameOpts.toJS ? frameOpts.toJS() : frameOpts if (frameOpts === undefined) { frameOpts = {} }