From 0a2c0586d423aaf0e6d8c19ed219c6df9f9d2214 Mon Sep 17 00:00:00 2001 From: Alex Liebowitz Date: Mon, 22 Aug 2016 14:13:41 -0400 Subject: [PATCH] Light refactor of daemon settings processing - Rename the daemon setter/getter methods to lbry.getDaemonSettings() and lbry.setDaemonSettings() to differentiate them from the new methods for client settings - Add lbry.setDaemonSetting(), for changing individual daemon settings easy to - Refactor Settings page to submit only changed settings instead of re-submitting all settings every time --- js/lbry.js | 14 ++++++++++---- js/page/settings.js | 38 +++++++++++++++----------------------- 2 files changed, 25 insertions(+), 27 deletions(-) diff --git a/js/lbry.js b/js/lbry.js index cca8c6af7..a90f32c2d 100644 --- a/js/lbry.js +++ b/js/lbry.js @@ -90,13 +90,19 @@ lbry.getNewAddress = function(callback) { lbry.call('get_new_address', {}, callback); } -lbry.getSettings = function(callback) { +lbry.getDaemonSettings = function(callback) { lbry.call('get_settings', {}, callback); -}; +} -lbry.setSettings = function(settings, callback) { +lbry.setDaemonSettings = function(settings, callback) { lbry.call('set_settings', settings, callback); -}; +} + +lbry.setDaemonSetting = function(setting, value, callback) { + var setSettingsArgs = {}; + setSettingsArgs[setting] = value; + lbry.call('set_settings', setSettingsArgs, callback) +} lbry.getBalance = function(callback) { diff --git a/js/page/settings.js b/js/page/settings.js index 44fb795c5..c7248d190 100644 --- a/js/page/settings.js +++ b/js/page/settings.js @@ -14,44 +14,36 @@ var settingsRadioOptionStyles = { }; var SettingsPage = React.createClass({ - storeSetting: function(setting, val) { - var settings = Object.assign({}, this.state.settings); - settings[setting] = val; - this.setState({ - 'settings': settings - }); - lbry.setSettings(settings); - }, onRunOnStartChange: function (event) { - this.storeSetting('run_on_startup', event.target.checked); + lbry.setDaemonSetting('run_on_startup', event.target.checked); }, onShareDataChange: function (event) { - this.storeSetting('upload_log', event.target.checked); + lbry.setDaemonSetting('upload_log', event.target.checked); }, onDownloadDirChange: function(event) { - this.storeSetting('download_directory', event.target.value); + lbry.setDaemonSetting('download_directory', event.target.value); }, onMaxUploadPrefChange: function(isLimited) { if (!isLimited) { - this.storeSetting('max_upload', 0.0); + lbry.setDaemonSetting('max_upload', 0.0); } this.setState({ isMaxUpload: isLimited }); }, onMaxUploadFieldChange: function(event) { - this.storeSetting('max_upload', Number(event.target.value)); + lbry.setDaemonSetting('max_upload', Number(event.target.value)); }, onMaxDownloadPrefChange: function(isLimited) { if (!isLimited) { - this.storeSetting('max_download', 0.0); + lbry.setDaemonSetting('max_download', 0.0); } this.setState({ isMaxDownload: isLimited }); }, onMaxDownloadFieldChange: function(event) { - this.storeSetting('max_download', Number(event.target.value)); + lbry.setDaemonSetting('max_download', Number(event.target.value)); }, getInitialState: function() { return { @@ -62,16 +54,16 @@ var SettingsPage = React.createClass({ document.title = "Settings"; }, componentWillMount: function() { - lbry.getSettings(function(settings) { + lbry.getDaemonSettings(function(settings) { this.setState({ - settings: settings, + initDaemonSettings: settings, isMaxUpload: settings.max_upload != 0, isMaxDownload: settings.max_download != 0 }); }.bind(this)); }, render: function() { - if (!this.state.settings) { // If the settings aren't loaded yet, don't render anything. + if (!this.state.initDaemonSettings) { return null; } @@ -80,13 +72,13 @@ var SettingsPage = React.createClass({

Run on Startup

Download Directory

Where would you like the files you download from LBRY to be saved?
- +

Bandwidth Limits

@@ -97,7 +89,7 @@ var SettingsPage = React.createClass({
@@ -107,14 +99,14 @@ var SettingsPage = React.createClass({

Share Diagnostic Data