Bug 470438 - Open new files in tab does not work in flatpak verison of Okular 23.04.1
Summary: Open new files in tab does not work in flatpak verison of Okular 23.04.1
Status: REPORTED
Alias: None
Product: okular
Classification: Applications
Component: general (show other bugs)
Version: 23.04.1
Platform: Other Linux
: NOR normal
Target Milestone: ---
Assignee: Okular developers
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-05-30 05:30 UTC by Azure Number
Modified: 2024-06-28 21:26 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Azure Number 2023-05-30 05:30:29 UTC
SUMMARY
Open new files in tab option in Settings > Configure Okular > General > Program features does not work when opening pdf files using double click from mouse in Dolphin file manager , instead multiple Okular windows opens up. But if I select multiple pdf files at once and launch them at once , the feature works and it does not work when multiple files launched one after the another .

This happens in flatpak version of Okular 23.04.1.

STEPS TO REPRODUCE
1. Launch pdf files from Dolphin file manager one at time .

OBSERVED RESULT
Multiple windows of Okular is launched for each pdf files.


EXPECTED RESULT
Pdf files should launch in new tabs in single okular window.

SOFTWARE/OS VERSIONS
Operating System: Debian GNU/Linux 11
KDE Plasma Version: 5.20.5
KDE Frameworks Version: 5.78.0
Qt Version: 5.15.2
Kernel Version: 5.10.0-23-amd64
OS Type: 64-bit
Processors: 4 × Intel® Core™ i3-7020U CPU @ 2.30GHz
Memory: 3.7 GiB of RAM
Graphics Processor: Mesa Intel® HD Graphics 620

ADDITIONAL INFORMATION
Flatpak package version : 1.10.8-0+deb11u1
Comment 1 kwvanderlinde 2024-06-28 21:26:33 UTC
Did some digging on this as I encountered the same problem on Linux Mint with Okular 24.05.1. I'm not an expert with the tech involved, but the issue seems to be a combo of collisions between D-Bus service names and lack of permissions on the flatpak itself.

For flatpak permissions, okular needs to have access to the session bus since it needs to discover the other okular services. But the flatpak does not have this permission set by default and so the user has to enable it explicitly.

For the D-Bus service name, okular includes the PID, which normally results in separate a D-Bus service for each okular process. But under flatpak, the PID is always the same due to running under a separate PID namespace (e.g., I always see a PID of 2). So when okular is already running, and we try to open a new document from the file explorer, the new okular process will have the same PID and D-Bus service name as the existing process. So even if the new process could discover the existing process service, it will think it just discovered itself and won't send the new paths over to the existing process.

As a workaround, here's what I did to get the flatpak to open docs in new tabs instead of new windows:
1. Add the `socket=session-bus` permission, e.g., through flatseal. This is generally not recommended by flatpak, but is required for service discovery.
2. Enable PID sharing with the top-level namespace, which will give each okular process a distinct PID. Instead of `flatpak run org.kde.okular`, use `flatpak --parent-pid=1 --parent-share-pids run org.kde.okular`.

I think the ideal (from a flatpak perspective) would be for okular to use one d-bus service with a consistent name rather than having a unique service per-process. This way the flatpak would only need permission for that particular service instead of the entire session bus. It would also mean there would be no issue with PID collisions, so those would not have to be shared with the parent namespace.