You are not logged in.

#1 2022-02-18 08:22:41

lorhof1
Member
Registered: 2022-01-31
Posts: 10

Differences for an app if it's being run from .desktop instead of sh?

Sorry for the short title, I am limited by the technology of my time.

I've seen a program (of mine) behave unexpectedly when run from a .desktop file in /usr/share/applications. When it is run from a shell (bash) it works just fine. Now, I'd like to know what changes for the program when it is run from said .desktop file so I can find the issue.

The .desktop file:

[Desktop Entry]
Name=Software Installation
Exec=softinst
Icon=/usr/share/icons/Crule/apps/scalable/org.kde.kget.svg
Terminal=false
Type=Application
StartupNotify=true

Edit: OK, maybe I didn't give enough information.

softinst:

#!/bin/python3
# this software depends on gui-get-pass (ggp)
from sys import argv, exit
from os import system

def sendNotification(title, text):
	system("notify-send \"" + title + "\" \"" + text + "\"")

def installName(root, packageName):
	root.destroy()
	system("ggp | sudo -Sv && yay --noconfirm -S " + packageName + " && notify-send \"Software Installation\" \"Sucess\" || notify-send \"Software Installation\" \"Failed to install software. Maybe the package was not found or the entered password was incorrect.\"")

def installFile(path):
	sendNotification("Software Installation", "Starting installation")
	system("ggp | sudo -S pacman --noconfirm -U " + path + " && notify-send \"Software Installation\" \"Sucess\" || notify-send \"Software Installation\" \"Failed to install software. Maybe the package is not supported or the entered password was incorrect.\"")


def gui():
	import tkinter as tk

	root = tk.Tk()
	root.configure(bg="white")
	root.geometry("800x600")
	root.title("Software Installation")

	tk.Label(root, text="\nInstall Software from a package name\n\n\n", bg="white").pack()
	packageName = tk.StringVar(root, value="")
	tk.Entry(root, width=50, textvariable=packageName).pack()
	tk.Label(root, text="\n", bg="white").pack()
	tk.Button(root, text="Continue", command=lambda:[installName(root, packageName.get())], bg="white").pack()
	root.bind("<Return>", lambda x:[installName(root, packageName.get())])


	root.mainloop()
	return 0


match len(argv):
	case 1:
		exit(gui())
	#case 2:
	#	exit(installFile(argv[1]))
	case _:
		exit("Invalid number of arguments")

Dependency ggp:

#!/bin/python3
# this software asks for the password with a gui and prints it to stdout for piping to programs like sudo
import tkinter as tk

root = tk.Tk()

def end(root, password):
	print(password.get())
	root.destroy()

root.configure(bg="white")
root.geometry("250x120")
root.title("Password entry")
tk.Label(root, text="\nPlease enter your Password\n", bg="white").pack()
password = tk.StringVar(root, value="")
tk.Entry(root, show="*", width=30, textvariable=password).pack()
root.bind("<Return>", lambda x:[end(root, password)])
tk.Button(root, text="Continue", command=lambda:[end(root, password)], bg="white").pack()

root.mainloop()

The exact issue: The system call in

installFile()

doesn't work correctly: It asks for the package to install as well as for the password, but I always get the error notification, while the software works flawlessly when run from the terminal.

Last edited by lorhof1 (2022-02-18 12:05:24)

Offline

#2 2022-02-18 09:32:05

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 77,063

Re: Differences for an app if it's being run from .desktop instead of sh?

It esp. inherits the environment of the interactive shell - maybe your locale is misconfigured.
If you want a more specific answer, you'll have to be a bit more elaborative on the "unexpected behavior".

Offline

#3 2022-02-18 09:55:08

V1del
Forum Moderator
Registered: 2012-10-16
Posts: 25,292

Re: Differences for an app if it's being run from .desktop instead of sh?

https://bbs.archlinux.org/viewtopic.php?id=57855

This isn't the desktop file, post the actual desktop file and in fact the actual script/program you are running if you want actual help including what exactly fails how and where.

The only hint I can give with this generic information is that check differences in your environment. If not started from a shell you'll likely have different environments between your graphical and your terminal session, if you manipulate anything here as part of your .bashrc then this won't be part of the environment of your desktop session and vice versa: https://wiki.archlinux.org/title/Environment_variables

Edit: Semi-fuck

Last edited by V1del (2022-02-18 09:56:00)

Offline

Board footer

Powered by FluxBB