From 9da9d7bb1b254d5d94265bda5e052ca4feee1b9a Mon Sep 17 00:00:00 2001 From: 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> Date: Fri, 13 Jun 2025 14:50:25 +1000 Subject: wallpaper: fix when no wall --- src/caelestia/utils/wallpaper.py | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'src/caelestia/utils') diff --git a/src/caelestia/utils/wallpaper.py b/src/caelestia/utils/wallpaper.py index 1146c73..0a666be 100644 --- a/src/caelestia/utils/wallpaper.py +++ b/src/caelestia/utils/wallpaper.py @@ -31,7 +31,10 @@ def check_wall(wall: Path, filter_size: tuple[int, int], threshold: float) -> bo def get_wallpaper() -> str: - return wallpaper_path_path.read_text() + try: + return wallpaper_path_path.read_text() + except IOError: + return None def get_wallpapers(args: Namespace) -> list[Path]: @@ -71,17 +74,17 @@ def get_thumb(wall: Path, cache: Path) -> Path: def get_smart_mode(wall: Path, cache: Path) -> str: mode_cache = cache / "mode.txt" - if mode_cache.exists(): + try: return mode_cache.read_text() + except IOError: + with Image.open(get_thumb(wall, cache)) as img: + img.thumbnail((1, 1), Image.LANCZOS) + mode = "light" if Hct.from_int(argb_from_rgb(*img.getpixel((0, 0)))).tone > 60 else "dark" - with Image.open(get_thumb(wall, cache)) as img: - img.thumbnail((1, 1), Image.LANCZOS) - mode = "light" if Hct.from_int(argb_from_rgb(*img.getpixel((0, 0)))).tone > 60 else "dark" + mode_cache.parent.mkdir(parents=True, exist_ok=True) + mode_cache.write_text(mode) - mode_cache.parent.mkdir(parents=True, exist_ok=True) - mode_cache.write_text(mode) - - return mode + return mode def get_colours_for_wall(wall: Path | str, no_smart: bool) -> None: -- cgit v1.2.3-freya