using Newtonsoft.Json; using Newtonsoft.Json.Linq; using PepperDash.Core; using PepperDash.Core.Logging; using PepperDash.Essentials.AppServer; using PepperDash.Essentials.AppServer.Messengers; namespace PepperDash.Essentials.Touchpanel { /// /// Messenger to save the current theme (light/dark) and send to a device /// public class ThemeMessenger : MessengerBase { private readonly ITheme _tpDevice; /// /// Create an instance of the class /// /// The key for this messenger /// The path for this messenger /// The device for this messenger 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 }, id); }); AddAction("/saveTheme", (id, content) => { var theme = content.ToObject>(); this.LogInformation("Setting theme to {theme}", theme.Value); _tpDevice.UpdateTheme(theme.Value); PostStatusMessage(JToken.FromObject(new { theme = theme.Value }), clientId: id); }); } } /// /// Represents a ThemeUpdateMessage /// public class ThemeUpdateMessage : DeviceStateMessageBase { /// /// Gets or sets the Theme /// [JsonProperty("theme")] public string Theme { get; set; } } }