Skip to content

Commit

Permalink
AutostartCondition support
Browse files Browse the repository at this point in the history
  • Loading branch information
Guiiix committed Dec 20, 2024
1 parent e9e5b81 commit 8bfa751
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions app-menu/qubes-session-autostart
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,38 @@ from qubesagent.xdg import launch, find_dropins, \
load_desktop_entry_with_dropins
import xdg.BaseDirectory
import os
import re


QUBES_XDG_CONFIG_DROPINS = '/etc/qubes/autostart'


def check_file_existence(path: str) -> bool:
if os.path.isabs(path):
return os.path.exists(path)
else:
return os.path.exists(os.path.join(xdg.BaseDirectory.xdg_config_home, path))


def entry_should_be_started(entry, environments):
"""
:type entry: DesktopEntry
"""
if entry.getHidden():
return False

# Handle AutostartCondition keys. Not part of the official XDG specification but documented here:
# https://lists.freedesktop.org/archives/xdg/2007-January/007436.html
# Only if-exists and unless-exists keywords are supported
# Invalid syntax is ignored
for autostart_condition in entry.get('AutostartCondition', list=True):
search = re.search(r'^\s*(if|unless)-exists (.*)', autostart_condition)
if search:
should_exists = search.group(1) == 'if'
if should_exists != check_file_existence(search.group(2)):
return False

if entry.getOnlyShowIn():
return bool(set(entry.getOnlyShowIn()).intersection(environments))
if entry.getNotShowIn():
Expand Down

0 comments on commit 8bfa751

Please sign in to comment.