Bug 394670 - Spectacle does not export screenshot if closed prematurely
Summary: Spectacle does not export screenshot if closed prematurely
Status: RESOLVED INTENTIONAL
Alias: None
Product: Spectacle
Classification: Applications
Component: General (other bugs)
Version First Reported In: 18.04.0
Platform: Slackware Linux
: NOR normal
Target Milestone: ---
Assignee: Boudhayan Gupta
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-05-25 13:21 UTC by naikinnn
Modified: 2018-05-26 15:07 UTC (History)
1 user (show)

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


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description naikinnn 2018-05-25 13:21:59 UTC
When I take a screenshot with spectacle I often want to export it to another program, e.g. GIMP. However, if I click on the export option and close the spectacle window before GIMP has managed to load, when GIMP starts it tells me that it cannot open the screenshot because it does not exist. This is definitely a problem with Spectacle because the same behavior is observed with other programs available for export. It would be nice to keep the file until it is read by the export program, even if Spectacle is closed beforehand. I remember that this behavior was present in KDE4.
Comment 1 null 2018-05-26 15:07:01 UTC
Thanks for the report. I looked into this, here's what I've found:

KSnapshot uses "KStandardDirs::locateLocal" to provide a temporary file, and then passes handling on to "kioexec". Cleanup (i.e. deleting the temporary file) is done when "kioexec" exits after a delay (~3 minutes for me), which starts as soon as the app you used to open the file exited.

In KF5, "KStandardDirs::locateLocal" is not provided by the API anymore, and therefore Spectacle uses "QTemporaryDir". Here, cleanup is done in-process by Spectacle via Qt. This means as soon as Spectacle closes, the temporary path will be gone, so GIMP fails to open it.

Nevertheless, "kioexec" is still used in Spectacle via "KRun::runService", and the deletion after the delay is still scheduled (see https://phabricator.kde.org/source/kio/browse/master/src/kioexec/main.cpp;047f5fe921172c0890c7a14d5fff93b1310376ee$258). However, "QTemporaryFile" already deleted the screenshot earlier.

Should we go back to the approach KSnapshot used? I'm not sure about that for a couple of reasons:

1. Deleting the file via "kioexec" is unreliable, for example ending your session by logging out within delay will result in the temporary file staying around forever.
2. The temporary file handling is also used for drag-and-drop, where otherwise no cleanup would be done.
3. "KRun" can only delete files, while Spectacle uses temporary directories to allow natural filenames while using a unique path name (this was a design deficiency in KSnapshot) and to provide a stable directory for saving multiple temporary screenshots.
4. "kioexec" deleting the file on its own breaks drag-and-dropping or exporting the image again after 3 minutes.

Therefore, I'm closing the bug as WONTFIX (sorry!). There are two workarounds you can employ:
- Close Spectacle only after GIMP loaded the image.
- Uncheck "Ignore images" in Klipper's configure dialog, and use "Copy To Clipboard" to be able to paste into GIMP after Spectacle was closed.

We are also working on adding more annotation/editing functions directly to Spectacle, so hopefully GIMP will be needed less often.