Skip to content

Commit 959027f

Browse files
committed
rework how module icons are defined
1 parent 185b90f commit 959027f

File tree

6 files changed

+43
-9
lines changed

6 files changed

+43
-9
lines changed

Desktop/ModuleManager/ModuleManager.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,13 @@ private void LoadModule(string moduleFolderPath, string moduleDll, string module
223223

224224
var module = (DesktopModuleBase?)ActivatorUtilities.CreateInstance(_serviceProvider, moduleAttribute.ModuleType);
225225
if (module is null) throw new Exception("Failed to instantiate module!");
226+
227+
#pragma warning disable CS0618
228+
if (module.IconPath is not null)
229+
{
230+
module.Icon = IconOneOf.FromPath(module.IconPath);
231+
}
232+
#pragma warning restore CS0618
226233

227234
var loadedModule = new LoadedModule
228235
{

Desktop/Ui/Pages/Dash/Components/ModuleManagerItem.razor

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
@using System.Collections.Immutable
22
@using OpenShock.Desktop.Config
3+
@using OpenShock.Desktop.ModuleBase
34
@using OpenShock.Desktop.ModuleManager
45
@using OpenShock.Desktop.ModuleManager.Repository
56
@using OpenShock.Desktop.Utils
@@ -10,7 +11,15 @@
1011
@inject ISnackbar Snackbar
1112

1213
<MudPaper Class="d-flex module-manager-item-root rounded-lg gap-10" Outlined="true">
13-
<img src="@_moduleIcon" alt="@_moduleName" class="icon rounded-lg"/>
14+
@switch (_moduleIcon?.Index)
15+
{
16+
case 0:
17+
<img src="@_moduleIcon.AsT0" alt="Module Icon" class="icon rounded-lg"/>
18+
break;
19+
case 1:
20+
<MudIcon Icon="@_moduleIcon.AsT1"/>
21+
break;
22+
}
1423

1524
<div class="d-flex flex-column justify-space-evenly overflow-hidden">
1625
<MudText Typo="Typo.h4">@_moduleName</MudText>
@@ -112,7 +121,7 @@
112121
[Parameter] public required string ModuleId { get; init; }
113122

114123
private string _moduleName = null!;
115-
private string? _moduleIcon;
124+
private IconOneOf? _moduleIcon;
116125

117126
private SemVersion? LatestVersion => RepoModule?.Versions.Keys.Where(x => x.IsRelease).OrderByDescending(x => x, SemVersion.PrecedenceComparer).FirstOrDefault();
118127
private SemVersion? LatestPreReleaseVersion => RepoModule?.Versions.Keys.Where(x => !x.IsRelease).OrderByDescending(x => x, SemVersion.PrecedenceComparer).FirstOrDefault();
@@ -127,7 +136,13 @@
127136
}
128137

129138
_moduleName = RepoModule?.Name ?? (LoadedModule?.Name ?? "error");
130-
_moduleIcon = RepoModule?.IconUrl?.ToString() ?? LoadedModule?.Module.IconPath;
139+
if (RepoModule?.IconUrl is not null)
140+
{
141+
_moduleIcon = IconOneOf.FromPath(RepoModule.IconUrl.ToString());
142+
}
143+
{
144+
_moduleIcon = LoadedModule?.Module.Icon;
145+
}
131146
_availableVersions = GetAvailableVersions();
132147
}
133148

Desktop/Ui/Pages/Dash/Components/ModuleNavComponent.razor

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
@if (LoadedModule.Module.RootComponent is not null)
44
{
5-
<MudNavLink Icon="@LoadedModule.Module.IconPath" Href="@("/dash/module/" + LoadedModule.Id)">@LoadedModule.Name</MudNavLink>
5+
<ModuleNavLink Icon="LoadedModule.Module.Icon" Href="@("/dash/module/" + LoadedModule.Id)">@LoadedModule.Name</ModuleNavLink>
66
}
77
else
88
{
9-
<ModuleNavGroup IconImage="@LoadedModule.Module.IconPath" Title="@LoadedModule.Name">
9+
<ModuleNavGroup Icon="@LoadedModule.Module.Icon" Title="@LoadedModule.Name">
1010
@foreach (var subComponent in LoadedModule.Module.NavigationComponents)
1111
{
1212
<ModuleNavLink Icon="@subComponent.Icon" Href="@("/dash/module/" + LoadedModule.Id + "/" + subComponent.Name)">@(subComponent.Name)</ModuleNavLink>

Desktop/Ui/Pages/Dash/Components/ModuleNavGroup.razor

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,21 @@
1111
aria-controls="@_navigationContext.MenuId"
1212
aria-expanded="@_navigationContext.Expanded.ToString().ToLowerInvariant()"
1313
aria-label="Toggle Module Navigation">
14-
@if (!string.IsNullOrEmpty(IconImage))
14+
@switch (Icon?.Index)
1515
{
16-
<img src="@IconImage" alt="Module Icon" style="width: 24px; height: 24px">
16+
case 0:
17+
<img src="@Icon.AsT0" alt="Module Icon" style="width: 24px; height: 24px">
18+
break;
19+
case 1:
20+
<MudIcon Icon="@Icon.AsT1"/>
21+
break;
1722
}
1823
<div Class="mud-nav-link-text">
1924
@Title
2025
</div>
2126
@if (!HideExpandIcon)
2227
{
23-
<MudIcon Disabled="@Disabled" Icon="@ExpandIcon" Class="@ExpandIconClassname" />
28+
<MudIcon Disabled="@Disabled" Icon="@ExpandIcon" Class="@ExpandIconClassname"/>
2429
}
2530
</button>
2631
<MudCollapse aria-hidden="@((_navigationContext.Expanded is false).ToString().ToLowerInvariant())"

Desktop/Ui/Pages/Dash/Components/ModuleNavGroup.razor.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using MudBlazor;
44
using MudBlazor.State;
55
using MudBlazor.Utilities;
6+
using OpenShock.Desktop.ModuleBase;
67

78
namespace OpenShock.Desktop.Ui.Pages.Dash.Components;
89

@@ -71,7 +72,7 @@ protected override void OnInitialized()
7172
/// </remarks>
7273
[Parameter]
7374
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
74-
public string? IconImage { get; set; }
75+
public IconOneOf? Icon { get; set; }
7576

7677
/// <summary>
7778
/// The CSS classes applied to this nav group title.

ModuleBase/DesktopModuleBase.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,14 @@ public abstract class DesktopModuleBase
1212
/// <summary>
1313
/// Icon path for the module, used in navigation and other UI components.
1414
/// </summary>
15+
[Obsolete("Use Icon property instead. This property will be removed in a future version.")]
1516
public virtual string? IconPath { get; } = null;
1617

18+
/// <summary>
19+
/// Main icon for the module, used in navigation and other UI components.
20+
/// </summary>
21+
public virtual IconOneOf? Icon { get; set; } = null;
22+
1723
/// <summary>
1824
/// Main interface for modules to interact with OpenShock Desktop.
1925
/// </summary>

0 commit comments

Comments
 (0)