feat: add cache_dir argument to get_random_file()

This commit is contained in:
Kritagya Bhattarai (CalfMoon) 2024-10-07 20:28:21 +05:45
parent 49b496eb8e
commit d14a866394
4 changed files with 5 additions and 4 deletions

View File

@ -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()

View File

@ -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:

View File

@ -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:

View File

@ -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)