Skip to content

Commit

Permalink
stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
phasephasephase committed Dec 31, 2023
1 parent b4de2b4 commit 0710a2f
Show file tree
Hide file tree
Showing 8 changed files with 123 additions and 116 deletions.
67 changes: 67 additions & 0 deletions JiayiLauncher/Appearance/LocalTheme.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
using System.Collections.Generic;
using System.IO;
using System.Text;
using JiayiLauncher.Settings;

namespace JiayiLauncher.Appearance;

public class LocalTheme
{
private static readonly string _themeRoot = Path.Combine(ThemeState.WWWRootPath, "themes");

public string Name;

public LocalTheme(string name)
{
Name = name;
}

public static LocalTheme[] GetAllThemes()
{
var localThemes = new List<LocalTheme>();

var directories = Directory.GetDirectories(Path.Combine(_themeRoot, ".local"));
foreach (var d in directories)
{
var name = new DirectoryInfo(d).Name;
var theme = new LocalTheme(name);
localThemes.Add(theme);
}

if (localThemes.Count <= 0)
{
var theme = CreateTheme("default");
if (theme != null) localThemes.Add(theme);
}

return localThemes.ToArray();
}

public static LocalTheme? CreateTheme(string name)
{
var path = Path.Combine(_themeRoot, $".local\\{name}");
if (Directory.Exists(path))
{
return null;
}

Directory.CreateDirectory(path);

var buffer = File.Create(Path.Combine(path, "theme.css"));
var defaultTheme = new ThemeState().ThemeCSS.ToString();
byte[] byteArray = Encoding.UTF8.GetBytes(defaultTheme);
buffer.Write(byteArray, 0, byteArray.Length);
buffer.Close();

return new LocalTheme(name);
}

public static void SaveCurrentTheme()
{
var buffer = File.OpenWrite(Path.Combine(_themeRoot, JiayiSettings.Instance.Theme, "theme.css"));
var themeCSS = ThemeState.Instance.ThemeCSS.ToString();
byte[] byteArray = Encoding.UTF8.GetBytes(themeCSS);
buffer.Write(byteArray, 0, byteArray.Length);
buffer.Close();
}
}
35 changes: 35 additions & 0 deletions JiayiLauncher/Appearance/PublicTheme.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System;
using JiayiLauncher.Utils;
using Newtonsoft.Json;

namespace JiayiLauncher.Appearance;

public class PublicTheme : ThemeMetadata
{
[JsonProperty("Name")]
public string Name;

[JsonProperty("bg")]
public Uri Background;

[JsonProperty("meta")]
public Uri Metadata;

[JsonProperty("theme")]
public Uri Theme;

public static PublicTheme[]? GetAllThemes()
{
string url = "https://raw.githubusercontent.com/JiayiSoftware/jiayi-themes/main/all_themes.json";
string response = InternetManager.Client.GetStringAsync(url).Result;
var data = JsonConvert.DeserializeObject<PublicTheme[]>(response);

if (data != null)
{
return data;
}

Log.Write("Theme", "Failed to retrieve public themes", Log.LogLevel.Error);
return null;
}
}
17 changes: 17 additions & 0 deletions JiayiLauncher/Appearance/ThemeMetadata.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System.Collections.Generic;
using Newtonsoft.Json;

namespace JiayiLauncher.Appearance;

public class ThemeMetadata
{
[JsonProperty("author")]
public string Author;
[JsonProperty("tags")]
public List<string> Tags;
[JsonProperty("raw_tags")]
public List<string> RawTags;

public static readonly List<string> RAW_TAGS = ["Dark", "Light", "Animated"];

}
2 changes: 1 addition & 1 deletion JiayiLauncher/Modals/PrepareThemePublish.razor
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
private JiayiTextBox? _tagsTextBox;
private JiayiDropDown? _rawTagsDropDown;

private Metadata publicTheme = new()
private ThemeMetadata publicTheme = new()
{
Author = "",
Tags = new(),
Expand Down
1 change: 1 addition & 0 deletions JiayiLauncher/Pages/Extra/Themes.razor
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
@page "/Themes"
@using System.Net.Http
@using JiayiLauncher.Appearance
@using JiayiLauncher.Settings
@using JiayiLauncher.Shared.Components.Mods
@using JiayiLauncher.Utils
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
public EventCallback<bool> ChangeApplying { get; set; }
[Parameter]
public bool Applying { get; set; }

[CascadingParameter]
public IModalService ModalService { get; set; } = default!;

Expand Down
1 change: 1 addition & 0 deletions JiayiLauncher/Shared/ThemeController.razor
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
@using JiayiLauncher.Appearance
@using System.IO
@using JiayiLauncher.Settings
@using JiayiLauncher.Utils

@inject NavigationManager nav;

Expand Down
114 changes: 0 additions & 114 deletions JiayiLauncher/Utils/Theme.cs

This file was deleted.

0 comments on commit 0710a2f

Please sign in to comment.