Skip to content

Commit df1ffd4

Browse files
committed
Merge remote-tracking branch 'origin/pr/538'
* origin/pr/538: AutostartCondition support Pull request description: Support conditional startup of XDG applications by checking the existence of a given file. The check must be configured using the setting ``AutostartCondition=if-exists`` or ``AutostartCondition=unless-exists`` in .desktop files.
2 parents 8497bb8 + 8bfa751 commit df1ffd4

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

app-menu/qubes-session-autostart

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,38 @@ from qubesagent.xdg import launch, find_dropins, \
2828
load_desktop_entry_with_dropins
2929
import xdg.BaseDirectory
3030
import os
31+
import re
3132

3233

3334
QUBES_XDG_CONFIG_DROPINS = '/etc/qubes/autostart'
3435

3536

37+
def check_file_existence(path: str) -> bool:
38+
if os.path.isabs(path):
39+
return os.path.exists(path)
40+
else:
41+
return os.path.exists(os.path.join(xdg.BaseDirectory.xdg_config_home, path))
42+
43+
3644
def entry_should_be_started(entry, environments):
3745
"""
3846
3947
:type entry: DesktopEntry
4048
"""
4149
if entry.getHidden():
4250
return False
51+
52+
# Handle AutostartCondition keys. Not part of the official XDG specification but documented here:
53+
# https://lists.freedesktop.org/archives/xdg/2007-January/007436.html
54+
# Only if-exists and unless-exists keywords are supported
55+
# Invalid syntax is ignored
56+
for autostart_condition in entry.get('AutostartCondition', list=True):
57+
search = re.search(r'^\s*(if|unless)-exists (.*)', autostart_condition)
58+
if search:
59+
should_exists = search.group(1) == 'if'
60+
if should_exists != check_file_existence(search.group(2)):
61+
return False
62+
4363
if entry.getOnlyShowIn():
4464
return bool(set(entry.getOnlyShowIn()).intersection(environments))
4565
if entry.getNotShowIn():

0 commit comments

Comments
 (0)