Skip to content

Commit 1c22b2d

Browse files
committed
fix some issues, add ddc settings, make new ui default
1 parent 827157f commit 1c22b2d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+5393
-3905
lines changed

ColorControl.UI/Blazor.cs

Lines changed: 102 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,118 @@
11
using ColorControl.Shared.Contracts;
22
using ColorControl.UI.Services;
3+
using Microsoft.AspNetCore.Hosting.Server;
4+
using Microsoft.AspNetCore.Hosting.Server.Features;
5+
using System.Net;
36

47
namespace ColorControl.UI;
58

69
public static class Blazor
710
{
8-
public static void Start(Config? config = null)
9-
{
10-
var builder = WebApplication.CreateBuilder();
11+
private static WebApplication? CurrentApplication;
12+
private static int Port;
13+
private static bool AllowRemoteConnections;
1114

12-
// Add services to the container.
13-
builder.Services.AddRazorComponents()
14-
.AddInteractiveServerComponents();
15+
public static bool IsRunning(Config config) => CurrentApplication != null && Port == config.UiPort && AllowRemoteConnections == config.UiAllowRemoteConnections;
1516

16-
builder.Services.AddSingleton<AppState>(new AppState { SelectedTheme = (config?.UseDarkMode ?? true) ? "dark" : "light" });
17-
builder.Services.AddTransient<RpcUiClientService>();
18-
builder.Services.AddTransient<JSHelper>();
19-
builder.Services.AddHttpContextAccessor();
20-
builder.Services.AddSingleton<NotificationService>();
21-
builder.WebHost.ConfigureKestrel(o => o.ListenAnyIP(config?.UiPort > 0 ? config.UiPort : 5000));
17+
public static async Task Start(Config config)
18+
{
19+
if (IsRunning(config))
20+
{
21+
return;
22+
}
2223

23-
var app = builder.Build();
24+
await Stop();
2425

25-
// Configure the HTTP request pipeline.
26-
if (!app.Environment.IsDevelopment())
27-
{
28-
app.UseExceptionHandler("/Error", createScopeForErrors: true);
29-
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
30-
app.UseHsts();
31-
}
26+
var builder = WebApplication.CreateBuilder();
3227

33-
app.UseHttpsRedirection();
28+
// Add services to the container.
29+
builder.Services.AddRazorComponents()
30+
.AddInteractiveServerComponents();
3431

35-
app.UseStaticFiles();
36-
app.UseAntiforgery();
32+
builder.Services.AddSingleton<AppState>(new AppState { SelectedTheme = config.UseDarkMode ? "dark" : "light" });
33+
builder.Services.AddTransient<RpcUiClientService>();
34+
builder.Services.AddTransient<JSHelper>();
35+
builder.Services.AddHttpContextAccessor();
36+
builder.Services.AddSingleton<NotificationService>();
3737

38-
app.MapRazorComponents<Components.App>()
39-
.AddInteractiveServerRenderMode();
38+
builder.Services.Configure<HostOptions>(opts => opts.ShutdownTimeout = TimeSpan.FromSeconds(3));
39+
40+
var listenPort = config.UiPort > 0 ? config.UiPort : 0;
41+
42+
builder.WebHost.ConfigureKestrel(options =>
43+
{
44+
if (config.UiAllowRemoteConnections)
45+
{
46+
options.ListenAnyIP(listenPort);
47+
}
48+
else
49+
{
50+
options.Listen(IPAddress.Parse("127.0.0.1"), listenPort);
51+
}
52+
});
53+
54+
var app = builder.Build();
55+
56+
// Configure the HTTP request pipeline.
57+
if (!app.Environment.IsDevelopment())
58+
{
59+
app.UseExceptionHandler("/Error", createScopeForErrors: true);
60+
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
61+
app.UseHsts();
62+
}
63+
64+
app.UseHttpsRedirection();
65+
66+
app.UseStaticFiles();
67+
app.UseAntiforgery();
68+
69+
app.MapRazorComponents<Components.App>()
70+
.AddInteractiveServerRenderMode();
71+
72+
CurrentApplication = app;
73+
Port = config.UiPort;
74+
AllowRemoteConnections = config.UiAllowRemoteConnections;
75+
76+
await app.RunAsync();
77+
}
78+
79+
public static async Task Stop()
80+
{
81+
if (CurrentApplication != null)
82+
{
83+
await CurrentApplication.StopAsync();
84+
CurrentApplication = null;
85+
}
86+
}
87+
88+
public static string GetCurrentUrl()
89+
{
90+
var port = GetCurrentPort();
91+
92+
return $"http://localhost:{port}";
93+
}
94+
95+
public static int GetCurrentPort()
96+
{
97+
if (CurrentApplication == null)
98+
{
99+
return -1;
100+
}
101+
102+
var server = CurrentApplication.Services.GetService<IServer>();
103+
var addressFeature = server?.Features.Get<IServerAddressesFeature>();
104+
105+
if (addressFeature == null)
106+
{
107+
return -1;
108+
}
109+
110+
foreach (var address in addressFeature.Addresses)
111+
{
112+
return int.Parse(address.Split(':').Last());
113+
}
114+
115+
return -1;
116+
}
40117

41-
app.Run();
42-
}
43118
}

ColorControl.UI/Components/Pages/ColorProfile/ColorProfilePage.razor

Lines changed: 50 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,16 @@
5151
<label class="form-label" for="description">Description</label>
5252
<input class="form-control" type="text" id="description" @bind="ColorProfile.Description" />
5353
</div>
54+
<div class="mb-2">
55+
<label class="form-label" for="renderingIntent">Rendering intent</label>
56+
<select class="form-select" id="renderingIntent" @bind="ColorProfile.RenderingIntent">
57+
@foreach (var renderingIntent in Enum.GetValues<LittleCms.RenderingIntent>().Where(ri => ri <= LittleCms.RenderingIntent.ABSOLUTE_COLORIMETRIC))
58+
{
59+
<option value="@renderingIntent">@renderingIntent.GetDescription()</option>
60+
}
61+
</select>
62+
</div>
63+
5464
<div class="accordion accordion-flush" id="presetAccordion">
5565

5666
<div class="accordion-item">
@@ -236,21 +246,49 @@
236246
</div>
237247
</div>
238248
</div>
239-
<div class="row">
240-
<div class="col">
241-
<div class="mb-2">
242-
<label class="form-label" for="brightnessBoost">Brightness boost (%)</label>
243-
<input class="form-control" id="brightnessBoost" type="number" min="-100" max="100" @bind="ColorProfile.SDRBrightnessBoost" disabled="@(ColorProfile.SDRTransferFunction == SDRTransferFunction.ToneMappedPiecewise)" />
244-
</div>
249+
}
250+
<div class="row">
251+
<div class="col">
252+
<div class="mb-2">
253+
<label class="form-label" for="brightnessBoost">Brightness boost (%)</label>
254+
<input class="form-control" id="brightnessBoost" type="number" min="-100" max="100" @bind="ColorProfile.SDRBrightnessBoost" disabled="@(ColorProfile.SDRTransferFunction == SDRTransferFunction.ToneMappedPiecewise)" />
245255
</div>
246-
<div class="col">
247-
<div class="mb-2">
248-
<label class="form-label" for="shadowDetailBoost">Shadow detail boost (%)</label>
249-
<input class="form-control" id="shadowDetailBoost" type="number" min="0" max="100" @bind="ColorProfile.ShadowDetailBoost" disabled="@(ColorProfile.SDRTransferFunction == SDRTransferFunction.Piecewise || ColorProfile.SDRTransferFunction == SDRTransferFunction.ToneMappedPiecewise)" />
250-
</div>
256+
</div>
257+
<div class="col">
258+
<div class="mb-2">
259+
<label class="form-label" for="shadowDetailBoost">Shadow detail boost (%)</label>
260+
<input class="form-control" id="shadowDetailBoost" type="number" min="-50" max="200" @bind="ColorProfile.ShadowDetailBoost" disabled="@(ColorProfile.SDRTransferFunction == SDRTransferFunction.ToneMappedPiecewise)" />
251261
</div>
252262
</div>
253-
263+
<div class="col">
264+
<div class="mb-2">
265+
<label class="form-label" for="shadowDetailRange">Shadow detail range (%)</label>
266+
<input class="form-control" id="shadowDetailRange" type="number" min="0" max="100" @bind="ColorProfile.ShadowDetailRange" disabled="@(ColorProfile.SDRTransferFunction == SDRTransferFunction.ToneMappedPiecewise)" />
267+
</div>
268+
</div>
269+
</div>
270+
<div class="row">
271+
<div class="col">
272+
<div class="mb-2">
273+
<label class="form-label" for="redGain">Red gain (%)</label>
274+
<input class="form-control" id="redGain" type="number" min="1" max="200" step="0.01" @bind="ColorProfile.RedGain" disabled="@(ColorProfile.SDRTransferFunction == SDRTransferFunction.ToneMappedPiecewise)" />
275+
</div>
276+
</div>
277+
<div class="col">
278+
<div class="mb-2">
279+
<label class="form-label" for="greenGain">Green gain (%)</label>
280+
<input class="form-control" id="greenGain" type="number" min="1" max="200" step="0.01" @bind="ColorProfile.GreenGain" disabled="@(ColorProfile.SDRTransferFunction == SDRTransferFunction.ToneMappedPiecewise)" />
281+
</div>
282+
</div>
283+
<div class="col">
284+
<div class="mb-2">
285+
<label class="form-label" for="blueGain">Blue gain (%)</label>
286+
<input class="form-control" id="blueGain" type="number" min="1" max="200" step="0.01" @bind="ColorProfile.BlueGain" disabled="@(ColorProfile.SDRTransferFunction == SDRTransferFunction.ToneMappedPiecewise)" />
287+
</div>
288+
</div>
289+
</div>
290+
@if (ColorProfile.IsHDRProfile)
291+
{
254292
<div class="row">
255293
<div class="col">
256294
<div class="mb-2">
@@ -280,17 +318,6 @@
280318
</div>
281319
</div>
282320
}
283-
else
284-
{
285-
<div class="row">
286-
<div class="col">
287-
<div class="mb-2">
288-
<label class="form-label" for="shadowDetailBoost">Shadow detail boost (%)</label>
289-
<input class="form-control" id="shadowDetailBoost" type="number" min="0" max="100" @bind="ColorProfile.ShadowDetailBoost" disabled="@(ColorProfile.SDRTransferFunction == SDRTransferFunction.Piecewise)" />
290-
</div>
291-
</div>
292-
</div>
293-
}
294321
</div>
295322
</div>
296323
</div>

ColorControl.UI/Components/Pages/Game/GameSummary.razor

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ else
6868
{
6969
<span class="ms-2 badge text-bg-warning" title="Show in Quick Access">QA</span>
7070
}
71+
@if (!preset.PathExists)
72+
{
73+
<span class="ms-2 badge text-bg-danger" title="@($"Path '{preset.Path}' is not found")">Not found</span>
74+
}
7175
</h5>
7276
</div>
7377
<span class="d-none d-lg-block">

ColorControl.UI/Components/Pages/Generic/FieldDefs.razor

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646

4747
<div class="mb-2">
4848
<label class="form-label" for="@fieldId">@field.Label</label>
49-
<select class="form-select" id="@fieldId" @bind="field.StringValue">
49+
<select class="form-select" id="@fieldId" @bind="field.StringValue" @bind:after="() => FieldBindAfter(field)">
5050
@if (field.ValueType != null)
5151
{
5252
@foreach (var item in Enum.GetValues(field.ValueType))
@@ -111,4 +111,12 @@
111111
@code {
112112
[Parameter]
113113
public List<FieldDefinition>? Fields { get; set; }
114+
115+
[Parameter]
116+
public EventCallback<FieldDefinition> FieldValueChanged { get; set; }
117+
118+
private async Task FieldBindAfter(FieldDefinition field)
119+
{
120+
await FieldValueChanged.InvokeAsync(field);
121+
}
114122
}

ColorControl.UI/Components/Pages/Generic/RangeInput.razor

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,5 +112,4 @@
112112

113113
ExtraLabelStyling = LabelStylingFunc?.Invoke(Value);
114114
}
115-
116115
}

0 commit comments

Comments
 (0)