Merge pull request #1042 from webtorrent/save-prefs
Save preferences immediately when changed
This commit is contained in:
9551
package-lock.json
generated
9551
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -64,7 +64,7 @@
|
|||||||
"nobin-debian-installer": "0.0.10",
|
"nobin-debian-installer": "0.0.10",
|
||||||
"nodemon": "^1.10.2",
|
"nodemon": "^1.10.2",
|
||||||
"open": "0.0.5",
|
"open": "0.0.5",
|
||||||
"plist": "^2.0.1",
|
"plist": "^3.0.1",
|
||||||
"pngjs": "^3.0.0",
|
"pngjs": "^3.0.0",
|
||||||
"run-series": "^1.1.4",
|
"run-series": "^1.1.4",
|
||||||
"spectron": "^3.3.0",
|
"spectron": "^3.3.0",
|
||||||
@@ -105,7 +105,7 @@
|
|||||||
"package": "node ./bin/package.js",
|
"package": "node ./bin/package.js",
|
||||||
"prepublish": "npm run build",
|
"prepublish": "npm run build",
|
||||||
"start": "npm run build && electron .",
|
"start": "npm run build && electron .",
|
||||||
"test": "standard && depcheck --ignores=buble,nodemon,gh-release --ignore-dirs=build,dist && node ./bin/extra-lint.js",
|
"test": "standard && depcheck --ignores=standard,babel-eslint --ignore-dirs=build,dist && node ./bin/extra-lint.js",
|
||||||
"test-integration": "npm run build && node ./test",
|
"test-integration": "npm run build && node ./test",
|
||||||
"update-authors": "./bin/update-authors.sh",
|
"update-authors": "./bin/update-authors.sh",
|
||||||
"watch": "nodemon --exec \"npm run start\" --ext js,css --ignore build/ --ignore dist/"
|
"watch": "nodemon --exec \"npm run start\" --ext js,css --ignore build/ --ignore dist/"
|
||||||
|
|||||||
@@ -16,45 +16,22 @@ module.exports = class PrefsController {
|
|||||||
setup: function (cb) {
|
setup: function (cb) {
|
||||||
// initialize preferences
|
// initialize preferences
|
||||||
state.window.title = 'Preferences'
|
state.window.title = 'Preferences'
|
||||||
state.unsaved = Object.assign(state.unsaved || {}, {
|
|
||||||
prefs: Object.assign({}, state.saved.prefs)
|
|
||||||
})
|
|
||||||
ipcRenderer.send('setAllowNav', false)
|
ipcRenderer.send('setAllowNav', false)
|
||||||
cb()
|
cb()
|
||||||
},
|
},
|
||||||
destroy: () => {
|
destroy: () => {
|
||||||
ipcRenderer.send('setAllowNav', true)
|
ipcRenderer.send('setAllowNav', true)
|
||||||
this.save()
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Updates a single property in the UNSAVED prefs
|
// Updates a single property in the saved prefs
|
||||||
// For example: updatePreferences('foo.bar', 'baz')
|
// For example: updatePreferences('isFileHandler', true)
|
||||||
// Call save() to save to config.json
|
|
||||||
update (property, value) {
|
update (property, value) {
|
||||||
const path = property.split('.')
|
if (property === 'isFileHandler') ipcRenderer.send('setDefaultFileHandler', value)
|
||||||
let obj = this.state.unsaved.prefs
|
else if (property === 'startup') ipcRenderer.send('setStartup', value)
|
||||||
let i
|
|
||||||
for (i = 0; i < path.length - 1; i++) {
|
|
||||||
if (typeof obj[path[i]] === 'undefined') {
|
|
||||||
obj[path[i]] = {}
|
|
||||||
}
|
|
||||||
obj = obj[path[i]]
|
|
||||||
}
|
|
||||||
obj[path[i]] = value
|
|
||||||
}
|
|
||||||
|
|
||||||
// All unsaved prefs take effect atomically, and are saved to config.json
|
this.state.saved.prefs[property] = value
|
||||||
save () {
|
|
||||||
const state = this.state
|
|
||||||
if (state.unsaved.prefs.isFileHandler !== state.saved.prefs.isFileHandler) {
|
|
||||||
ipcRenderer.send('setDefaultFileHandler', state.unsaved.prefs.isFileHandler)
|
|
||||||
}
|
|
||||||
if (state.unsaved.prefs.startup !== state.saved.prefs.startup) {
|
|
||||||
ipcRenderer.send('setStartup', state.unsaved.prefs.startup)
|
|
||||||
}
|
|
||||||
state.saved.prefs = Object.assign(state.saved.prefs || {}, state.unsaved.prefs)
|
|
||||||
dispatch('stateSaveImmediate')
|
dispatch('stateSaveImmediate')
|
||||||
dispatch('checkDownloadPath')
|
dispatch('checkDownloadPath')
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ class PreferencesPage extends React.Component {
|
|||||||
}}
|
}}
|
||||||
onChange={this.handleDownloadPathChange}
|
onChange={this.handleDownloadPathChange}
|
||||||
title='Download location'
|
title='Download location'
|
||||||
value={this.props.state.unsaved.prefs.downloadPath} />
|
value={this.props.state.saved.prefs.downloadPath} />
|
||||||
</Preference>
|
</Preference>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -51,7 +51,7 @@ class PreferencesPage extends React.Component {
|
|||||||
<Preference>
|
<Preference>
|
||||||
<Checkbox
|
<Checkbox
|
||||||
className='control'
|
className='control'
|
||||||
checked={!this.props.state.unsaved.prefs.openExternalPlayer}
|
checked={!this.props.state.saved.prefs.openExternalPlayer}
|
||||||
label={'Play torrent media files using WebTorrent'}
|
label={'Play torrent media files using WebTorrent'}
|
||||||
onCheck={this.handleOpenExternalPlayerChange} />
|
onCheck={this.handleOpenExternalPlayerChange} />
|
||||||
</Preference>
|
</Preference>
|
||||||
@@ -67,7 +67,7 @@ class PreferencesPage extends React.Component {
|
|||||||
<Preference>
|
<Preference>
|
||||||
<Checkbox
|
<Checkbox
|
||||||
className='control'
|
className='control'
|
||||||
checked={this.props.state.unsaved.prefs.highestPlaybackPriority}
|
checked={this.props.state.saved.prefs.highestPlaybackPriority}
|
||||||
label={'Highest Playback Priority'}
|
label={'Highest Playback Priority'}
|
||||||
onCheck={this.handleHighestPlaybackPriorityChange}
|
onCheck={this.handleHighestPlaybackPriorityChange}
|
||||||
/>
|
/>
|
||||||
@@ -81,10 +81,10 @@ class PreferencesPage extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
externalPlayerPathSelector () {
|
externalPlayerPathSelector () {
|
||||||
const playerPath = this.props.state.unsaved.prefs.externalPlayerPath
|
const playerPath = this.props.state.saved.prefs.externalPlayerPath
|
||||||
const playerName = this.props.state.getExternalPlayerName()
|
const playerName = this.props.state.getExternalPlayerName()
|
||||||
|
|
||||||
const description = this.props.state.unsaved.prefs.openExternalPlayer
|
const description = this.props.state.saved.prefs.openExternalPlayer
|
||||||
? `Torrent media files will always play in ${playerName}.`
|
? `Torrent media files will always play in ${playerName}.`
|
||||||
: `Torrent media files will play in ${playerName} if WebTorrent cannot play them.`
|
: `Torrent media files will play in ${playerName} if WebTorrent cannot play them.`
|
||||||
|
|
||||||
@@ -113,7 +113,7 @@ class PreferencesPage extends React.Component {
|
|||||||
<Preference>
|
<Preference>
|
||||||
<Checkbox
|
<Checkbox
|
||||||
className='control'
|
className='control'
|
||||||
checked={this.props.state.unsaved.prefs.autoAddTorrents}
|
checked={this.props.state.saved.prefs.autoAddTorrents}
|
||||||
label={'Watch for new .torrent files and add them immediately'}
|
label={'Watch for new .torrent files and add them immediately'}
|
||||||
onCheck={(e, value) => { this.handleAutoAddTorrentsChange(e, value) }}
|
onCheck={(e, value) => { this.handleAutoAddTorrentsChange(e, value) }}
|
||||||
/>
|
/>
|
||||||
@@ -122,7 +122,7 @@ class PreferencesPage extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
handleAutoAddTorrentsChange (e, isChecked) {
|
handleAutoAddTorrentsChange (e, isChecked) {
|
||||||
const torrentsFolderPath = this.props.state.unsaved.prefs.torrentsFolderPath
|
const torrentsFolderPath = this.props.state.saved.prefs.torrentsFolderPath
|
||||||
if (isChecked && !torrentsFolderPath) {
|
if (isChecked && !torrentsFolderPath) {
|
||||||
alert('Select a torrents folder first.') // eslint-disable-line
|
alert('Select a torrents folder first.') // eslint-disable-line
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
@@ -140,7 +140,7 @@ class PreferencesPage extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
torrentsFolderPathSelector () {
|
torrentsFolderPathSelector () {
|
||||||
const torrentsFolderPath = this.props.state.unsaved.prefs.torrentsFolderPath
|
const torrentsFolderPath = this.props.state.saved.prefs.torrentsFolderPath
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Preference>
|
<Preference>
|
||||||
@@ -162,7 +162,7 @@ class PreferencesPage extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
setDefaultAppButton () {
|
setDefaultAppButton () {
|
||||||
const isFileHandler = this.props.state.unsaved.prefs.isFileHandler
|
const isFileHandler = this.props.state.saved.prefs.isFileHandler
|
||||||
if (isFileHandler) {
|
if (isFileHandler) {
|
||||||
return (
|
return (
|
||||||
<Preference>
|
<Preference>
|
||||||
@@ -195,7 +195,7 @@ class PreferencesPage extends React.Component {
|
|||||||
<Preference>
|
<Preference>
|
||||||
<Checkbox
|
<Checkbox
|
||||||
className='control'
|
className='control'
|
||||||
checked={this.props.state.unsaved.prefs.startup}
|
checked={this.props.state.saved.prefs.startup}
|
||||||
label={'Open WebTorrent on startup.'}
|
label={'Open WebTorrent on startup.'}
|
||||||
onCheck={this.handleStartupChange}
|
onCheck={this.handleStartupChange}
|
||||||
/>
|
/>
|
||||||
|
|||||||
Reference in New Issue
Block a user