diff --git a/CHANGELOG b/CHANGELOG index 898a1b72..3f67cc6a 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -4,11 +4,12 @@ ## v0.5.5 (upcoming) -- All: Add russian translation. Thanks, @ViktorOn! ([#611](https://github.com/dynobo/normcap/pull/611)) -- All: Update spanish translation. Thanks, @haggen88! ([#614](https://github.com/dynobo/normcap/pull/614)) +- All: Add russian translation. Thanks, [@ViktorOn](https://github.com/ViktorOn)! ([#611](https://github.com/dynobo/normcap/pull/611)) +- All: Update spanish translation. Thanks, [@haggen88](https://github.com/haggen88)! ([#614](https://github.com/dynobo/normcap/pull/614)) - Linux: Add `xsel` as another clipboard handler. Try `--clipboard-handler xsel` if Normcap's result isn't copied to the clipboard correctly. - Linux: Fix clipboard on Gnome 46 + Wayland. ([#620](https://github.com/dynobo/normcap/pull/620)) +- Linux: Auto-remove screenshot file from pictures-directory on Wayland. Thanks, [@PavelDobCZ23](https://github.com/PavelDobCZ23)! ([#600](https://github.com/dynobo/normcap/issues/600)) ## v0.5.4 (2024-01-15) diff --git a/normcap/screengrab/handlers/dbus_portal.py b/normcap/screengrab/handlers/dbus_portal.py index 8fec1647..95e49d71 100644 --- a/normcap/screengrab/handlers/dbus_portal.py +++ b/normcap/screengrab/handlers/dbus_portal.py @@ -4,7 +4,7 @@ import random import re import sys -import os +from pathlib import Path from typing import Optional from urllib.parse import urlparse @@ -198,12 +198,18 @@ def _exception_triggered(uri: Exception) -> None: raise error uri = result[0] - image_path = urlparse(uri).path + parsed_uri = urlparse(uri) + + image_path = Path(parsed_uri.path) image = QtGui.QImage(image_path) + + # XDG Portal save the image file to the users xdg-pictures directory. To not let + # them pile up, we try to remove it: try: - os.remove(image_path) - except: - logger.warn(f"Failed to remove leftover screenshot file \"{image_path}\"!") + image_path.unlink() + except PermissionError: + logger.warning("Missing permission to remove screenshot file '%s'!", image_path) + return image