Pref: default torrent file handler

Before, the app made itself the default torrent file handler automatically, pissing off some of our users. Now, it's not by default, and you can change it in the prefs.
This commit is contained in:
DC
2016-08-10 02:21:10 -07:00
parent 11eb603930
commit 8233faf518
5 changed files with 77 additions and 22 deletions

View File

@@ -22,7 +22,8 @@ function renderGeneralSection (state) {
description: '',
icon: 'settings'
}, [
renderDownloadDirSelector(state)
renderDownloadDirSelector(state),
renderFileHandlers(state)
])
}
@@ -43,6 +44,29 @@ function renderDownloadDirSelector (state) {
})
}
function renderFileHandlers (state) {
var definition = {
key: 'file-handlers',
label: 'Handle Torrent Files'
}
var buttonText = state.unsaved.prefs.isFileHandler
? 'Remove default app for torrent files'
: 'Make WebTorrent the default app for torrent files'
var controls = [(
<button key='toggle-handlers'
className='btn'
onClick={toggleFileHandlers}>
{buttonText}
</button>
)]
return renderControlGroup(definition, controls)
function toggleFileHandlers () {
var isFileHandler = state.unsaved.prefs.isFileHandler
dispatch('updatePreferences', 'isFileHandler', !isFileHandler)
}
}
// Renders a prefs section.
// - definition should be {icon, title, description}
// - controls should be an array of vdom elements
@@ -73,25 +97,18 @@ function renderSection (definition, controls) {
// - value should be the current pref, a file or folder path
// - callback takes a new file or folder path
function renderFileSelector (definition, value, callback) {
return (
<div key={definition.key} className='control-group'>
<div className='controls'>
<label className='control-label'>
<div className='preference-title'>{definition.label}</div>
<div className='preference-description'>{definition.description}</div>
</label>
<div className='controls'>
<input type='text' className='file-picker-text'
id={definition.property}
disabled='disabled'
value={value} />
<button className='btn' onClick={handleClick}>
<i className='icon'>folder_open</i>
</button>
</div>
</div>
</div>
)
var controls = [(
<input type='text' className='file-picker-text'
id={definition.property}
disabled='disabled'
value={value} />
), (
<button className='btn' onClick={handleClick}>
<i className='icon'>folder_open</i>
</button>
)]
return renderControlGroup(definition, controls)
function handleClick () {
dialog.showOpenDialog(remote.getCurrentWindow(), definition.options, function (filenames) {
if (!Array.isArray(filenames)) return
@@ -100,6 +117,22 @@ function renderFileSelector (definition, value, callback) {
}
}
function renderControlGroup (definition, controls) {
return (
<div key={definition.key} className='control-group'>
<div className='controls'>
<label className='control-label'>
<div className='preference-title'>{definition.label}</div>
<div className='preference-description'>{definition.description}</div>
</label>
<div className='controls'>
{controls}
</div>
</div>
</div>
)
}
function setStateValue (property, value) {
dispatch('updatePreferences', property, value)
}