diff --git a/Moonlight/App/Models/Json/Theme/ThemeExport.cs b/Moonlight/App/Models/Json/Theme/ThemeExport.cs new file mode 100644 index 00000000..fee81d6b --- /dev/null +++ b/Moonlight/App/Models/Json/Theme/ThemeExport.cs @@ -0,0 +1,10 @@ +namespace Moonlight.App.Models.Json.Theme; + +public class ThemeExport +{ + public string Name { get; set; } = ""; + public string Author { get; set; } = ""; + public string? DonateUrl { get; set; } = ""; + public string CssUrl { get; set; } = ""; + public string? JsUrl { get; set; } = ""; +} \ No newline at end of file diff --git a/Moonlight/App/Models/Json/Theme/ThemeImport.cs b/Moonlight/App/Models/Json/Theme/ThemeImport.cs new file mode 100644 index 00000000..370dbfc5 --- /dev/null +++ b/Moonlight/App/Models/Json/Theme/ThemeImport.cs @@ -0,0 +1,10 @@ +namespace Moonlight.App.Models.Json.Theme; + +public class ThemeImport +{ + public string Name { get; set; } = ""; + public string Author { get; set; } = ""; + public string? DonateUrl { get; set; } = ""; + public string CssUrl { get; set; } = ""; + public string? JsUrl { get; set; } = ""; +} \ No newline at end of file diff --git a/Moonlight/App/Services/Interop/FileDownloadService.cs b/Moonlight/App/Services/Interop/FileDownloadService.cs new file mode 100644 index 00000000..572417e7 --- /dev/null +++ b/Moonlight/App/Services/Interop/FileDownloadService.cs @@ -0,0 +1,34 @@ +using System.Text; +using Microsoft.JSInterop; + +namespace Moonlight.App.Services.Interop; + +public class FileDownloadService +{ + private readonly IJSRuntime JsRuntime; + + public FileDownloadService(IJSRuntime jsRuntime) + { + JsRuntime = jsRuntime; + } + + public async Task DownloadStream(string fileName, Stream stream) + { + using var streamRef = new DotNetStreamReference(stream); + + await JsRuntime.InvokeVoidAsync("moonlight.utils.download", fileName, streamRef); + } + + public async Task DownloadBytes(string fileName, byte[] bytes) + { + var ms = new MemoryStream(bytes); + + await DownloadStream(fileName, ms); + + ms.Close(); + await ms.DisposeAsync(); + } + + public async Task DownloadString(string fileName, string content) => + await DownloadBytes(fileName, Encoding.UTF8.GetBytes(content)); +} \ No newline at end of file diff --git a/Moonlight/Pages/_Host.cshtml b/Moonlight/Pages/_Host.cshtml index 801ac5e7..381ac914 100644 --- a/Moonlight/Pages/_Host.cshtml +++ b/Moonlight/Pages/_Host.cshtml @@ -55,7 +55,7 @@ @foreach (var theme in themes) { - if (theme.JsUrl != null) + if (!string.IsNullOrEmpty(theme.JsUrl)) { diff --git a/Moonlight/Program.cs b/Moonlight/Program.cs index c1674416..f5c1482f 100644 --- a/Moonlight/Program.cs +++ b/Moonlight/Program.cs @@ -56,6 +56,7 @@ builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); +builder.Services.AddScoped(); // Services / Store builder.Services.AddScoped(); diff --git a/Moonlight/Shared/Components/Forms/AutoCrud.razor b/Moonlight/Shared/Components/Forms/AutoCrud.razor index e6b5bcc3..dfad589f 100644 --- a/Moonlight/Shared/Components/Forms/AutoCrud.razor +++ b/Moonlight/Shared/Components/Forms/AutoCrud.razor @@ -14,7 +14,8 @@

@(Title)

-
@@ -26,7 +27,7 @@ PageSize="50" TableClass="table table-row-bordered table-row-gray-100 align-middle gs-0 gy-3 fs-6" TableHeadClass="fw-bold text-muted"> - @ChildContent + @View