diff options
| author | JP Dillingham <jpdillingham@gmail.com> | 2021-10-16 18:37:47 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-10-16 18:37:47 -0500 |
| commit | f2213488b3eaabea38e1f5859974952708cdd300 (patch) | |
| tree | 6c421eaff3ef7ef578d22fa097098cf73d8d8935 /src | |
| parent | 3d136ba9eeb01481e0cfb1e9192234444e87a6d2 (diff) | |
| parent | 1952103f75d1050cfc6fd5382d17e1de8b02cd27 (diff) | |
| download | slskd-f2213488b3eaabea38e1f5859974952708cdd300.tar.gz | |
Merge pull request #218 from slskd/config-ui
Display configuration on the UI
Diffstat (limited to 'src')
| -rw-r--r-- | src/slskd/Application.cs | 6 | ||||
| -rw-r--r-- | src/slskd/Core/API/Hubs/ApplicationHub.cs | 21 | ||||
| -rw-r--r-- | src/web/src/components/System/Options.js | 13 | ||||
| -rw-r--r-- | src/web/src/components/System/System.js | 2 |
4 files changed, 39 insertions, 3 deletions
diff --git a/src/slskd/Application.cs b/src/slskd/Application.cs index 1027d7f3..681384b3 100644 --- a/src/slskd/Application.cs +++ b/src/slskd/Application.cs @@ -638,6 +638,9 @@ namespace slskd Logger.Information("One or more updated options requires an application restart to take effect."); } + PreviousOptions = newOptions; + _ = ApplicationHub.BroadcastOptionsAsync(newOptions); + Logger.Information("Options updated successfully."); } catch (Exception ex) @@ -646,7 +649,6 @@ namespace slskd } finally { - PreviousOptions = OptionsMonitor.CurrentValue; OptionsSyncRoot.ExitWriteLock(); } } @@ -740,7 +742,7 @@ namespace slskd private void State_OnChange((State Previous, State Current) state) { Logger.Debug("State changed from {Previous} to {Current}", state.Previous.ToJson(), state.Current.ToJson()); - ApplicationHub.BroadcastStateAsync(state.Current); + _ = ApplicationHub.BroadcastStateAsync(state.Current); } /// <summary> diff --git a/src/slskd/Core/API/Hubs/ApplicationHub.cs b/src/slskd/Core/API/Hubs/ApplicationHub.cs index c02f625f..46a1fef9 100644 --- a/src/slskd/Core/API/Hubs/ApplicationHub.cs +++ b/src/slskd/Core/API/Hubs/ApplicationHub.cs @@ -15,6 +15,8 @@ // along with this program. If not, see https://www.gnu.org/licenses/. // </copyright> +using Microsoft.Extensions.Options; + namespace slskd.Core.API { using System.Threading.Tasks; @@ -24,6 +26,7 @@ namespace slskd.Core.API public static class ApplicationHubMethods { public static readonly string State = "STATE"; + public static readonly string Options = "OPTIONS"; } /// <summary> @@ -41,6 +44,17 @@ namespace slskd.Core.API { return hub.Clients.All.SendAsync(ApplicationHubMethods.State, state); } + + /// <summary> + /// Broadcast the present application options. + /// </summary> + /// <param name="hub">The hub.</param> + /// <param name="options">The options to broadcast.</param> + /// <returns>The operation context.</returns> + public static Task BroadcastOptionsAsync(this IHubContext<ApplicationHub> hub, Options options) + { + return hub.Clients.All.SendAsync(ApplicationHubMethods.Options, options); + } } /// <summary> @@ -49,16 +63,21 @@ namespace slskd.Core.API [Authorize] public class ApplicationHub : Hub { - public ApplicationHub(IStateMonitor<State> stateMonitor) + public ApplicationHub( + IStateMonitor<State> stateMonitor, + IOptionsMonitor<Options> optionsMonitor) { StateMonitor = stateMonitor; + OptionsMonitor = optionsMonitor; } IStateMonitor<State> StateMonitor { get; } + IOptionsMonitor<Options> OptionsMonitor { get; } public override async Task OnConnectedAsync() { await Clients.Caller.SendAsync(ApplicationHubMethods.State, StateMonitor.CurrentValue); + await Clients.Caller.SendAsync(ApplicationHubMethods.Options, OptionsMonitor.CurrentValue); } } }
\ No newline at end of file diff --git a/src/web/src/components/System/Options.js b/src/web/src/components/System/Options.js new file mode 100644 index 00000000..e822b11d --- /dev/null +++ b/src/web/src/components/System/Options.js @@ -0,0 +1,13 @@ +import React, { Component } from 'react'; + +class Options extends Component { + render = () => { + return ( + <div> + <pre>{JSON.stringify(this.props.options, null, 2)}</pre> + </div> + ); + } +} + +export default Options;
\ No newline at end of file diff --git a/src/web/src/components/System/System.js b/src/web/src/components/System/System.js index e1e61c5c..bbba292d 100644 --- a/src/web/src/components/System/System.js +++ b/src/web/src/components/System/System.js @@ -3,6 +3,7 @@ import { Segment, Tab } from 'semantic-ui-react'; import './System.css'; import Info from './Info'; import Logs from './Logs'; +import Options from './Options'; class System extends Component { componentDidMount = () => { @@ -18,6 +19,7 @@ class System extends Component { <Segment raised> <Tab panes={[ { menuItem: 'Info', render: () => <Tab.Pane><Info state={this.props.state}/></Tab.Pane> }, + { menuItem: 'Options', render: () => <Tab.Pane><Options options={this.props.options}/></Tab.Pane> }, { menuItem: 'Logs', render: () => <Tab.Pane><Logs/></Tab.Pane> }, ]}/> </Segment> |
