From d14a8663944ad6f41d40c0872b0358385eb2e554 Mon Sep 17 00:00:00 2001 From: "Kritagya Bhattarai (CalfMoon)" Date: Mon, 7 Oct 2024 20:28:21 +0545 Subject: [PATCH] feat: add cache_dir argument to get_random_file() --- waypaper/__main__.py | 3 +-- waypaper/app.py | 2 +- waypaper/common.py | 2 ++ waypaper/config.py | 2 +- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/waypaper/__main__.py b/waypaper/__main__.py index 8cfde64..0474d9d 100644 --- a/waypaper/__main__.py +++ b/waypaper/__main__.py @@ -69,7 +69,7 @@ def run(): for wallpaper, monitor in zip(cf.wallpapers, cf.monitors): if args.random: - wallpaper_str = get_random_file(cf.backend, str(cf.image_folder), cf.include_subfolders, cf.show_hidden) + wallpaper_str = get_random_file(cf.backend, str(cf.image_folder), cf.include_subfolders, cf.cache_dir, cf.show_hidden) if wallpaper_str: cf.select_wallpaper(wallpaper_str) cf.save() @@ -112,4 +112,3 @@ def run(): if __name__ == "__main__": run() - diff --git a/waypaper/app.py b/waypaper/app.py index ce35801..ca83a76 100644 --- a/waypaper/app.py +++ b/waypaper/app.py @@ -496,7 +496,7 @@ class App(Gtk.Window): def set_random_wallpaper(self) -> None: """Choose a random image and set it as the wallpaper""" self.cf.backend = self.backend_option_combo.get_active_text() - new_wallpaper = get_random_file(self.cf.backend, str(self.cf.image_folder), self.cf.include_subfolders) + new_wallpaper = get_random_file(self.cf.backend, str(self.cf.image_folder), self.cf.cache_dir, self.cf.include_subfolders) if new_wallpaper: self.cf.select_wallpaper(new_wallpaper) else: diff --git a/waypaper/common.py b/waypaper/common.py index e79d86a..9166fe3 100644 --- a/waypaper/common.py +++ b/waypaper/common.py @@ -5,6 +5,7 @@ import re import random import shutil import subprocess +from pathlib import Path from waypaper.options import IMAGE_EXTENSIONS, BACKEND_OPTIONS from typing import List @@ -58,6 +59,7 @@ def get_image_paths(backend: str, def get_random_file(backend: str, folder: str, include_subfolders: bool, + cache_dir: Path, include_hidden: bool = False) -> str | None: """Pick a random file from the folder""" try: diff --git a/waypaper/config.py b/waypaper/config.py index da94945..c09851f 100644 --- a/waypaper/config.py +++ b/waypaper/config.py @@ -49,7 +49,7 @@ class Config: # Create config and cache folders: self.config_dir.mkdir(parents=True, exist_ok=True) - self.cache_dir.mkdir(parents=True,exist_ok=True) + self.cache_dir.mkdir(parents=True, exist_ok=True) self.state_dir.mkdir(parents=True, exist_ok=True)