From 9534a5a14d1c8a134a5d89df00a37341f916efcb Mon Sep 17 00:00:00 2001 From: Andrey Maksimov Date: Tue, 22 Aug 2023 00:39:27 +0300 Subject: [PATCH] Quote shared text to fix its representation --- data/ui/extracted_page.blp | 2 +- data/ui/share_row.blp | 3 +++ frog/services/share_service.py | 14 +++++++++++--- frog/widgets/share_row.py | 2 +- 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/data/ui/extracted_page.blp b/data/ui/extracted_page.blp index 8c3e428..4888a8f 100644 --- a/data/ui/extracted_page.blp +++ b/data/ui/extracted_page.blp @@ -155,4 +155,4 @@ menu primary_menu { menu grab_menu { item (_("Open image"), "app.open_image", "folder-open-symbolic") item (_("Paste from clipboard"), "app.paste_from_clipboard", "folder-open-symbolic") -} \ No newline at end of file +} diff --git a/data/ui/share_row.blp b/data/ui/share_row.blp index d00e76d..cc2484f 100644 --- a/data/ui/share_row.blp +++ b/data/ui/share_row.blp @@ -1,4 +1,5 @@ using Gtk 4.0; +using Adw 1; template $ShareRow : ListBoxRow { GestureClick row_click { @@ -6,6 +7,8 @@ template $ShareRow : ListBoxRow { released => $_on_released(); } + activate => $_on_released(); + Box box { spacing: 6; tooltip-text: _("Share via Pocket"); diff --git a/frog/services/share_service.py b/frog/services/share_service.py index 69f7b19..8f79888 100644 --- a/frog/services/share_service.py +++ b/frog/services/share_service.py @@ -26,6 +26,7 @@ # use or other dealings in this Software without prior written # authorization. from typing import List +from urllib.parse import quote from gi.repository import GObject, Gtk @@ -53,10 +54,17 @@ def providers() -> List[str]: ] def share(self, provider: str, text: str): + if not text: + return + + text = text.strip() if handler := getattr(self, f"get_link_{provider}"): - share_link: str = handler(text) - self.launcher.set_uri(share_link) - self.launcher.launch(callback=self._on_share) + try: + share_link: str = handler(quote(text)) + self.launcher.set_uri(share_link) + self.launcher.launch(callback=self._on_share) + except Exception as e: + print(f"ERROR: failed to share, error: {e}") def _on_share(self, _, result): self.emit("share", self.launcher.launch_finish(result)) diff --git a/frog/widgets/share_row.py b/frog/widgets/share_row.py index 23248fd..9cea2a9 100644 --- a/frog/widgets/share_row.py +++ b/frog/widgets/share_row.py @@ -50,7 +50,7 @@ def __init__(self, provider_name: str): self.image.set_from_icon_name(f"share-{self.provider_name.lower()}-symbolic") @Gtk.Template.Callback() - def _on_released(self, key, code, n, data): + def _on_released(self, *args): self.activate_action( "window.share", GLib.Variant.new_string(self.provider_name) )