Skip to content

Commit b67d85c

Browse files
committed
Add widget asset types for image and video, wheelspin websocket status control
1 parent bcce18f commit b67d85c

16 files changed

Lines changed: 1307 additions & 100 deletions

SubathonManager.Core/Enums/WebsocketClientMessageType.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ public enum WebsocketClientMessageType
1010
IntegrationSource, // send partial-integration events
1111
IntegrationConsumer, // get all updates like widgets
1212
ValueConfig, // will consume config events but also signify sending
13-
Command // will send commands
13+
Command, // will send commands
14+
WheelControl // will receive wheel spin history status changes
1415
}
1516

1617
[ExcludeFromCodeCoverage]
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
namespace SubathonManager.Core.Enums;
2+
3+
public enum WidgetType
4+
{
5+
Html = 0,
6+
Image = 1,
7+
Video = 2
8+
}
9+
10+
public static class WidgetTypeHelper
11+
{
12+
private static readonly HashSet<string> ImageExtensions = new(StringComparer.OrdinalIgnoreCase)
13+
{ ".png", ".jpg", ".jpeg", ".gif", ".webp", ".avif", ".bmp", ".svg" };
14+
15+
private static readonly HashSet<string> VideoExtensions = new(StringComparer.OrdinalIgnoreCase)
16+
{ ".mp4", ".m4v", ".webm", ".ogm", ".mkv", ".mov" };
17+
18+
public static WidgetType DetectFromPath(string path)
19+
{
20+
var ext = Path.GetExtension(path);
21+
22+
if (ImageExtensions.Contains(ext)) return WidgetType.Image;
23+
if (VideoExtensions.Contains(ext)) return WidgetType.Video;
24+
25+
return WidgetType.Html;
26+
}
27+
28+
public static bool IsAsset(this WidgetType type) => type != WidgetType.Html;
29+
}

SubathonManager.Core/Models/Widget.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,8 @@ public partial class Widget
262262

263263
public string? DocsUrl { get; set; } = string.Empty;
264264

265+
public WidgetType Type { get; set; } = WidgetType.Html;
266+
265267
public Widget(string name, string htmlPath)
266268
{
267269
Name = name;
@@ -281,12 +283,13 @@ public Widget Clone(Guid? routeId, string? newName, int? newZ)
281283
widget.Height = Height;
282284
widget.ScaleX = ScaleX;
283285
widget.ScaleY = ScaleY;
284-
286+
widget.Type = Type;
287+
285288
foreach (var jsVariable in JsVariables)
286289
widget.JsVariables.Add(jsVariable.Clone(widget.Id));
287290
foreach (var cssVariable in CssVariables)
288291
widget.CssVariables.Add(cssVariable.Clone(widget.Id));
289-
292+
290293
return widget;
291294
}
292295

@@ -382,6 +385,7 @@ public JsonElement ToJson(string htmlRelPath)
382385
{
383386
name = Name,
384387
htmlPath = htmlRelPath,
388+
type = Type.ToString(),
385389

386390
position = new
387391
{

0 commit comments

Comments
 (0)