Skip to content

Commit

Permalink
Quote shared text to fix its representation
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrey Maksimov committed Aug 21, 2023
1 parent 4e17b82 commit 9534a5a
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
2 changes: 1 addition & 1 deletion data/ui/extracted_page.blp
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}
3 changes: 3 additions & 0 deletions data/ui/share_row.blp
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
using Gtk 4.0;
using Adw 1;

template $ShareRow : ListBoxRow {
GestureClick row_click {
button: 1;
released => $_on_released();
}

activate => $_on_released();

Box box {
spacing: 6;
tooltip-text: _("Share via Pocket");
Expand Down
14 changes: 11 additions & 3 deletions frog/services/share_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion frog/widgets/share_row.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)

0 comments on commit 9534a5a

Please sign in to comment.