Open saved screenshot file when notification is clicked#4691
Open
dshcherb wants to merge 4 commits into
Open
Conversation
On GNOME (Wayland), clicking Flameshot's screenshot notification did nothing. The notification was sent via D-Bus with empty actions and only a KDE-specific x-kde-urls hint, which GNOME Shell ignores. Add a "default" action to the D-Bus notification when a file path is attached (per the freedesktop notification spec, this makes the notification body clickable). When the user clicks it, GNOME Shell emits the ActionInvoked signal, which the new handler receives and calls QDesktopServices::openUrl() to open the file. https://specifications.freedesktop.org/notification/1.3/basic-design.html SystemNotification instances are short-lived stack locals in AbstractLogger, so a persistent singleton (actionHandler) is used to receive the D-Bus signal. The notification ID-to-path mapping is stored in a static map. In the CLI capture flow, delay process exit by 10 seconds when notifications are pending, so the D-Bus handler stays alive long enough to receive the user's click. Platform impact: - macOS/Windows: no change (guarded by platform #if) - Linux X11: minor, notification now includes default action - Linux Wayland/KDE: improvement, click-to-open alongside x-kde-urls - Linux Wayland/GNOME: fixed, click now opens the saved file
The previous commit added qApp->exit() in onActionInvoked to exit the CLI process after the user clicks a notification. But the daemon also takes screenshots (e.g. via tray icon) and sends notifications with the same code path — calling qApp->exit() there kills the daemon. Guard the exit with a static flag (s_exitOnLastAction) that is only set to true in the CLI flow (requestCaptureAndWait). The daemon never sets it, so clicking notifications opened from daemon-triggered screenshots opens the file without terminating the daemon.
The Flatpak D-Bus proxy only routes ActionInvoked signals to the sandbox that created the notification. When the CLI sends the notification and exits, the daemon never receives the click signal. This can be fixed by having the CLI suppress its own notification and sending the save path to the daemon via D-Bus. The daemon sends the notification itself, receives the click, and opens the file. The CLI exits immediately, allowing successive screenshots without a 10-second wait.
The notification delegation code uses QDBusConnection and QDBusMessage which are unavailable on Windows and macOS. Wrap it with the existing platform guard so non-Linux builds fall back to the simple exit path.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
On GNOME (Wayland), clicking Flameshot's screenshot notification did nothing. The notification was sent via D-Bus with empty actions and only a KDE-specific x-kde-urls hint, which GNOME Shell ignores.
The change introduces:
Click-to-open logic: added a
defaultaction to the D-Bus notification when a file path is attached (per the freedesktop notification spec, this makes the notification body clickable). When the user clicks it, the notification daemon emits ActionInvoked, which a persistent actionHandler() singleton receives and calls QDesktopServices::openUrl() to open the file. The notification ID-to-path mapping is stored in a static map. We suppress the two non-actionable AbstractLogger::info() notifications (GNOME Wayland detected...andCapture saved to clipboard) by changing them to qDebug(). These sent competing notifications without a default action - if the user clicked one before the actionableCapture saved as <path>notification appeared, the click did nothing.Daemon delegation (Flatpak on GNOME Wayland): The Flatpak D-Bus proxy routes ActionInvoked only to the sandbox whose unique bus ID called Notify(). Each flatpak run invocation creates a separate proxy instance, so when the CLI sends the notification and exits, the daemon never receives the click signal.
This is fixed by having the CLI suppress its own
Capture saved as...notification and sending the save path to the daemon via a new showSaveNotification D-Bus method. The daemon sends the notification itself, receives the click, and opens the file. The CLI exits immediately, allowing rapid successive screenshots.Platform impact: