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

[Linux, FlatPak] Permissions need workaround with timeout and helper window #320

Open
dynobo opened this issue Nov 20, 2022 · 14 comments
Open
Assignees
Labels
enhancement New feature or request requires upstream change A change in a dependen project is necessary before this issue can be solved

Comments

@dynobo
Copy link
Owner

dynobo commented Nov 20, 2022

System:

{  'cli_args': '/app/bin/normcap -v debug',
   'config_directory': PosixPath('/home/REDACTED/.var/app/com.github.dynobo.normcap/config/normcap'),
   'desktop_environment': <DesktopEnvironment.GNOME: 1>,
   'display_manager_is_wayland': True,
   'envs': {  'LD_LIBRARY_PATH': '',
              'TESSDATA_PREFIX': '/app/share',
              'TESSERACT_CMD': None,
              'TESSERACT_VERSION': None},
   'gnome_version': None,
   'is_flatpak_package': True,
   'is_prebuild_package': None,
   'normcap_version': '0.3.14',
   'platform': 'linux',
   'pyside6_version': '6.4.0.1',
   'qt_library_path': '/usr/share/runtime/lib/plugins, '
                      '/app/lib/python3.9/site-packages/PySide6/Qt/plugins, '
                      '/usr/bin',
   'qt_version': '6.4.0',
   'screens': {  0: Screen(is_primary=True, device_pixel_ratio=1.0, geometry=Rect(left=0, top=0, right=1920, bottom=1080), index=0, screenshot=None)},
   'tessdata_path': '/home/REDACTED/.var/app/com.github.dynobo.normcap/config/normcap/tessdata'}

Variables:

                  '__builtins__': <module 'builtins' (built-in)>,
                  '__cached__': None,
                  '__doc__': None,
                  '__file__': '/app/bin/normcap',
                  '__loader__': <_frozen_importlib_external.SourceFileLoader object at 0x7f8b1c1e5c10>,
                  '__name__': '__main__',
                  '__package__': None,
                  '__spec__': None,
                  'main': <function main at 0x7f8b1c0a53a0>,
                  're': <module 're' from '/usr/lib/python3.9/re.py'>,
                  'sys': <module 'sys' (built-in)>},
   '__init__': {  '__class__': <class 'normcap.gui.tray.SystemTray'>,
                  'args': {...},
                  'parent': <PySide6.QtWidgets.QApplication(0x5591af3c10b0) at 0x7f8b15187580>,
                  'self': 'REDACTED'},
   '_read_some_data': {'self': 'REDACTED', 'timeout': 14.999996797996573},
   '_receive': {  'deadline': 17350.304494858996,
                  'msg': None,
                  'self': 'REDACTED'},
   '_update_screenshots': {  'capture': <function capture at 0x7f8b10dcfe50>,
                             'self': 'REDACTED'},
   'capture': {},
   'grab_full_desktop': {  'connection': <jeepney.io.blocking.DBusConnection object at 0x7f8b1518b700>,
                           'handle': '/org/freedesktop/portal/desktop/request/1_1460/normcap_fgjajpag',
                           'image': None,
                           'msg': Message(Header(<Endianness.little: 1>, <MessageType.method_call: 1>, <MessageFlag.0: 0>, 1, 88, -1, fields={<HeaderFields.path: 1>: '/org/freedesktop/portal/desktop', <HeaderFields.destination: 6>: 'org.freedesktop.portal.Desktop', <HeaderFields.interface: 2>: 'org.freedesktop.portal.Screenshot', <HeaderFields.member: 3>: 'Screenshot', <HeaderFields.signature: 8>: 'sa{sv}'}), ('', {'handle_token': ('s', 'normcap_fgjajpag'), 'interactive': ('b', False)})),
                           'pseudo_unique_str': 'fgjajpag',
                           'response_rule': <jeepney.bus_messages.MatchRule object at 0x7f8b10dce250>,
                           'responses': deque([], maxlen=1),
                           'sender_name': '1_1460',
                           'token': 'normcap_fgjajpag'},
   'main': {  'app': <PySide6.QtWidgets.QApplication(0x5591af3c10b0) at 0x7f8b15187580>,
              'args': Namespace(color=None, language=None, mode=None, notification=None, tray=None, update=None, reset=False, verbosity='debug', version=False),
              'logger': <Logger normcap (DEBUG)>},
   'receive': {'self': 'REDACTED', 'timeout': 14.999998282997694},
   'recv_messages': {'self': 'REDACTED', 'timeout': 14.999998282997694},
   'recv_until_filtered': {  'deadline': 17350.304492661,
                             'queue': deque([], maxlen=1),
                             'self': 'REDACTED',
                             'timeout': 15}}

Exception:

  TimeoutError

Traceback:

  File "/app/bin/normcap", line 8, in <module>
    sys.exit(main())
  File "/app/lib/python3.9/site-packages/normcap/app.py", line 58, in main
    tray = SystemTray(app, vars(args))
  File "/app/lib/python3.9/site-packages/normcap/gui/tray.py", line 72, in __init__
    self._update_screenshots()
  File "/app/lib/python3.9/site-packages/normcap/gui/tray.py", line 164, in _update_screenshots
    screens = capture()
  File "/app/lib/python3.9/site-packages/normcap/screengrab/dbus_portal.py", line 91, in capture
    full_image = grab_full_desktop()
  File "/app/lib/python3.9/site-packages/normcap/screengrab/dbus_portal.py", line 68, in grab_full_desktop
    response = connection.recv_until_filtered(responses, timeout=15)
  File "/app/lib/python3.9/site-packages/jeepney/io/blocking.py", line 242, in recv_until_filtered
    self.recv_messages(timeout=deadline_to_timeout(deadline))
  File "/app/lib/python3.9/site-packages/jeepney/io/blocking.py", line 172, in recv_messages
    msg = self.receive(timeout=timeout)
  File "/app/lib/python3.9/site-packages/jeepney/io/blocking.py", line 165, in receive
    return self._receive(timeout_to_deadline(timeout))
  File "/app/lib/python3.9/site-packages/jeepney/io/blocking.py", line 102, in _receive
    b, fds = self._read_some_data(timeout=deadline_to_timeout(deadline))
  File "/app/lib/python3.9/site-packages/jeepney/io/blocking.py", line 113, in _read_some_data
    raise TimeoutError
@dynobo
Copy link
Owner Author

dynobo commented Nov 20, 2022

I noticed that behavior for NormCap v0.3.14+, after my Manjaro Linux received the new Gnome version.

First ideas about possible causes:

  • Changes in the org.freedesktop.portal protocol, specifically in xdg-desktop-portal.
  • Changes regarding permissions to access org.freedesktop.portal

I think it might be a good idea to wait a 1-2 weeks to see, if something upstream is broken.

If you experience the same issue, please leave a comment with the Linux distribution and Desktop Environment you are running! 🕵️

@dynobo dynobo added the bug Something isn't working label Nov 20, 2022
@dynobo dynobo pinned this issue Nov 20, 2022
@proninyaroslav
Copy link

Same here, Fedora 37, GNOME 43.1.

@Renner0E
Copy link

Same issue here on KDE Plasma 5.26.4 with Wayland Flatpak, AppImage on Arch Linux
full log
Works on Plasma X11

@dynobo
Copy link
Owner Author

dynobo commented Dec 24, 2022

A month later, I still have this issue on a fully updated Arch. I start looking into it, now... Stay tuned!

@dynobo
Copy link
Owner Author

dynobo commented Dec 31, 2022

Something I discovered: It seems like other applications have the same issue. E.g. the Flatpak version of the screenshot tool org.flameshot.Flameshot hangs, too, while the native version is working flawless for me. Can anyone with the same issue confirm this?

@dynobo
Copy link
Owner Author

dynobo commented Jan 1, 2023

Might be related to flameshot-org/flameshot#2880, as flameshot also uses the xdg-portal for taking screenshots.

@dynobo
Copy link
Owner Author

dynobo commented Jan 14, 2023

Update: I found the underlying issue, and I am working on a fix/workaround right now!

Why does NormCap hang?

The source problem is, that the "permission for screenshot"-dialog, which asks the user to give NormCap permission to access org.freedesktop.portal.Screenshot doesn't show @up. This leaves NormCap waiting for a response with the screenshot URI, which will never come because NormCap doesn't (yet) have permission to receive it.

Why does the permission dialog doesn't show up to give the user the possibility to provide the permission?

That was really hard to find out: Two requirements are necessary for the permission dialog to show up:

  1. org.freedesktop.portal.Screenshot has to be called with interactive=True. In NormCap, this flag was set to False, as it prevents this intermediate dialog many users are annoyed about (see [Linux, Wayland] Avoid intermediate "share" dialog on opening NormCap #264)
  2. The application that does the call to org.freedesktop.portal.Screenshot needs to have a visible Window. NormCap, with its design to stay out of the way of the user, doesn't have a window by the time the screenshot is requested.

In a test, I was able to confirm, that fulfilling those two requirements will lead to the "permission for screenshot"-dialog appearing. Luckily, those two requirements are only necessary for the initial first request! After the permissions got granted once, it's possible to again request screenshots with interactive=False and without any window again.

How will the solution/workaround look like?

Current idea:
On every start, NormCap will try to request a screenshot in its normal way at first (interactive=True, no window), but if it doesn't receive a response within e.g. 3 seconds, a small dialog window pops up (the necessary window) and a request with interactive=False is made. This should trigger the "permission for screenshot"-dialog, and, if the user confirms, the intermediate dialog from #264. This has to be done at least once (I don't know if the permissions are preserved across updates).

I understand that this will not be a perfect solution from UX point of view, but it's my best idea right now and at least should make it usable again.

@dynobo
Copy link
Owner Author

dynobo commented Jan 21, 2023

While I'm still in to process of releasing the workaround, I opened an issue @ xdg-desktop-portal to (hopefully) clarify the underlying issue: flatpak/xdg-desktop-portal#950

@dynobo
Copy link
Owner Author

dynobo commented Jan 30, 2023

The main issue should be fixed with NormCap v0.4.0.

But the "solution" (as outlined above) is more like a workaround for missing functionality upstream in xdg-portal. I am going to leave this issue open as a reminder to look into this issue again, once there is some movement in xdg-desktop-portal.

@dynobo dynobo unpinned this issue Jan 30, 2023
@dynobo dynobo added the requires upstream change A change in a dependen project is necessary before this issue can be solved label Jan 30, 2023
@dynobo dynobo changed the title [Linux] FlatPak crashs with "TimeoutError" on Gnome 43 [Linux] FlatPak permissions require workaround with a timeout and a helper window Jan 30, 2023
@dynobo dynobo changed the title [Linux] FlatPak permissions require workaround with a timeout and a helper window [Linux, FlatPak] Permissions need workaround with timeout and helper window Jan 30, 2023
@dynobo dynobo added enhancement New feature or request and removed bug Something isn't working labels Jan 30, 2023
@flaphoschi
Copy link

Hello!
I've installed Normcap 0.4.4 via Flathub on GNOME 44.3 (Archlinux). I'm afraid the fix from above doesn't work:

Aug 26 20:11:57 cupcake systemd[924]: Started app-flatpak-com.github.dynobo.normcap-12801.scope.
Aug 26 20:11:58 cupcake xdg-desktop-por[1561]: Failed to show access dialog: GDBus.Error:org.freedesktop.DBus.Error.AccessDenied: Only the focused app is allowed to show a system access dialog
Aug 26 20:12:05 cupcake org.gnome.Software.desktop[12442]: 20:12:05 - ERROR   - normcap.screengrab.dbus_portal:88 - No response from xdg-portal within 7s!

Guess: Flatpak (xdg-desktop-portal) has an own timeout and it is violated?

@dynobo
Copy link
Owner Author

dynobo commented Aug 28, 2023

Hi @flaphoschi,

Thanks for you report! Could you please try to run NormCap in Terminal via

flatpak run --command=normcap com.github.dynobo.normcap -v debug

and share the complete debug log output?

That would help me to diagnose the issue and, most importantly, it would tell me if the recently added workaround is applied at all.

@flaphoschi
Copy link

Hi!

I installed NormCap again on another laptop with Archlinux:

First start from GNOME-Shell:

Aug 31 13:36:01 lap-lnx-pew systemd[1671]: Started Application launched by gnome-shell.
Aug 31 13:36:01 lap-lnx-pew systemd[1671]: Started app-flatpak-com.github.dynobo.normcap-140999.scope.
Aug 31 13:36:02 lap-lnx-pew xdg-desktop-por[2341]: Failed to show access dialog: GDBus.Error:org.freedesktop.DBus.Error.AccessDenied: Only the focused app is allowed to show a system access dialog
Aug 31 13:36:06 lap-lnx-pew systemd[1671]: Started Application launched by gnome-shell.
Aug 31 13:36:06 lap-lnx-pew dbus-daemon[1694]: [session uid=1000 pid=1694] Activating via systemd: service name='org.gnome.Terminal' unit='gnome-terminal-server.service' requested by ':1.1644' (uid=1000 pid=141027 comm="/usr/bin/gnome-ter>
Aug 31 13:36:06 lap-lnx-pew systemd[1671]: Starting GNOME Terminal Server...
Aug 31 13:36:06 lap-lnx-pew dbus-daemon[1694]: [session uid=1000 pid=1694] Successfully activated service 'org.gnome.Terminal'
Aug 31 13:36:06 lap-lnx-pew systemd[1671]: Started GNOME Terminal Server.
Aug 31 13:36:06 lap-lnx-pew gnome-shell[1762]: meta_window_set_stack_position_no_sync: assertion 'window->stack_position >= 0' failed
Aug 31 13:36:06 lap-lnx-pew systemd[1671]: Started VTE child process 141053 launched by gnome-terminal-server process 141034.
Aug 31 13:36:09 lap-lnx-pew com.github.dynobo.normcap.desktop[141017]: 13:36:09 - ERROR   - normcap.screengrab.dbus_portal:88 - No response from xdg-portal within 7s!
Aug 31 13:36:09 lap-lnx-pew com.github.dynobo.normcap.desktop[141017]: 13:36:09 - WARNING - normcap.screengrab.dbus_portal:199 - Timeout when taking screenshot!
Aug 31 13:36:17 lap-lnx-pew com.github.dynobo.normcap.desktop[141017]: 13:36:17 - ERROR   - normcap.screengrab.dbus_portal:88 - No response from xdg-portal within 7s!
Aug 31 13:36:35 lap-lnx-pew xdg-desktop-por[2341]: Failed to show access dialog: Timeout was reached
Aug 31 13:36:49 lap-lnx-pew dbus-daemon[1694]: [session uid=1000 pid=1694] Activating via systemd: service name='org.freedesktop.Tracker3.Miner.Extract' unit='tracker-extract-3.service' requested by ':1.156' (uid=1000 pid=7931 comm="/usr/>
Aug 31 13:36:49 lap-lnx-pew systemd[1671]: Starting Tracker metadata extractor...
Aug 31 13:36:49 lap-lnx-pew dbus-daemon[1694]: [session uid=1000 pid=1694] Successfully activated service 'org.freedesktop.Tracker3.Miner.Extract'
Aug 31 13:36:49 lap-lnx-pew systemd[1671]: Started Tracker metadata extractor.
Aug 31 13:36:57 lap-lnx-pew gnome-shell[1762]: Window manager warning: Ping serial 92086387 was reused for window W580, previous use was for window W579.
Aug 31 13:37:14 lap-lnx-pew dbus-daemon[1694]: [session uid=1000 pid=1694] Activating via systemd: service name='org.freedesktop.Tracker3.Miner.Extract' unit='tracker-extract-3.service' requested by ':1.156' (uid=1000 pid=7931 comm="/usr/>
Aug 31 13:37:14 lap-lnx-pew systemd[1671]: Starting Tracker metadata extractor...
Aug 31 13:37:15 lap-lnx-pew dbus-daemon[1694]: [session uid=1000 pid=1694] Successfully activated service 'org.freedesktop.Tracker3.Miner.Extract'

To my surprise several seconds later a permission for screenshots was requests. I granted the permission! Also I recognized a small window in the background:

Timeout when taking a screenshot!

Retrying with different settings...

Please grant NormCap permission to take
screenshots, if you get asked for it in a pop-up!

(You should not see this Window on the next start!)

So I assumed NormCap is useable after the next start but nothing happened and I saw this in the logs:

Aug 31 13:42:14 lap-lnx-pew systemd[1671]: Started Application launched by gnome-shell.
Aug 31 13:42:14 lap-lnx-pew rtkit-daemon[1165]: Supervising 6 threads of 3 processes of 1 users.
Aug 31 13:42:14 lap-lnx-pew rtkit-daemon[1165]: Supervising 6 threads of 3 processes of 1 users.
Aug 31 13:42:14 lap-lnx-pew rtkit-daemon[1165]: Supervising 6 threads of 3 processes of 1 users.
Aug 31 13:42:14 lap-lnx-pew rtkit-daemon[1165]: Supervising 6 threads of 3 processes of 1 users.
Aug 31 13:42:14 lap-lnx-pew rtkit-daemon[1165]: Supervising 6 threads of 3 processes of 1 users.
Aug 31 13:42:14 lap-lnx-pew rtkit-daemon[1165]: Supervising 6 threads of 3 processes of 1 users.
Aug 31 13:42:14 lap-lnx-pew rtkit-daemon[1165]: Successfully made thread 142450 of process 142305 owned by '1000' RT at priority 10.
Aug 31 13:42:14 lap-lnx-pew rtkit-daemon[1165]: Supervising 7 threads of 4 processes of 1 users.
Aug 31 13:42:14 lap-lnx-pew gnome-shell[1762]: meta_window_set_stack_position_no_sync: assertion 'window->stack_position >= 0' failed
Aug 31 13:42:14 lap-lnx-pew com.github.dynobo.normcap.desktop[141017]: 13:42:14 - ERROR   - normcap.screengrab.dbus_portal:88 - No response from xdg-portal within 7s!

Withing GNOME-Settings -> Apps -> NormCap only the Network Access Permission seems used.

So I've done what you posted and used flatpak run --command=normcap com.github.dynobo.normcap -v debug

[peter@lap-lnx-pew ~]$ flatpak run --command=normcap com.github.dynobo.normcap -v debug
13:51:38 - INFO    - normcap:30 - Start NormCap v0.4.4
13:51:38 - DEBUG   - normcap:81 - Set XCURSOR_SIZE=24
13:51:38 - DEBUG   - normcap:86 - Set QT_QPA_PLATFORM=wayland
13:51:38 - DEBUG   - normcap.gui.tray:60 - System info:
{'cli_args': '/app/bin/normcap -v debug', 'is_briefcase_package': False, 'is_flatpak_package': True, 'platform': 'linux', 'pyside6_version': '6.5.1', 'qt_version': '6.5.1', 'qt_library_path': '/usr/share/runtime/lib/plugins, /app/lib/python3.10/site-packages/PySide6/Qt/plugins, /usr/bin', 'config_directory': PosixPath('/home/peter/.var/app/com.github.dynobo.normcap/config/normcap'), 'normcap_version': '0.4.4', 'ressources_path': PosixPath('/app/lib/python3.10/site-packages/normcap/resources'), 'tesseract_path': PosixPath('/app/bin/tesseract'), 'tessdata_path': PosixPath('/home/peter/.var/app/com.github.dynobo.normcap/config/normcap/tessdata'), 'envs': {'TESSDATA_PREFIX': '/app/share', 'LD_LIBRARY_PATH': ''}, 'desktop_environment': <DesktopEnvironment.GNOME: 1>, 'display_manager_is_wayland': True, 'screens': [Screen(is_primary=True, device_pixel_ratio=1.0, rect=Rect(left=0, top=0, right=1920, bottom=1080), index=0, screenshot=None)]}
13:51:38 - DEBUG   - normcap.gui.tray:68 - Another instance is already running. Sending capture signal.
13:51:38 - INFO    - normcap.gui.tray:506 - Exit normcap (NormCap already running)
13:51:38 - DEBUG   - normcap.gui.tray:507 - Debug images saved in /tmp/normcap

Already running? Yep. I found it in the process list and terminated it.

[peter@lap-lnx-pew ~]$ flatpak run --command=normcap com.github.dynobo.normcap -v debug
13:56:20 - INFO    - normcap:30 - Start NormCap v0.4.4
13:56:20 - DEBUG   - normcap:81 - Set XCURSOR_SIZE=24
13:56:20 - DEBUG   - normcap:86 - Set QT_QPA_PLATFORM=wayland
13:56:20 - DEBUG   - normcap.gui.tray:60 - System info:
{'cli_args': '/app/bin/normcap -v debug', 'is_briefcase_package': False, 'is_flatpak_package': True, 'platform': 'linux', 'pyside6_version': '6.5.1', 'qt_version': '6.5.1', 'qt_library_path': '/usr/share/runtime/lib/plugins, /app/lib/python3.10/site-packages/PySide6/Qt/plugins, /usr/bin', 'config_directory': PosixPath('/home/peter/.var/app/com.github.dynobo.normcap/config/normcap'), 'normcap_version': '0.4.4', 'ressources_path': PosixPath('/app/lib/python3.10/site-packages/normcap/resources'), 'tesseract_path': PosixPath('/app/bin/tesseract'), 'tessdata_path': PosixPath('/home/peter/.var/app/com.github.dynobo.normcap/config/normcap/tessdata'), 'envs': {'TESSDATA_PREFIX': '/app/share', 'LD_LIBRARY_PATH': ''}, 'desktop_environment': <DesktopEnvironment.GNOME: 1>, 'display_manager_is_wayland': True, 'screens': [Screen(is_primary=True, device_pixel_ratio=1.0, rect=Rect(left=0, top=0, right=1920, bottom=1080), index=0, screenshot=None)]}
13:56:20 - DEBUG   - normcap.gui.tray:342 - Listen on local socket v0.4.4-normcap.
13:56:20 - DEBUG   - normcap.gui.settings:128 - Skip update of non existing setting (cli_mode: False)
13:56:20 - DEBUG   - normcap.gui.settings:128 - Skip update of non existing setting (background_mode: False)
13:56:20 - DEBUG   - normcap.screengrab:37 - Select capture method DBUS portal
13:56:20 - DEBUG   - normcap.screengrab.dbus_portal:196 - Request screenshot with interactive=False
13:56:20 - DEBUG   - normcap.screengrab.dbus_portal:79 - Request accepted
13:56:21 - DEBUG   - normcap.ocr.tesseract:23 - Tesseract command output:
List of available languages in "/home/peter/.var/app/com.github.dynobo.normcap/config/normcap/tessdata/" (1):
eng
13:56:21 - DEBUG   - normcap.screengrab.dbus_portal:106 - Parse response
13:56:21 - DEBUG   - normcap.screengrab.utils:26 - Virtual geometry width: 1920
13:56:21 - DEBUG   - normcap.screengrab.utils:27 - Image width: 1920
13:56:21 - DEBUG   - normcap.screengrab.utils:28 - Resize ratio: 1.0
13:56:21 - DEBUG   - normcap.gui.utils:22 - Save debug image as /tmp/normcap/1693482981.5301783_raw_screen0.png
13:56:21 - DEBUG   - normcap.gui.window:131 - Create window for screen 0
13:56:21 - DEBUG   - normcap.gui.window:193 - Set window of screen 0 to fullscreen
13:56:21 - DEBUG   - normcap:213 - [QT] qtwarningmsg - qobject::connect: no such signal qplatformnativeinterface::systemtraywindowchanged(qscreen*)
13:56:21 - DEBUG   - normcap.gui.window:184 - Move window 0 to (left=0, top=0, right=1920, bottom=1080)
13:56:21 - WARNING - normcap.gui.window:67 - Invalid dbus interface on Gnome
13:56:24 - DEBUG   - normcap.gui.tray:294 - Hide 1 window
13:56:24 - INFO    - normcap.gui.tray:197 - Crop image to region (48, 162, 322, 213)
13:56:24 - DEBUG   - normcap.gui.utils:22 - Save debug image as /tmp/normcap/1693482984.4757063_cropped.png
13:56:24 - DEBUG   - normcap.gui.tray:222 - Start OCR
13:56:24 - DEBUG   - normcap.ocr.enhance:76 - Scale image x3.2
13:56:24 - DEBUG   - normcap.ocr.enhance:54 - Pad image by 80px
13:56:24 - DEBUG   - normcap.ocr.recognize:35 - Run Tesseract on image of size (1035, 323) with args:
TessArgs(tessdata_path=PosixPath('/home/peter/.var/app/com.github.dynobo.normcap/config/normcap/tessdata'), lang='eng', oem=<OEM.DEFAULT: 3>, psm=<PSM.AUTO_OSD: 1>)
13:56:24 - DEBUG   - normcap.ocr.tesseract:23 - Tesseract command output:

13:56:24 - DEBUG   - normcap.ocr.recognize:44 - OCR result:
OcrResult(tess_args=TessArgs(tessdata_path=PosixPath('/home/peter/.var/app/com.github.dynobo.normcap/config/normcap/tessdata'), lang='eng', oem=<OEM.DEFAULT: 3>, psm=<PSM.AUTO_OSD: 1>), words=[{'level': 5, 'page_num': 1, 'block_num': 1, 'par_num': 1, 'line_num': 1, 'word_num': 1, 'left': 108, 'top': 117, 'width': 123, 'height': 34, 'conf': 89.867867, 'text': 'hello'}, {'level': 5, 'page_num': 1, 'block_num': 1, 'par_num': 1, 'line_num': 1, 'word_num': 2, 'left': 258, 'top': 117, 'width': 146, 'height': 43, 'conf': 95.737907, 'text': 'world,'}, {'level': 5, 'page_num': 1, 'block_num': 1, 'par_num': 1, 'line_num': 1, 'word_num': 3, 'left': 440, 'top': 118, 'width': 97, 'height': 33, 'conf': 96.653618, 'text': 'this'}, {'level': 5, 'page_num': 1, 'block_num': 1, 'par_num': 1, 'line_num': 1, 'word_num': 4, 'left': 568, 'top': 118, 'width': 46, 'height': 33, 'conf': 96.030113, 'text': 'is'}, {'level': 5, 'page_num': 1, 'block_num': 1, 'par_num': 1, 'line_num': 1, 'word_num': 5, 'left': 644, 'top': 127, 'width': 21, 'height': 24, 'conf': 96.371277, 'text': 'a'}, {'level': 5, 'page_num': 1, 'block_num': 1, 'par_num': 1, 'line_num': 1, 'word_num': 6, 'left': 695, 'top': 121, 'width': 98, 'height': 30, 'conf': 95.670349, 'text': 'text'}], image=<PySide6.QtGui.QImage(QSize(1035, 323),format=QImage::Format_RGB32,depth=32,devicePixelRatio=1,bytesPerLine=4140,sizeInBytes=1337220) at 0x7f20cd3019c0>, magic_scores={}, parsed='')
13:56:24 - INFO    - normcap.ocr.magics.email_magic:33 - 0 emails found 
13:56:24 - DEBUG   - normcap.ocr.magics.email_magic:41 - 0/22 (0.0) chars in emails
13:56:24 - INFO    - normcap.ocr.magics.url_magic:55 - 0 URLs found 
13:56:24 - DEBUG   - normcap.ocr.magics.url_magic:63 - 0/27 (0.0) chars in urls
13:56:24 - DEBUG   - normcap.ocr.magics.magic:70 - Magic scores:
{'SingleLineMagic': 50, 'MultiLineMagic': 0, 'ParagraphMagic': 0.0, 'EmailMagic': 0.0, 'UrlMagic': 0.0}
13:56:24 - DEBUG   - normcap.ocr.recognize:48 - Parsed text:
hello world, this is a text
13:56:24 - DEBUG   - normcap.gui.utils:22 - Save debug image as /tmp/normcap/1693482984.6475632_enhanced.png
13:56:24 - INFO    - normcap.gui.tray:240 - Text from OCR:
hello world, this is a text
13:56:24 - DEBUG   - normcap.clipboard.linux:38 - Select clipboard method wl-copy
13:56:24 - DEBUG   - normcap.gui.tray:270 - Copy text to clipboard
13:56:24 - DEBUG   - normcap.gui.notifier:111 - Send notification via QT
13:56:30 - INFO    - normcap.gui.tray:506 - Exit normcap (notification sent delaying exit)
13:56:30 - DEBUG   - normcap.gui.tray:507 - Debug images saved in /tmp/normcap

Now it works.

@flaphoschi
Copy link

flaphoschi commented Aug 31, 2023

I've learned now some things and fixed my problem :)

Show static permissions of an application:
flatpak info --show-permissions com.github.dynobo.normcap

This static permissions doesn't require support for portals?

Show dynamic permissions:
flatpak permission-show com.github.dynobo.normcap

This is more interesting. GNOME doesn't list that under permissions of an application but above (see later on screenshot). And if a dynamic permission wasn't granted initially NormCap or Flatpak doesn't allow a further request:

[peter@lap-lnx-pew ~]$ flatpak permission-show com.github.dynobo.normcap
Table      Object     App                       Permissions Data
screenshot screenshot com.github.dynobo.normcap no          0x00

This "no" seems to be definite. But from the privacy settings of GNOME this can be modified.

Conclusion:

  • I guess it works.
  • Users need to be patient upon first launch!
  • I've not tested what happens if you launch the application twice within short time (e.g. within 7 seconds). Maybe that caused my issue.

Screenshot from 2023-08-31 14-46-22
Either turn on the switch for "Screenshots" here or use
flatpak permission-reset com.github.dynobo.normcap

which should allow the application to request dynamic permissions again.

// edit
When the dynamic permission for screenshots is missing, NormCap exits:

14:49:28 - INFO    - normcap:30 - Start NormCap v0.4.4
14:49:28 - DEBUG   - normcap:81 - Set XCURSOR_SIZE=24
14:49:28 - DEBUG   - normcap:86 - Set QT_QPA_PLATFORM=wayland
14:49:28 - DEBUG   - normcap.gui.tray:60 - System info:
{'cli_args': '/app/bin/normcap -v debug', 'is_briefcase_package': False, 'is_flatpak_package': True, 'platform': 'linux', 'pyside6_version': '6.5.1', 'qt_version': '6.5.1', 'qt_library_path': '/usr/share/runtime/lib/plugins, /app/lib/python3.10/site-packages/PySide6/Qt/plugins, /usr/bin', 'config_directory': PosixPath('/home/peter/.var/app/com.github.dynobo.normcap/config/normcap'), 'normcap_version': '0.4.4', 'ressources_path': PosixPath('/app/lib/python3.10/site-packages/normcap/resources'), 'tesseract_path': PosixPath('/app/bin/tesseract'), 'tessdata_path': PosixPath('/home/peter/.var/app/com.github.dynobo.normcap/config/normcap/tessdata'), 'envs': {'TESSDATA_PREFIX': '/app/share', 'LD_LIBRARY_PATH': ''}, 'desktop_environment': <DesktopEnvironment.GNOME: 1>, 'display_manager_is_wayland': True, 'screens': [Screen(is_primary=True, device_pixel_ratio=1.0, rect=Rect(left=0, top=0, right=1920, bottom=1080), index=0, screenshot=None)]}
14:49:28 - DEBUG   - normcap.gui.tray:342 - Listen on local socket v0.4.4-normcap.
14:49:28 - DEBUG   - normcap.gui.settings:128 - Skip update of non existing setting (cli_mode: False)
14:49:28 - DEBUG   - normcap.gui.settings:128 - Skip update of non existing setting (background_mode: False)
14:49:28 - DEBUG   - normcap.screengrab:37 - Select capture method DBUS portal
14:49:28 - DEBUG   - normcap.screengrab.dbus_portal:196 - Request screenshot with interactive=False
14:49:28 - DEBUG   - normcap.screengrab.dbus_portal:79 - Request accepted
14:49:28 - ERROR   - normcap.screengrab.dbus_portal:103 - Error code 2 received from xdg-portal!
14:49:28 - DEBUG   - normcap.screengrab.dbus_portal:106 - Parse response
Traceback (most recent call last):
  File "/app/lib/python3.10/site-packages/normcap/screengrab/dbus_portal.py", line 107, in got_signal
    uri = str(message).split('[Variant(QString): "')[1]
IndexError: list index out of range
Traceback (most recent call last):
  File "/app/bin/normcap", line 8, in <module>
    sys.exit(main())
  File "/app/lib/python3.10/site-packages/normcap/app.py", line 57, in main
    tray = SystemTray(app, vars(args))
  File "/app/lib/python3.10/site-packages/normcap/gui/tray.py", line 100, in __init__
    self._update_screenshots(delayed=False)
  File "/app/lib/python3.10/site-packages/normcap/gui/tray.py", line 425, in _update_screenshots
    screens = capture()
  File "/app/lib/python3.10/site-packages/normcap/screengrab/dbus_portal.py", line 197, in capture
    result = _synchronized_capture(interactive=False)
  File "/app/lib/python3.10/site-packages/normcap/screengrab/dbus_portal.py", line 152, in _synchronized_capture
    raise error
normcap.screengrab.ScreenshotResponseError: Error code 2 received from xdg-portal!

Not relevant for normal application flow but maybe this can be improved. NormCap could try to detected the declined permission and show a visible prompt to the user, which explains usage of flatpak permission-reset or directs to the settings of GNOME.

@dynobo
Copy link
Owner Author

dynobo commented Sep 2, 2023

Thank you for sharing your detailed investigation, @flaphoschi! That gave me some new insights!

NormCap could try to detected the declined permission and show a visible prompt to the user.

That is exactly, what NormCap is trying to do. But unfortunately, there is no way to retrieve/detect a missing permission directly, as the portal doesn't send any error when a screenshot is requested with missing permissions, it just doesn't send the response.

The (quite dirty) workaround that is implemented in NormCap works like this:

  1. Request screenshot (silently)
  2. If no response is received after <timeout> seconds, assume missing permission.
  3. Show a visible window, which is a prerequisite of the portal to request for permission. (This is the small background window Timeout when taking a screenshot! ...)
  4. Request screenshot again -> with the visible window, the dynamic permission dialog should become visible.

NormCap could try to detected the declined permission and show a visible prompt to the user, which explains usage of flatpak permission-reset or directs to the settings of GNOME.

A simple implementation of this idea would be to show this information in the already implemented intermediate window (Timeout when taking a screenshot ...). What do you think?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request requires upstream change A change in a dependen project is necessary before this issue can be solved
Projects
None yet
Development

No branches or pull requests

4 participants