dialect-app / dialect

A translation app for GNOME.
https://dialectapp.org/
GNU General Public License v3.0
603 stars 69 forks source link

Translate from primary selection not work #407

Open FusionGold opened 1 week ago

FusionGold commented 1 week ago

I am encountering an issue with Dialect, both when installed via AUR (dialect-git) and Flatpak on my Archlinux Gnome Wayland desktop environment. When running dialect -n from terminal and attempting to translate from the primary selection, the following error occurs:

Traceback (most recent call last):
  File "/app/share/dialect/dialect/window.py", line 532, in on_paste
    text = clipboard.read_text_finish(result)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
gi.repository.GLib.GError: g-io-error-quark: Cannot read from empty clipboard. (1)

Steps to Reproduce:

  1. Install Dialect via AUR (dialect-git) or Flatpak.
  2. In GNOME Text Editor, select a word and ensure wl-paste --primary can paste the content.
  3. With the flatpak version, run LANG=C flatpak run app.drey.Dialect -n
  4. Dialect window poped up with empty input and the above error message.
ivan-toriya commented 6 days ago

Experiencing the same issue. Dialect 2.5.0, installed via flatpak.

ivan-toriya commented 6 days ago

Identified another issue: clipboard history is only available for running apps. So, in order to translate the selection, I just run the flatpak run app.drey.Dialect --selection twice via custom shortcut.

rafaelmardojai commented 6 days ago

If you use the paste button in Dialect, do you get the same error?

FusionGold commented 5 days ago

Paste button works fine if I have contents in my clipboard.

rafaelmardojai commented 5 days ago

Right, @mufeedali confirmed me that he could reproduce the problem, but I can't in my Fedora setup.

@ivan-toriya could you give me info about your system? I can get the selection activating Dialect once.

ivan-toriya commented 5 days ago

@rafaelmardojai Debian 12.7, Gnome 43.9 (Wayland)

ivan-toriya commented 4 days ago

@rafaelmardojai btw, is it possible to run Dialect in background or in minimized mode?

rafaelmardojai commented 4 days ago

@ivan-toriya Nope.

rafaelmardojai commented 4 days ago

If you have wl-clipboard, as a workaround to this issue you can use what's suggested in this comment: https://github.com/dialect-app/dialect/issues/219#issuecomment-965583085.

FusionGold commented 4 days ago

@rafaelmardojai Thanks for the workaround hint.

zefr0x commented 1 day ago

Identified another issue: clipboard history is only available for running apps. So, in order to translate the selection, I just run the flatpak run app.drey.Dialect --selection twice via custom shortcut.

You need to focus on Dialect window while the second run is done.

It looks like it is a Wayland thing that prevents a window from reading the clipboard unless you are currently focusing on it.

https://wayland.app/protocols/primary-selection-unstable-v1

The result will differ depending on the timing of execution and the desktop environment behaviour (e.g. auto focus on new opened windows). That's why some might not be able to reproduce.


@rafaelmardojai can we wait for the user to focus on the window before reading the clipboard? This should solve the issue.

rafaelmardojai commented 1 day ago

@zefr0x Yes that's possible.

Implemented that in #408, could you test that PR?

FusionGold commented 1 day ago

@rafaelmardojai It seems that the primary selection can be correctly filled in with #408 . However, now whenever the -n option is used, a 'Translation failed' warning pops up first, and then the translation appears. Screenshot from 2024-11-02 01-46-24

rafaelmardojai commented 1 day ago

@FusionGold should be fixed now, could you test?

FusionGold commented 1 day ago

@rafaelmardojai Everything seems fine for me. Thanks for your hard work!