Skip to content

Commit

Permalink
Fix image extraction with Take a Screenshot
Browse files Browse the repository at this point in the history
This problem was caused by two separate issues:
1) The file names passed to `Image.Open` were escaped (e.g. " " -> "%20")
2) Frog tries to delete the file after text extraction but might not have the permissions to do so under a sandbox

Closes #192
  • Loading branch information
DaPigGuy committed May 2, 2024
1 parent 42996ea commit 96396a6
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions frog/services/screenshot_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import os
from gettext import gettext as _

from gi.repository import GObject, Gio, Xdp
from gi.repository import GObject, Gio, GLib, Xdp
from loguru import logger

from frog.config import tessdata_config
Expand Down Expand Up @@ -101,6 +101,7 @@ 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:]
filename = GLib.Uri.unescape_string(filename)
self.decode_image(lang, filename, copy, True)

def decode_image(self,
Expand Down Expand Up @@ -142,8 +143,11 @@ def decode_image(self,

finally:
if remove_source:
logger.debug(f"Removing {file}")
os.unlink(file)
try:
logger.debug(f"Removing {file}")
os.unlink(file)
except Exception as e:
logger.debug(f"Error deleting {file}: {e}")

if extracted:
logger.debug("Extracted successfully")
Expand Down

0 comments on commit 96396a6

Please sign in to comment.