diff --git a/frog/services/screenshot_service.py b/frog/services/screenshot_service.py index d925f19..f3f4901 100644 --- a/frog/services/screenshot_service.py +++ b/frog/services/screenshot_service.py @@ -27,6 +27,7 @@ # authorization. import os from gettext import gettext as _ + from gi.repository import GObject, Gio, Xdp from frog.config import tessdata_config @@ -97,15 +98,18 @@ def take_screenshot_finish(self, source_object, res: Gio.Task, user_data): filename = self.portal.take_screenshot_finish(res) # Remove file:// from the path filename = filename[7:] - self.decode_image(lang, filename, copy) - - def decode_image( - self, lang: str, file: str | Image.Image, copy: bool = False - ) -> None: + self.decode_image(lang, filename, copy, True) + + def decode_image(self, + lang: str, + file: str | Image.Image, + copy: bool = False, + remove_source: bool = False, + ) -> None: # Check if `file` is a filepath and mark it for deletion - need_remove = False - if isinstance(file, str) and os.path.exists(file): - need_remove = True + if not isinstance(file, str) or not os.path.exists(file): + remove_source = False + print('Remove source set to False') print(f"Decoding with {lang} language.") extracted = None @@ -134,7 +138,8 @@ def decode_image( self.emit("error", "Failed to decode data.") finally: - if need_remove: + if remove_source: + print(f"Removing {file}") os.unlink(file) if extracted: @@ -144,6 +149,5 @@ def decode_image( else: self.emit("error", "No text found.") - def capture_cancelled(self, cancellable: Gio.Cancellable) -> None: self.emit("error", "Cancelled")