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 #14568 from brave/fix/relaunch-tor
Browse files Browse the repository at this point in the history
Add button to restart tor without restarting brave
  • Loading branch information
bsclifton authored Jun 27, 2018
2 parents 47b3f48 + 5f75090 commit 8ebcdd1
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 20 deletions.
3 changes: 3 additions & 0 deletions app/browser/reducers/torReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ const appConstants = require('../../../js/constants/appConstants')

const torReducer = (state, action) => {
switch (action.actionType) {
case appConstants.APP_RESTART_TOR:
filtering.relaunchTor()
break
case appConstants.APP_SET_TOR_NEW_IDENTITY:
filtering.setTorNewIdentity(action.url, action.tabId)
break
Expand Down
3 changes: 1 addition & 2 deletions app/extensions/brave/locales/en-US/app.properties
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,7 @@ torrentWarningOk=Ok
torConnectionError=Unable to connect to the Tor network
torConnectionErrorInfo=Brave could not make a connection to the Tor network. Disable Tor to continue private browsing without Tor protection.
torConnectionErrorDisable=Disable Tor
torConnectionErrorRetry=To retry connecting to the Tor network,
torConnectionErrorRestart=click here to restart Brave.
torConnectionErrorRetry=Retry connection
turnOffNotifications=Turn off notifications
unknownError=Oops, something went wrong.
unmuteTab=Unmute tab
Expand Down
16 changes: 16 additions & 0 deletions app/filtering.js
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,22 @@ module.exports.setTorNewIdentity = (url, tabId) => {
})
}

module.exports.relaunchTor = () => {
const ses = session.fromPartition(appConfig.tor.partition)
if (!ses) {
console.log('Tor session no longer exists. Cannot restart Tor.')
return
}
appActions.onTorInitError(null)
try {
// TODO (riastradh): why is calling setupTor again necessary?
setupTor()
ses.relaunchTor()
} catch (e) {
appActions.onTorInitError(`Could not restart Tor: ${e}`)
}
}

function initSession (ses, partition) {
registeredSessions[partition] = ses
ses.setEnableBrotli(true)
Expand Down
26 changes: 8 additions & 18 deletions app/renderer/components/main/siteInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ class SiteInfo extends React.Component {
this.props.activeTabIndex)
}

onRestart () {
appActions.shuttingDown(true)
onRestartTor () {
appActions.restartTor()
}

get secureIcon () {
Expand Down Expand Up @@ -169,17 +169,16 @@ class SiteInfo extends React.Component {
<div className={css(styles.torBody)}>
<div className={css(styles.torConnectionInfo)} data-l10n-id='torConnectionErrorInfo' />
<Button
l10nId='torConnectionErrorDisable'
l10nId='torConnectionErrorRetry'
className='primaryButton'
onClick={this.onRestartTor}
/>
<Button
l10nId='torConnectionErrorDisable'
className='whiteButton'
onClick={this.onDisableTor}
/>
</div>
<div className={css(styles.torFooter)}>
<div data-l10n-id='torConnectionErrorRetry' />
<div data-l10n-id='torConnectionErrorRestart'
className={css(styles.link)}
onClick={this.onRestart} />
</div>
</div>
} else if (this.props.maybePhishingLocation) {
return <div className={css(styles.connectionInfo)}>
Expand Down Expand Up @@ -342,15 +341,6 @@ const styles = StyleSheet.create({
lineHeight: '1.5em'
},

torFooter: {
lineHeight: '1.5em'
},

link: {
color: globalStyles.color.braveOrange,
cursor: 'pointer'
},

siteInfo: {
maxHeight: '300px',
maxWidth: '400px',
Expand Down
6 changes: 6 additions & 0 deletions js/actions/appActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -2082,6 +2082,12 @@ const appActions = {
})
},

restartTor: function () {
dispatch({
actionType: appConstants.APP_RESTART_TOR
})
},

recreateTorTab: function (torEnabled, tabId, index) {
dispatch({
actionType: appConstants.APP_RECREATE_TOR_TAB,
Expand Down
1 change: 1 addition & 0 deletions js/constants/appConstants.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ const appConstants = {
APP_ON_TOR_INIT_SUCCESS: _,
APP_ON_TOR_INIT_PERCENTAGE: _,
APP_SET_TOR_NEW_IDENTITY: _,
APP_RESTART_TOR: _,
APP_RECREATE_TOR_TAB: _
}

Expand Down

0 comments on commit 8ebcdd1

Please sign in to comment.