Skip to content

Commit

Permalink
thingz
Browse files Browse the repository at this point in the history
  • Loading branch information
phasephasephase committed Jan 7, 2024
1 parent 561e17b commit 5152035
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
6 changes: 6 additions & 0 deletions JiayiLauncher/Appearance/PaletteGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ private enum ColorChannel

public static void CreatePalette()
{
if (!JiayiSettings.Instance.UseBackgroundImage) return;

var extension = Path.GetExtension(JiayiSettings.Instance.BackgroundImageUrl);
if (string.IsNullOrEmpty(extension)) return;
if (extension is ".mp4" or ".webm" or ".mov") return;

var themeRoot = Path.Combine(ThemeState.RootPath, "themes", JiayiSettings.Instance.Theme);
var imagePath = Path.Combine(themeRoot, $"background{Path.GetExtension(JiayiSettings.Instance.BackgroundImageUrl)}");
using var bitmap = new Bitmap(imagePath);
Expand Down
11 changes: 8 additions & 3 deletions JiayiLauncher/Settings/JiayiSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,13 +187,13 @@ public bool UseBackgroundImage
Instance.Save();
});

/* TODO: Remove this, as files will now be locally saved and uploaded to theme repo */
[Setting("Background image URL", "Appearance", "The URL of the image to use as the background. Videos are also supported.",
"UseBackgroundImage", "The URL should be a link to an image or video on the internet. A path to a local image will not work.")]
// [Setting("Background image URL", "Appearance", "The URL of the image to use as the background. Videos are also supported.",
// "UseBackgroundImage", "The URL should be a link to an image or video on the internet. A path to a local image will not work.")]
public string BackgroundImageUrl
{
get
{
if (Instance == null) return string.Empty;
if (Instance.UseBackgroundImage)
return Regex.Match(_themeState.ThemeStyles.GetProperty(":root", "--background-image")?.Value ?? "",
@"url\(\'(?<url>[^']+)\'\)").Groups["url"].Value;
Expand All @@ -202,8 +202,13 @@ public string BackgroundImageUrl
}
set
{
// TODO: better fix for the launcher not loading backgrounds with the same extension
var needRefresh = Path.GetExtension(BackgroundImageUrl) == Path.GetExtension(value);

value = value.Replace("\\", "/");
_themeState.UpdateTheme("--background-image", $"url('{value}')");

if (needRefresh && MainLayout.Instance != null) MainLayout.Instance.Reload();
}
}

Expand Down

0 comments on commit 5152035

Please sign in to comment.