-
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b4de2b4
commit 0710a2f
Showing
8 changed files
with
123 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"]; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.