From 51520359293fa1089c73c0c701b8f79473e55393 Mon Sep 17 00:00:00 2001 From: carlton <64127681+notcarlton@users.noreply.github.com> Date: Sun, 7 Jan 2024 12:58:52 -0700 Subject: [PATCH] thingz --- JiayiLauncher/Appearance/PaletteGenerator.cs | 6 ++++++ JiayiLauncher/Settings/JiayiSettings.cs | 11 ++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/JiayiLauncher/Appearance/PaletteGenerator.cs b/JiayiLauncher/Appearance/PaletteGenerator.cs index b92d46e..285569c 100644 --- a/JiayiLauncher/Appearance/PaletteGenerator.cs +++ b/JiayiLauncher/Appearance/PaletteGenerator.cs @@ -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); diff --git a/JiayiLauncher/Settings/JiayiSettings.cs b/JiayiLauncher/Settings/JiayiSettings.cs index a1952d0..e93f03d 100644 --- a/JiayiLauncher/Settings/JiayiSettings.cs +++ b/JiayiLauncher/Settings/JiayiSettings.cs @@ -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\(\'(?[^']+)\'\)").Groups["url"].Value; @@ -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(); } }