Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix image extraction with Take a Screenshot #199

Merged
merged 1 commit into from
May 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading