diff options
Diffstat (limited to 'src/caelestia')
| -rw-r--r-- | src/caelestia/subcommands/wallpaper.py | 2 | ||||
| -rw-r--r-- | src/caelestia/utils/wallpaper.py | 21 |
2 files changed, 13 insertions, 10 deletions
diff --git a/src/caelestia/subcommands/wallpaper.py b/src/caelestia/subcommands/wallpaper.py index 1440484..940dcb5 100644 --- a/src/caelestia/subcommands/wallpaper.py +++ b/src/caelestia/subcommands/wallpaper.py @@ -18,4 +18,4 @@ class Command: elif self.args.random: set_random(self.args) else: - print(get_wallpaper()) + print(get_wallpaper() or "No wallpaper set") 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: |