From aaf470a1cde07b20f2a30c3063a8c01105bf8fc8 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Tue, 12 Oct 2021 09:04:47 -0500 Subject: add options broadcast to ApplicationHub --- src/slskd/Core/API/Hubs/ApplicationHub.cs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'src') 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/. // +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"; } /// @@ -41,6 +44,17 @@ namespace slskd.Core.API { return hub.Clients.All.SendAsync(ApplicationHubMethods.State, state); } + + /// + /// Broadcast the present application options. + /// + /// The hub. + /// The options to broadcast. + /// The operation context. + public static Task BroadcastOptionsAsync(this IHubContext hub, Options options) + { + return hub.Clients.All.SendAsync(ApplicationHubMethods.Options, options); + } } /// @@ -49,16 +63,21 @@ namespace slskd.Core.API [Authorize] public class ApplicationHub : Hub { - public ApplicationHub(IStateMonitor stateMonitor) + public ApplicationHub( + IStateMonitor stateMonitor, + IOptionsMonitor optionsMonitor) { StateMonitor = stateMonitor; + OptionsMonitor = optionsMonitor; } IStateMonitor StateMonitor { get; } + IOptionsMonitor 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 -- cgit v1.2.3 From 9b3a2db7ac917913a0baa54432b6f844437800e8 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Tue, 12 Oct 2021 09:07:29 -0500 Subject: broadcast options on change --- src/slskd/Application.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src') 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); } /// -- cgit v1.2.3 From b073af776e6bd7b57c14b219de3d22d6417d9dfa Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Tue, 12 Oct 2021 09:07:39 -0500 Subject: add stubbed Options component --- src/web/src/components/System/Options.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 src/web/src/components/System/Options.js (limited to 'src') 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 ( +
+
{JSON.stringify(this.props.options, null, 2)}
+
+ ); + } +} + +export default Options; \ No newline at end of file -- cgit v1.2.3 From 193a050ad1ed6be9f2a0af31cf20994b4d0091bd Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Tue, 12 Oct 2021 09:07:49 -0500 Subject: add Options tab --- src/web/src/components/System/System.js | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src') 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 { }, + { menuItem: 'Options', render: () => }, { menuItem: 'Logs', render: () => }, ]}/> -- cgit v1.2.3 From 26c134e898c65110e63dcc4254cf7693f5f096a2 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Tue, 12 Oct 2021 09:08:03 -0500 Subject: capture options from SignalR and pass to System --- src/web/src/components/App.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/web/src/components/App.js b/src/web/src/components/App.js index f8813820..0eb2b6a9 100644 --- a/src/web/src/components/App.js +++ b/src/web/src/components/App.js @@ -34,6 +34,7 @@ const initialState = { error: undefined }, applicationState: {}, + applicationOptions: {}, error: false, }; @@ -64,6 +65,11 @@ class App extends Component { this.setState({ applicationState: state }); }); + appHub.on('options', (options) => { + console.debug(options); + this.setState({ applicationOptions: options }); + }) + appHub.onreconnecting(() => this.setState({ error: true })); appHub.onclose(() => this.setState({ error: true })); appHub.onreconnected(() => this.setState({ error: false })); @@ -226,7 +232,7 @@ class App extends Component { this.withTokenCheck()}/> this.withTokenCheck()}/> this.withTokenCheck()}/> - this.withTokenCheck()}/> + this.withTokenCheck()}/> this.withTokenCheck()}/> -- cgit v1.2.3