Skip to content

Commit

Permalink
Fix autostart and launch desktop entries
Browse files Browse the repository at this point in the history
Fixes #193
  • Loading branch information
luisbocanegra committed May 1, 2024
1 parent cd96127 commit c2a9544
Showing 1 changed file with 47 additions and 38 deletions.
85 changes: 47 additions & 38 deletions src/kde_material_you_colors/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,44 +53,53 @@ def copy_user_files(dests):


def update_desktop_entry():
if not settings.IN_PATH:
entries = [
{
"dest": settings.USER_APPS_PATH + settings.AUTOSTART_SCRIPT,
"cmd": settings.PKG_BIN,
},
{
"dest": settings.USER_APPS_PATH + settings.STOP_SCRIPT,
"cmd": settings.PKG_BIN + " --stop",
},
{
"dest": settings.USER_AUTOSTART_SCRIPT_PATH + settings.AUTOSTART_SCRIPT,
"cmd": settings.PKG_BIN,
},
]
for entry in entries:
if os.path.exists(entry["dest"]):
logging.debug(f'Updating Exec {entry["dest"]}')
config = configparser.ConfigParser()
config.optionxform = str
config.read(entry["dest"])
config.set("Desktop Entry", "Exec", entry["cmd"])
with open(entry["dest"], "w", encoding="utf-8") as f:
config.write(f, space_around_delimiters=False)
# create symbolic link to user PATH

if not os.path.exists(settings.USER_LOCAL_BIN_PATH):
os.makedirs(settings.USER_LOCAL_BIN_PATH)
link_path = settings.USER_LOCAL_BIN_PATH + "kde-material-you-colors"
if os.path.islink(link_path):
os.unlink(link_path)
logging.debug(f"Updating link {settings.PKG_BIN} -> {link_path}")
else:
logging.debug(f"Creating link {settings.PKG_BIN} -> {link_path}")
os.symlink(
settings.PKG_BIN,
link_path,
)
# This is now executed when creating/updating the desktop entries.
# https://github.com/luisbocanegra/kde-material-you-colors/issues/193
# Even when the executable is already on ~/.local/bin/
# Saves the user from having to add the install location to $PATH e.g:
# $ cat $HOME/.config/plasma-workspace/env/path.sh
# export PATH=$HOME/.local/bin:$PATH
# by always setting the absolute location of the executable.
#
# Also makes sure the alias exists (for advanced users not using pipx)
# so the widget can make use of it
entries = [
{
"dest": settings.USER_APPS_PATH + settings.AUTOSTART_SCRIPT,
"cmd": settings.PKG_BIN,
},
{
"dest": settings.USER_APPS_PATH + settings.STOP_SCRIPT,
"cmd": settings.PKG_BIN + " --stop",
},
{
"dest": settings.USER_AUTOSTART_SCRIPT_PATH + settings.AUTOSTART_SCRIPT,
"cmd": settings.PKG_BIN,
},
]
for entry in entries:
if os.path.exists(entry["dest"]):
logging.debug(f'Updating Exec {entry["dest"]}')
config = configparser.ConfigParser()
config.optionxform = str
config.read(entry["dest"])
config.set("Desktop Entry", "Exec", entry["cmd"])
with open(entry["dest"], "w", encoding="utf-8") as f:
config.write(f, space_around_delimiters=False)

# create symbolic link to user PATH
if not os.path.exists(settings.USER_LOCAL_BIN_PATH):
os.makedirs(settings.USER_LOCAL_BIN_PATH)
link_path = settings.USER_LOCAL_BIN_PATH + "kde-material-you-colors"
if os.path.islink(link_path):
os.unlink(link_path)
logging.debug(f"Updating link {settings.PKG_BIN} -> {link_path}")
else:
logging.debug(f"Creating link {settings.PKG_BIN} -> {link_path}")
os.symlink(
settings.PKG_BIN,
link_path,
)


def one_shot_actions(args):
Expand Down

0 comments on commit c2a9544

Please sign in to comment.