Skip to content

Commit

Permalink
Fixes disabled torrent viewer torrent download
Browse files Browse the repository at this point in the history
Resolves brave#10767

Auditors:

Test Plan:
  • Loading branch information
NejcZdovc committed May 15, 2018
1 parent 86dec47 commit 3d6763e
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion js/stores/appStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const platformUtil = require('../../app/common/lib/platformUtil')
const urlUtil = require('../lib/urlutil')
const buildConfig = require('../constants/buildConfig')
const {shouldDebugStoreActions} = require('../../app/cmdLine')
const getSetting = require('../settings').getSetting

// state helpers
const {makeImmutable, findNullKeyPaths} = require('../../app/common/state/immutableUtil')
Expand All @@ -46,6 +47,7 @@ const tabState = require('../../app/common/state/tabState')
const bookmarksState = require('../../app/common/state/bookmarksState')
const bookmarkFoldersState = require('../../app/common/state/bookmarkFoldersState')
const historyState = require('../../app/common/state/historyState')
const config = require('../constants/config')

// Only used internally
const CHANGE_EVENT = 'app-state-change'
Expand Down Expand Up @@ -202,6 +204,14 @@ const applyReducers = (state, action, immutableAction) => reducers.reduce(
return newState
}, appState)

const isWebTorrentEnabled = (state) => {
const settingsState = state.get('settings')
const extension = extensionState.getExtensionById(state, config.torrentExtensionId)
const extensionEnabled = extension !== undefined ? extension.get('enabled') : false
const torrentEnabled = getSetting(settings.TORRENT_VIEWER_ENABLED, settingsState)
return extensionEnabled && torrentEnabled
}

const handleAppAction = (action) => {
const ledgerReducer = require('../../app/browser/reducers/ledgerReducer')
const timeStart = process.hrtime()
Expand Down Expand Up @@ -271,7 +281,9 @@ const handleAppAction = (action) => {
// TODO(bridiver) - these should be refactored into reducers
appState = filtering.init(appState, action, appStore)
appState = basicAuth.init(appState, action, appStore)
appState = webtorrent.init(appState, action, appStore)
if (isWebTorrentEnabled(appState)) {
appState = webtorrent.init(appState, action, appStore)
}
appState = profiles.init(appState, action, appStore)
appState = require('../../app/sync').init(appState, action, appStore)
calculateTopSites(true, true)
Expand Down

0 comments on commit 3d6763e

Please sign in to comment.