Bug 415948 - Session creation in Kate causes invalid desktop file to be placed in ~/.local/share/applications
Summary: Session creation in Kate causes invalid desktop file to be placed in ~/.local...
Status: CONFIRMED
Alias: None
Product: frameworks-kconfig
Classification: Frameworks and Libraries
Component: general (show other bugs)
Version: 5.90.0
Platform: Fedora RPMs Linux
: NOR major
Target Milestone: ---
Assignee: Matthew Dawson
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-01-06 21:49 UTC by Manuel Amador (Rudd-O)
Modified: 2023-12-23 16:37 UTC (History)
12 users (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Manuel Amador (Rudd-O) 2020-01-06 21:49:29 UTC
SUMMARY

If the user creates a Kate session, Kate persists the session in a desktop file created in the user's local/share/applications folder.  It does so the following way:

------------------------------------------
[Desktop Action Session d4c143f004d88b7286e6f999dea9d0d7]
Exec=kate -s accounting
Name=accounting

[Desktop Entry]
Actions=Session d4c143f004d88b7286e6f999dea9d0d7;
Categories=Qt;KDE;Utility;TextEditor;
Comment=KDE Advanced Text Editor
Exec=kate -b %U
GenericName=Advanced Text Editor
Icon=kate
InitialPreference=9
MimeType=text/plain;
Name=Kate
StartupNotify=true
Terminal=false
Type=Application
X-DBUS-ServiceName=org.kde.kate
X-DBUS-StartupType=Multi
X-DocPath=kate/index.html
X-KDE-HasTempFileOption=true
------------------------------------------

The presence of this header before the [Desktop Entry] header (which is a violation of the desktop entry spec) causes programs which use GIO's GDesktopAppInfo to launch applications (including the Qubes OS operating system) to fail to launch the applications.  The same file minus the [Desktop Actions] header works fine in the same environment:

--------------------------------------

[Desktop Entry]
Actions=Session d4c143f004d88b7286e6f999dea9d0d7;
Categories=Qt;KDE;Utility;TextEditor;
Comment=KDE Advanced Text Editor
Exec=kate -b %U
GenericName=Advanced Text Editor
Icon=kate
InitialPreference=9
MimeType=text/plain;
Name=Kate
StartupNotify=true
Terminal=false
Type=Application
X-DBUS-ServiceName=org.kde.kate
X-DBUS-StartupType=Multi
X-DocPath=kate/index.html
X-KDE-HasTempFileOption=true

--------------------------------------

It is unclear at this time whether the problem is with the editor that does it, or somewhere in KDELibs that is doing the creation of the desktop file, but it's certainly a bug.

OBSERVED RESULT

Programs compliant with the desktop entry specification fail.  Please see https://gitlab.gnome.org/GNOME/glib/issues/1987 for more information.

SOFTWARE/OS VERSIONS
Linux/KDE Plasma: Latest available in Fedora 30.
Comment 1 Justin Zobel 2020-10-30 03:21:21 UTC
Manuel I've just tested this on git master and can't see the same header as you're getting in the .desktop file.

Can you please re-test and let us know if this issue is still affecting you?
Comment 2 Bug Janitor Service 2020-11-14 04:33:56 UTC
Dear Bug Submitter,

This bug has been in NEEDSINFO status with no change for at least
15 days. Please provide the requested information as soon as
possible and set the bug status as REPORTED. Due to regular bug
tracker maintenance, if the bug is still in NEEDSINFO status with
no change in 30 days the bug will be closed as RESOLVED > WORKSFORME
due to lack of needed information.

For more information about our bug triaging procedures please read the
wiki located here:
https://community.kde.org/Guidelines_and_HOWTOs/Bug_triaging

If you have already provided the requested information, please
mark the bug as REPORTED so that the KDE team knows that the bug is
ready to be confirmed.

Thank you for helping us make KDE software even better for everyone!
Comment 3 Manuel Amador (Rudd-O) 2020-11-14 11:47:38 UTC
Hello.  I can't test with KDE git, I'm sorry.  I'm on kate-20.04.1-1.fc32.x86_64 at this time.
Comment 4 Manuel Amador (Rudd-O) 2020-11-14 11:48:02 UTC
Moving back to REPORTED.
Comment 5 Manuel Amador (Rudd-O) 2020-11-14 11:49:40 UTC
To reproduce:

Create a Kate session however you like.  Give it a name.  Save the session.  Exit kate.  cat .local/share/applications/org.kde.kate.desktop

You should see the [Desktop Action Session XXXXX] header at the top then.
Comment 6 Manuel Amador (Rudd-O) 2020-11-14 11:50:56 UTC
Just to be perfectly clear: it's normal and okay that Kate adds such a section in the desktop file — this supports the behavior of modern desktop environments that allow context menu launches of various "application modes" (e.g. in this case "Open session X" when right-clicking on Kate in the application launcher).

What's wrong is that the first section of the file MUST BE, according to the spec, [Desktop Entry].
Comment 7 Manuel Amador (Rudd-O) 2020-11-14 11:54:08 UTC
This function is where the problematic behavior takes place:

https://github.com/KDE/kate/blob/6d0dc7ddaf0ccc19f716b951aa5e2223034f854b/kate/session/katesessionmanager.cpp#L569
Comment 8 Manuel Amador (Rudd-O) 2020-11-14 12:00:41 UTC
Get Git blame added to the Github view in the link I just pasted.  On line 620, there's code to "Alphabetically sort actions".  This causes "Desktop Action XXX" to appear before "Desktop Entry".

That's what's causing the bug.  This code should always keep "Desktop Entry" at the very beginning.
Comment 9 Manuel Amador (Rudd-O) 2020-11-14 12:01:03 UTC
Incidentally this code was added about 2 years ago which more or less is when I started experiencing the issue.
Comment 10 Manuel Amador (Rudd-O) 2020-11-14 12:01:34 UTC
https://github.com/KDE/kate/blame/6d0dc7ddaf0ccc19f716b951aa5e2223034f854b/kate/session/katesessionmanager.cpp#L620 the exact point to where the save behavior is broken.
Comment 11 Kåre Särs 2020-11-14 14:20:36 UTC
Thanks for the detailed description.

I sounds like you would be able to provide a patch to fix it ;)

https://invent.kde.org/utilities/kate

Best regards,
  Kåre
Comment 12 Manuel Amador (Rudd-O) 2020-11-14 20:19:04 UTC
I, uh, would love to, but my employer forbids me from coding for others, which is something I regret having have signed.  Can we enlist someone in the project to look at the fix please?  Thank you!  🤗

Nov 14, 2020 15:20:42 Kåre Särs <bugzilla_noreply@kde.org>:

> https://bugs.kde.org/show_bug.cgi?id=415948
> 
> Kåre Särs <kare.sars@iki.fi> changed:
> 
>            What    |Removed                     |Added
> ----------------------------------------------------------------------------
>                  CC|                            |kare.sars@iki.fi
> 
> --- Comment #11 from Kåre Särs <kare.sars@iki.fi> ---
> Thanks for the detailed description.
> 
> I sounds like you would be able to provide a patch to fix it ;)
> 
> https://invent.kde.org/utilities/kate
> 
> Best regards,
>   Kåre
> 
> -- 
> You are receiving this mail because:
> You reported the bug.
Comment 13 pavl.va 2020-11-26 16:08:00 UTC
It is still present and reproducible.
Please, assign someone to this bug reported in June 2020
https://bugs.launchpad.net/ubuntu/+source/kate/+bug/1884432
Comment 14 Justin Zobel 2020-11-27 01:36:30 UTC
(In reply to pavl.va from comment #13)
> It is still present and reproducible.
> Please, assign someone to this bug reported in June 2020
> https://bugs.launchpad.net/ubuntu/+source/kate/+bug/1884432

The KDE Community has no bearing on launchpad. That kate entry on launchpad is managed by the Debian Qt/KDE team.
Comment 15 adrianna.pinska 2020-12-17 08:42:13 UTC
I can confirm that this bug is present in Kate 19.12.3, the default version in Ubuntu 20.04, and is a major annoyance. The only workaround is to rewrite the desktop file manually every time a new session is saved. This is clearly an upstream issue which has nothing to do with Ubuntu.
Comment 16 pavl.va 2020-12-17 08:49:40 UTC
(In reply to adrianna.pinska from comment #15)
> I can confirm that this bug is present in Kate 19.12.3, the default version
> in Ubuntu 20.04, and is a major annoyance. The only workaround is to rewrite
> the desktop file manually every time a new session is saved. This is clearly
> an upstream issue which has nothing to do with Ubuntu.

Ok, so, please, at least draw attention to it by confirming on launchpad that it affects you too. Thank you.
Comment 17 John Wyatt 2021-05-10 23:08:32 UTC
This issue is still present in both Kate 21.04.0 and 20.12.3. On GNOME 40 it causes a very nasty bug where Kate no longer shows in the app picker after opening and closing Kate with session files. Experienced on both Manjaro and Arch GNOME. (Note: Manjaro GNOME uses additional plugins over Arch GNOME.)

https://gitlab.gnome.org/GNOME/gnome-shell/-/issues/4227
Comment 18 Christoph Cullmann 2022-01-08 20:57:37 UTC
Perhaps I misread the code, but the order is because KConfig will sort that output that way for writing it to the desktop file.
If the [Desktop Entry] group really needs to be first, perhaps this must be handled in KDeskopFile.
Comment 19 Martinus 2023-02-27 08:01:06 UTC
I hit this bug in KDE 5.92.0 installed on the top of regular Ubuntu 22.04.2 LTS
Comment 20 Ralf Jung 2023-08-24 12:07:36 UTC
This is still a problem in Kate 22.12.3. It makes Kate very hard to use on non-KDE desktop environments that expect desktop files to match the spec.

One doesn't even need to create a session. Just starting Kate when a session exists, and closing it again, will create the faulty desktop file. I would probably have to delete all my sessions to work around this.
Comment 21 lamyseba 2023-12-09 02:07:01 UTC
This bug is still present in Manjaro Gnome version as of today (december 2023). It seems quite simple to fix, but has been present for three years?  Meanwhile, it seams it can help to do the job manually yourself: edit the file
`~/.local/share/applications/org.kde.kate.desktop

And cut all the text that is above 

[Desktop Entry]

Then, paste that text at the end of the file, below everything. That should do the job.