Files
Essentials/src/PepperDash.Essentials.MobileControl/Touchpanel/ThemeMessenger.cs
Andrew Welker 9c9eaea928 feat: unique status requests for messengers
UI Applications can now request status for specific feature sets instead of full status for a device. This will hopefully cut down on the traffic and messages required to get the data for the UI.
2025-09-23 10:55:16 -05:00

53 lines
1.5 KiB
C#

using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using PepperDash.Core;
using PepperDash.Essentials.AppServer;
using PepperDash.Essentials.AppServer.Messengers;
namespace PepperDash.Essentials.Touchpanel
{
/// <summary>
/// Represents a ThemeMessenger
/// </summary>
public class ThemeMessenger : MessengerBase
{
private readonly ITheme _tpDevice;
public ThemeMessenger(string key, string path, ITheme device) : base(key, path, device as Device)
{
_tpDevice = device;
}
protected override void RegisterActions()
{
AddAction("/fullStatus", (id, content) =>
{
PostStatusMessage(new ThemeUpdateMessage { Theme = _tpDevice.Theme });
});
AddAction("/saveTheme", (id, content) =>
{
var theme = content.ToObject<MobileControlSimpleContent<string>>();
Debug.LogMessage(Serilog.Events.LogEventLevel.Information, "Setting theme to {theme}", this, theme.Value);
_tpDevice.UpdateTheme(theme.Value);
PostStatusMessage(JToken.FromObject(new { theme = theme.Value }));
});
}
}
/// <summary>
/// Represents a ThemeUpdateMessage
/// </summary>
public class ThemeUpdateMessage : DeviceStateMessageBase
{
/// <summary>
/// Gets or sets the Theme
/// </summary>
[JsonProperty("theme")]
public string Theme { get; set; }
}
}