feat(wallpaper_changer):add image hash, move to src

decode and leave: decrypt file instead of saving loaded image
add conf_dir instead of ~/Wallpaper
add decode_image function instead of decrypting directly
This commit is contained in:
Lucas Vivo committed 2026-11-13 10:51:47 +01:00
1 parent bd6ed049f7
commit 8aa679b405
1 file changed
+11 -10
@@ -7,6 +7,7 @@ from pathlib import Path
from PIL import Image, ImageDraw, ImageFont, ImageOps
from wallpaper_changer.encryption_manager import EncryptionManager
from wallpaper_changer.image_repository import ImageRepository
from wallpaper_changer.logging_utils import get_logger
from wallpaper_changer.monitor_manager import ScreenLayout
@@ -16,9 +17,10 @@ class WallpaperBuilder:
def build(
self,
images: Sequence[Mapping[str, Path | str]],
images: Sequence[Mapping[str, Path | str,str]],
layout: ScreenLayout,
private_key: str | Path,
conf_dir: str | Path,
search_terms: Sequence[str] | None = None,
exclude: Sequence[str] = (),
output_path: str | Path | None = None,
@@ -30,7 +32,7 @@ class WallpaperBuilder:
if not layout.monitors:
raise ValueError("Cannot build a wallpaper without monitor dimensions")
selected_images: list[Mapping[str, Path | str]] = []
selected_images: list[Mapping[str, Path | str,str]] = []
for index, monitor in enumerate(layout.monitors):
term = None
if search_terms:
@@ -64,11 +66,11 @@ class WallpaperBuilder:
source = self._open_image(
image_record,
private_key,
encryption_manager,
disable_encryption=disable_encryption,
)
if decode_and_leave:
source.save(Path(image_record["file"]).with_name(image_record["name"]))
dest = Path(image_record["file"]).with_name(image_record["name"])
encryption_manager.decrypt(image_record["file"], dest, private_key)
logger.debug(f"Leaving decrypted image on disk: {image_record['file']}")
centering_panorama = [(0,0),(1,0)]
@@ -93,14 +95,16 @@ class WallpaperBuilder:
stroke_width=1,
stroke_fill="black",
)
logger.info(f"Pasted image {image_record['name']} on monitor at x={monitor.x}, width={monitor.width}, height={monitor.height}")
destination = (
Path(output_path)
if output_path
else (Path.home() / "Wallpaper" / "current" / "wallpaper.jpg")
else (Path(conf_dir).expanduser().resolve() / "current" / "wallpaper.jpg")
)
destination.parent.mkdir(parents=True, exist_ok=True)
canvas.save(destination, format="JPEG", quality=95)
logger.info(f"Wallpaper built and saved to {destination}")
return destination
@staticmethod
@@ -140,9 +144,8 @@ class WallpaperBuilder:
@staticmethod
def _open_image(
image_record: Mapping[str, Path | str],
image_record: Mapping[str, Path | str, str],
private_key: str | Path,
encryption_manager: EncryptionManager | None,
disable_encryption: bool = False,
) -> Image.Image:
image_path = Path(image_record["file"])
@@ -153,9 +156,7 @@ class WallpaperBuilder:
raise ValueError(
f"Cannot open encrypted image while encryption is disabled: {image_path}"
)
if encryption_manager is None:
raise RuntimeError("Encryption manager is required to decrypt images")
decrypted = encryption_manager.decrypt(image_path, None, private_key)
decrypted = ImageRepository(image_path.parent).decode_image(image_path, None, private_key, image_record.get("hash"))
if decrypted is None:
raise ValueError(f"Could not decrypt image: {image_path}")
image_data = decrypted