-
Notifications
You must be signed in to change notification settings - Fork 904
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3150 from brave/ca-3121
[brave-extension] add settings option to hide Shields activity count
- Loading branch information
Showing
33 changed files
with
302 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
components/brave_extension/extension/brave_extension/actions/settingsActions.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
// Types | ||
import * as types from '../constants/settingsTypes' | ||
import * as actions from '../types/actions/settingsActions' | ||
import { SettingsOptions, GeneratedSettingsKey, SettingsData } from '../types/other/settingsTypes' | ||
|
||
// Helpers | ||
import * as shieldsAPI from '../background/api/shieldsAPI' | ||
import * as settingsUtils from '../helpers/settingsUtils' | ||
import { areObjectsEqual } from '../helpers/objectUtils' | ||
import { Dispatch } from 'redux' | ||
import { State } from '../types/state/mainState' | ||
/** | ||
* Inform the store that settings have changed. This action is used only | ||
* for storing values in Redux and does not tell which brave settings have changed. | ||
*/ | ||
export const setStoreSettingsChange: actions.SetStoreSettingsChange = (settingsData) => { | ||
return { | ||
type: types.SET_STORE_SETTINGS_CHANGE, | ||
settingsData | ||
} | ||
} | ||
|
||
/** | ||
* Perform an update in settings both in brave://settings and Shields store whenever a setting change. | ||
* This action is bounded to the settings listener and should not be used outside this scope. | ||
*/ | ||
export const settingsDidChange: actions.SettingsDidChange = (settings) => { | ||
const settingsOptions: SettingsOptions = settingsUtils.settingsOptions | ||
const currentSetting: Partial<GeneratedSettingsKey> = settingsOptions[settings.key] | ||
return setStoreSettingsChange({ [currentSetting]: settings.value }) | ||
} | ||
|
||
/** | ||
* Get a list of settings values from brave://settings and update if comparison | ||
* against settings values from store deosn't match. | ||
*/ | ||
interface FetchAndDispatchSettings { | ||
(): (dispatch: Dispatch, getState: () => State) => void | ||
} | ||
|
||
export const fetchAndDispatchSettings: FetchAndDispatchSettings = () => { | ||
return (dispatch, getState) => { | ||
const settingsDataFromStore: SettingsData = getState().shieldsPanel.settingsData | ||
shieldsAPI.getViewPreferences() | ||
.then( | ||
(settingsData: SettingsData) => { | ||
if (!areObjectsEqual(settingsDataFromStore, settingsData)) { | ||
dispatch(setStoreSettingsChange(settingsData)) | ||
} | ||
}, | ||
error => console.error('[Shields] error updating settings data', error) | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
components/brave_extension/extension/brave_extension/background/actions/settingsActions.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
import { bindActionCreators } from 'redux' | ||
import store from '../store' | ||
import * as settingsActions from '../../actions/settingsActions' | ||
export default bindActionCreators(settingsActions, store.dispatch) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
components/brave_extension/extension/brave_extension/background/events/settingsEvents.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
import settingsActions from '../actions/settingsActions' | ||
import { settingsKeyList } from '../../helpers/settingsUtils' | ||
import { SettingsKey } from '../../types/other/settingsTypes' | ||
|
||
chrome.settingsPrivate.onPrefsChanged.addListener(function (settings) { | ||
const settingsKey = settings[0].key as SettingsKey | ||
// only call the store update if the settings change is something we care about | ||
if (settingsKeyList.includes(settingsKey)) { | ||
settingsActions.settingsDidChange(settings[0]) | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
components/brave_extension/extension/brave_extension/constants/settingsTypes.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
export const SET_STORE_SETTINGS_CHANGE = 'SET_STORE_SETTINGS_CHANGE' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.