Skip to content

Commit 7dde1d8

Browse files
committed
Added theme loading. Improved theme editor. Updated app theme model
1 parent a480ae9 commit 7dde1d8

File tree

8 files changed

+339
-165
lines changed

8 files changed

+339
-165
lines changed

Moonlight.ApiServer/Http/Controllers/Frontend/FrontendPage.razor

Lines changed: 63 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,73 @@
1+
@using Moonlight.ApiServer.Database.Entities
12
@using Moonlight.Shared.Misc
3+
24
<!DOCTYPE html>
35
<html lang="en" class="bg-background text-base-content font-inter">
46

57
<head>
6-
<meta charset="utf-8" />
7-
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
8+
<meta charset="utf-8"/>
9+
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
810
<title>@Configuration.Title</title>
9-
<base href="/" />
10-
11+
<base href="/"/>
12+
1113
@foreach (var style in Configuration.Styles)
1214
{
13-
<link rel="stylesheet" href="@style" />
15+
<link rel="stylesheet" href="@style"/>
16+
}
17+
18+
<link href="manifest.webmanifest" rel="manifest"/>
19+
<link rel="apple-touch-icon" sizes="512x512" href="/_content/Moonlight.Client/img/icon-512.png"/>
20+
<link rel="apple-touch-icon" sizes="192x192" href="/_content/Moonlight.Client/img/icon-192.png"/>
21+
22+
@if (Theme != null)
23+
{
24+
<style>
25+
:root {
26+
--mooncore-color-background: @(Theme.Content.ColorBackground);
27+
--mooncore-color-base-100: @(Theme.Content.ColorBase100);
28+
--mooncore-color-base-150: @(Theme.Content.ColorBase150);
29+
--mooncore-color-base-200: @(Theme.Content.ColorBase200);
30+
--mooncore-color-base-250: @(Theme.Content.ColorBase250);
31+
--mooncore-color-base-300: @(Theme.Content.ColorBase300);
32+
--mooncore-color-base-content: @(Theme.Content.ColorBaseContent);
33+
34+
--mooncore-color-primary: @(Theme.Content.ColorPrimary);
35+
--mooncore-color-primary-content: @(Theme.Content.ColorPrimaryContent);
36+
37+
--mooncore-color-secondary: @(Theme.Content.ColorSecondary);
38+
--mooncore-color-secondary-content: @(Theme.Content.ColorSecondaryContent);
39+
40+
--mooncore-color-accent: @(Theme.Content.ColorAccent);
41+
--mooncore-color-accent-content: @(Theme.Content.ColorAccentContent);
42+
43+
--mooncore-color-neutral: @(Theme.Content.ColorNeutral);
44+
--mooncore-color-neutral-content: @(Theme.Content.ColorNeutralContent);
45+
46+
--mooncore-color-info: @(Theme.Content.ColorInfo);
47+
--mooncore-color-info-content: @(Theme.Content.ColorInfoContent);
48+
49+
--mooncore-color-success: @(Theme.Content.ColorSuccess);
50+
--mooncore-color-success-content: @(Theme.Content.ColorSuccessContent);
51+
52+
--mooncore-color-warning: @(Theme.Content.ColorWarning);
53+
--mooncore-color-warning-content: @(Theme.Content.ColorWarningContent);
54+
55+
--mooncore-color-error: @(Theme.Content.ColorError);
56+
--mooncore-color-error-content: @(Theme.Content.ColorErrorContent);
57+
58+
--mooncore-radius-selector: @(Theme.Content.RadiusSelector)rem;
59+
--mooncore-radius-field: @(Theme.Content.RadiusField)rem;
60+
--mooncore-radius-box: @(Theme.Content.RadiusBox)rem;
61+
62+
--mooncore-size-selector: @(Theme.Content.SizeSelector)rem;
63+
--mooncore-size-field: @(Theme.Content.SizeField)rem;
64+
65+
--mooncore-border: @(Theme.Content.Border)px;
66+
--mooncore-depth: @(Theme.Content.Depth);
67+
--mooncore-noise: @(Theme.Content.Noise);
68+
}
69+
</style>
1470
}
15-
16-
<link href="manifest.webmanifest" rel="manifest" />
17-
<link rel="apple-touch-icon" sizes="512x512" href="/_content/Moonlight.Client/img/icon-512.png" />
18-
<link rel="apple-touch-icon" sizes="192x192" href="/_content/Moonlight.Client/img/icon-192.png" />
1971
</head>
2072

2173
<body>
@@ -31,7 +83,7 @@
3183
</div>
3284
</div>
3385
</div>
34-
86+
3587
</div>
3688

3789
@foreach (var script in Configuration.Scripts)
@@ -48,4 +100,5 @@
48100
@code
49101
{
50102
[Parameter] public FrontendConfiguration Configuration { get; set; }
103+
[Parameter] public Theme? Theme { get; set; }
51104
}

Moonlight.ApiServer/Models/ApplicationTheme.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,6 @@ public class ApplicationTheme
4444
public float SizeField { get; set; }
4545

4646
public float Border { get; set; }
47-
public float Depth { get; set; }
48-
public float Noise { get; set; }
47+
public int Depth { get; set; }
48+
public int Noise { get; set; }
4949
}

Moonlight.ApiServer/Services/FrontendService.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@
22
using System.Text;
33
using System.Text.Json;
44
using Microsoft.AspNetCore.Hosting;
5+
using Microsoft.EntityFrameworkCore;
56
using Microsoft.Extensions.FileProviders;
67
using MoonCore.Attributes;
78
using MoonCore.Exceptions;
9+
using MoonCore.Extended.Abstractions;
810
using MoonCore.Helpers;
911
using Moonlight.ApiServer.Configuration;
12+
using Moonlight.ApiServer.Database.Entities;
1013
using Moonlight.ApiServer.Http.Controllers.Frontend;
1114
using Moonlight.ApiServer.Models;
1215
using Moonlight.Shared.Misc;
@@ -20,18 +23,21 @@ public class FrontendService
2023
private readonly IWebHostEnvironment WebHostEnvironment;
2124
private readonly IEnumerable<FrontendConfigurationOption> ConfigurationOptions;
2225
private readonly IServiceProvider ServiceProvider;
26+
private readonly DatabaseRepository<Theme> ThemeRepository;
2327

2428
public FrontendService(
2529
AppConfiguration configuration,
2630
IWebHostEnvironment webHostEnvironment,
2731
IEnumerable<FrontendConfigurationOption> configurationOptions,
28-
IServiceProvider serviceProvider
32+
IServiceProvider serviceProvider,
33+
DatabaseRepository<Theme> themeRepository
2934
)
3035
{
3136
Configuration = configuration;
3237
WebHostEnvironment = webHostEnvironment;
3338
ConfigurationOptions = configurationOptions;
3439
ServiceProvider = serviceProvider;
40+
ThemeRepository = themeRepository;
3541
}
3642

3743
public async Task<FrontendConfiguration> GetConfiguration()
@@ -71,11 +77,16 @@ public async Task<string> GenerateIndexHtml() // TODO: Cache
7177
{
7278
var configuration = await GetConfiguration();
7379

80+
var theme = await ThemeRepository
81+
.Get()
82+
.FirstOrDefaultAsync(x => x.IsEnabled);
83+
7484
return await ComponentHelper.RenderComponent<FrontendPage>(
7585
ServiceProvider,
7686
parameters =>
7787
{
7888
parameters["Configuration"] = configuration;
89+
parameters["Theme"] = theme!;
7990
}
8091
);
8192
}

Moonlight.Client/Styles/mappings/classes.map

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,9 +224,11 @@ grid
224224
grid-cols-1
225225
grid-cols-12
226226
grid-cols-2
227+
grid-cols-3
227228
grid-flow-col
228229
grow
229230
grow-0
231+
h-0
230232
h-12
231233
h-14
232234
h-2
@@ -399,6 +401,7 @@ overlay-open:duration-50
399401
overlay-open:opacity-100
400402
p-0.5
401403
p-1
404+
p-1.5
402405
p-2
403406
p-2.5
404407
p-3

Moonlight.Client/UI/Components/ThemeColorSelector.razor

Lines changed: 0 additions & 83 deletions
This file was deleted.

0 commit comments

Comments
 (0)