typer
typer copied to clipboard
[BUG] Cannot .launch Executable In latest KDE Plasma versions
Describe the bug
Attempting to launch an executable directly or launching a .desktop on KDE has unanticipated behavior/fails.
To Reproduce
Steps to reproduce the behavior with a minimum self-contained file.
- Create a file
main.py
with:
app = typer.Typer()
@app.command()
def launch_exec():
typer.launch("/usr/bin/ls")
@app.command()
def launch_desktop():
typer.launch("ls.desktop")
if __name__ == "__main__":
app()
- Create a file
ls.desktop
in the same directory with:
[Desktop Entry]
# The type as listed above
Type=Application
# The version of the desktop entry specification to which this file complies
Version=1.0
# The name of the application
Name=ls
# A comment which can/will be used as a tooltip
Comment=run ls
# The path to the folder in which the executable is run
Path=/
# The executable of the application, possibly with arguments.
Exec=/usr/bin/ls
# Describes whether this application needs to be run in a terminal or not
Terminal=true
- To test with an executable:
python main.py launch-exec
-
launch-exec
outputs (See screenshots):
A new window displays the following information:
Error -- KIO Client
For security reasons, launching executables is not allowed in this context.
- But I expected it to output:
It should request permission to launch if permission is required (or it should launch)
- To test with a desktop file:
python main.py launch-desktop
-
launch-desktop
outputs (See screenshots):
It opens the desktop file in KATE (KDEs text editor) for editing.
- But I expected it to output:
It should request permission to launch if permission is required (or it should launch)
Expected behavior
When attempting to launch an application, the application should launch or request permissions to launch
Screenshots
for an executable
for a .desktop
file
Environment
-
OS: Linux, Manjaro KDE Edition
-
Typer Version 0.3.2
-
Python version: Python 3.9.1
Additional context
I did a bit of digging into this.
The launch function is recreated in Typer but this issue can be recreated in Click (Not surprising since it's almost identical).
On the backend these both use [xdg-open](https://wiki.archlinux.org/index.php/User:Larivact/xdg-open#:~:text=xdg%2Dopen%20is%20a%20desktop,file%2Dopener%20application%20(eg.) which is a DE agnostic tool for opening files and URLs. Inside a DE this will pass along to the running DE's file opener app.
Here is the default application that will be used to open an executable or a desktop file on my KDE environment.
# An executable file type does not appear to have a default.
(cdda-manager) ~/r/b/cdda-manager ❯❯❯ xdg-mime query default "application/x-executable"
# The default for desktop files is to open in kate, which is the behavior we observed.
(cdda-manager) ~/r/b/cdda-manager ❯❯❯ xdg-mime query default "application/x-desktop" ✘ 4
org.kde.kate.desktop
(cdda-manager) ~/r/b/cdda-manager ❯❯❯
One way that does seem to work to open these files from a terminal is this:
# Both of these execute properly without even requesting a user prompt.
kioclient5 exec ls.desktop
kioclient5 exec /usr/bin/ls
Also of note is that you DO see the expected behavior in Dolphin (KDEs File Manager) if you double click an executable or desktop file as it appears to have it's own settings for how to handle executables (or .desktop files which it consider executable as well)
See attached screenshots.
Working examples
Here are some working examples for getting execs and desktops to run.
@app.command()
def working_exec1():
typer.echo("I'm running the executable directly")
c = subprocess.Popen(["/usr/bin/ls"])
return 0
@app.command()
def working_exec2():
typer.echo("I'm running the executable via kioclient")
c = subprocess.Popen(["/usr/bin/kioclient5", "exec", "/usr/bin/ls"])
return 0
@app.command()
def working_desktop1():
typer.echo("I'm opening the .desktop via kioclient")
c = subprocess.Popen(["/usr/bin/kioclient5", "exec", "ls.desktop"])
return 0
@app.command()
def working_desktop2():
typer.echo("I'm opening the .desktop via dolphin")
c = subprocess.Popen(["dolphin", "+", FULLPATHTOFILE])
return 0
EDIT: Updated
This was posted accidentally adding additional information.
I'm still facing this issue as of today on the latest version of Endeavor OS
From what I understand you're facing an issue with KDE and how it handles programs and permissions, not with Typer itself, right? I suspect the right place to ask would be on KDE. There's probably something you have to do to your program or to Python in general to make KDE accept that interaction.
Sorry for the long delay! 🙈 I wanted to personally address each issue/PR and they piled up through time, but now I'm checking each one in order.
Assuming the original issue was solved, it will be automatically closed now. But feel free to add more comments or create new issues.