This repository has been archived by the owner on Dec 11, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 975
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 #8065 from cezaraugusto/extensions/6530
Add extensionsTab to preferences page
- Loading branch information
Showing
27 changed files
with
954 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* 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/. */ | ||
|
||
'use strict' | ||
|
||
const electron = require('electron') | ||
const app = electron.app | ||
|
||
const path = require('path') | ||
const rimraf = require('../../../tools/lib/rimraf') | ||
|
||
const extensionState = require('../../common/state/extensionState') | ||
const ExtensionConstants = require('../../common/constants/extensionConstants') | ||
const {makeImmutable} = require('../../common/state/immutableUtil') | ||
|
||
const extensionsReducer = (state, action) => { | ||
action = makeImmutable(action) | ||
switch (action.get('actionType')) { | ||
case ExtensionConstants.EXTENSION_UNINSTALLED: | ||
let extensionId = action.get('extensionId').toString() | ||
let extensionPath = path.join(app.getPath('userData'), 'Extensions', extensionId) | ||
|
||
state = extensionState.extensionUninstalled(state, action) | ||
// Remove extension folder | ||
rimraf(extensionPath, err => { | ||
if (err) { | ||
console.log('unable to remove extension', err) | ||
} | ||
console.log(`extension id ${extensionId} removed at: \n ${extensionPath}`) | ||
}) | ||
break | ||
} | ||
return state | ||
} | ||
|
||
module.exports = extensionsReducer |
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* 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/. */ | ||
|
||
const ImmutableComponent = require('../../../js/components/immutableComponent') | ||
const globalStyles = require('./styles/global') | ||
|
||
class HelpfulText extends ImmutableComponent { | ||
render () { | ||
return <div className={this.props.wrapperClassName}> | ||
<span className={globalStyles.appIcons.moreInfo} | ||
style={{ | ||
color: globalStyles.color.mediumGray, | ||
fontSize: '20px', | ||
marginRight: '5px' | ||
}} /> | ||
<span className={this.props.textClassName} data-l10n-id={this.props.l10nId} /> | ||
{this.props.children} | ||
</div> | ||
} | ||
} | ||
|
||
module.exports = HelpfulText |
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,205 @@ | ||
/* 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/. */ | ||
|
||
const React = require('react') | ||
const ImmutableComponent = require('../../../../js/components/immutableComponent') | ||
|
||
const {StyleSheet, css} = require('aphrodite') | ||
const globalStyles = require('../styles/global') | ||
const {thirdPartyPasswordManagers} = require('../../../../js/constants/passwordManagers') | ||
const aboutActions = require('../../../../js/about/aboutActions') | ||
const settings = require('../../../../js/constants/settings') | ||
const config = require('../../../../js/constants/config') | ||
const {getSetting} = require('../../../../js/settings') | ||
const {SettingCheckbox} = require('../settings') | ||
const {isPasswordManager, getExtensionKey, isBuiltInExtension, bravifyText} = require('../../lib/extensionsUtil') | ||
|
||
const HelpfulText = require('../helpfulText') | ||
const SortableTable = require('../../../../js/components/sortableTable') | ||
|
||
class ExtensionsTab extends ImmutableComponent { | ||
getIcon (extension) { | ||
const icon = extension.getIn(['manifest', 'icons', '128']) | ||
return `${extension.get('base_path')}/${icon}` | ||
} | ||
|
||
onRemoveExtension (extensionId) { | ||
// Disable extension before uninstalling | ||
// otherwise user will not be able to install it again | ||
isPasswordManager(extensionId) | ||
? aboutActions.changeSetting(settings.ACTIVE_PASSWORD_MANAGER, extensionId) | ||
: aboutActions.changeSetting(getExtensionKey(extensionId), false) | ||
|
||
aboutActions.extensionUninstalled(extensionId) | ||
} | ||
|
||
getCheckedExtension (extensionId) { | ||
const activePwManager = getSetting(settings.ACTIVE_PASSWORD_MANAGER, this.props.settings) | ||
return isPasswordManager(extensionId) | ||
? activePwManager === getExtensionKey(extensionId) | ||
: void (0) | ||
} | ||
|
||
isRemovableExtension (extension) { | ||
// do not allow built-in extensions from being uninstalled | ||
return extension.get('excluded') && !isBuiltInExtension(extension.get('id')) | ||
} | ||
|
||
getRow (extension) { | ||
if ([config.braveExtensionId, config.syncExtensionId].includes(extension.get('id')) || | ||
(!extension.get('dummy') && this.isRemovableExtension(extension))) { | ||
return [] | ||
} | ||
|
||
return [ | ||
{ // Icon | ||
html: <img className={css(styles.icon)} src={this.getIcon(extension)} /> | ||
}, | ||
{ // Name | ||
html: <span data-extension-id={extension.get('id')} | ||
data-extension-enabled={extension.get('enabled')} | ||
data-l10n-id={bravifyText(extension.get('name'))} /> | ||
}, | ||
{ // Description | ||
html: <span data-l10n-id={bravifyText(extension.get('description'))} /> | ||
}, | ||
{ // Version | ||
html: <span data-l10n-id={extension.get('version') || 'latest'} /> | ||
}, | ||
{ // Enable/Disable toggle | ||
html: <SettingCheckbox | ||
forPassword={thirdPartyPasswordManagers.includes(extension.get('id'))} | ||
prefKey={getExtensionKey(extension.get('id'))} | ||
settings={this.props.settings} | ||
checked={this.getCheckedExtension(extension.get('id'))} | ||
onChangeSetting={this.props.onChangeSetting} /> | ||
}, | ||
{ // Exclude option | ||
html: !extension.get('isDummy') && !isBuiltInExtension(extension.get('id')) | ||
? <div className={globalStyles.appIcons.trash} | ||
onClick={this.onRemoveExtension.bind(this, extension.get('id'))} /> | ||
: <span data-l10n-id={isBuiltInExtension(extension.get('id')) ? 'integrated' : 'notInstalled'} /> | ||
} | ||
] | ||
} | ||
|
||
get columnClassNames () { | ||
return [ | ||
css(styles.extensionsColumn, styles.center), | ||
css(styles.extensionsColumn), | ||
css(styles.extensionsColumn), | ||
css(styles.extensionsColumn), | ||
css(styles.extensionsColumn, styles.center), | ||
css(styles.extensionsColumn, styles.center) | ||
] | ||
} | ||
|
||
render () { | ||
if (!this.props.extensions) { | ||
return null | ||
} | ||
return <div className={css(styles.extensionsContainer)}> | ||
<main className={css(styles.extensionsMain)}> | ||
<header className={css(styles.extensionsOption)}> | ||
<h1 className={css(styles.extensionsHeading)} data-l10n-id='extensions' /> | ||
</header> | ||
<SortableTable | ||
tableClassNames={css(styles.extensionsTable)} | ||
headings={['icon', 'name', 'description', 'version', 'enabled', 'exclude']} | ||
columnClassNames={this.columnClassNames} | ||
rowClassNames={ | ||
this.props.extensions.map(entry => (entry = css(styles.extensionsRow))).toJS() | ||
} | ||
rows={this.props.extensions.map(entry => this.getRow(entry))} /> | ||
</main> | ||
<footer className={css(styles.moreInfo)}> | ||
<HelpfulText l10nId='extensionsTabFooterInfo'> | ||
<span data-l10n-id='community' | ||
className={css(styles.moreInfoLink)} | ||
onClick={aboutActions.createTabRequested.bind(null, { | ||
url: 'https://community.brave.com' | ||
}, true)} />. | ||
</HelpfulText> | ||
</footer> | ||
</div> | ||
} | ||
} | ||
|
||
const styles = StyleSheet.create({ | ||
extensionsContainer: { | ||
display: 'flex', | ||
flexDirection: 'column', | ||
justifyContent: 'space-between', | ||
height: '100%' | ||
}, | ||
|
||
extensionsMain: { | ||
paddingBottom: '40px' | ||
}, | ||
|
||
icon: { | ||
display: 'flex', | ||
margin: 'auto', | ||
width: '32px', | ||
height: '32px' | ||
}, | ||
|
||
extensionsOption: { | ||
display: 'flex', | ||
flex: '1', | ||
alignItems: 'center', | ||
justifyContent: 'space-between', | ||
marginBottom: '15px' | ||
}, | ||
|
||
extensionsHeading: { | ||
color: '#444444', | ||
cursor: 'default', | ||
fontSize: '1.2em', | ||
marginBottom: '0.7em', | ||
userSelect: 'none' | ||
}, | ||
|
||
extensionsTable: { | ||
width: '100%' | ||
}, | ||
|
||
extensionsRow: { | ||
background: '#fff', | ||
height: '56px', | ||
|
||
':nth-child(even)': { | ||
background: globalStyles.color.veryLightGray | ||
}, | ||
':hover': { | ||
background: globalStyles.color.lightGray | ||
} | ||
}, | ||
|
||
extensionsColumn: { | ||
padding: '0 8px' | ||
}, | ||
|
||
center: { | ||
textAlign: 'center' | ||
}, | ||
|
||
moreInfo: { | ||
display: 'flex', | ||
flex: '1', | ||
alignItems: 'flex-end' | ||
}, | ||
|
||
moreInfoLink: { | ||
cursor: 'pointer', | ||
color: globalStyles.color.braveOrange, | ||
textDecoration: 'none', | ||
|
||
':hover': { | ||
textDecoration: 'underline' | ||
} | ||
} | ||
}) | ||
|
||
module.exports = ExtensionsTab |
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
Oops, something went wrong.