Skip to content

Commit

Permalink
Merge pull request #853 from Ulauncher/780
Browse files Browse the repository at this point in the history
Restore --scope argument but only use systemd-run if running from within a systemd unit
  • Loading branch information
friday committed Nov 14, 2021
2 parents c1f5707 + 8316df6 commit 6c410cc
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions ulauncher/api/shared/action/LaunchAppAction.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import os
import re
import shlex
import shutil
from shutil import which
from pathlib import Path
import gi

Expand All @@ -16,7 +16,8 @@

logger = logging.getLogger(__name__)
settings = Settings.get_instance()
hasSystemdRun = bool(shutil.which("systemd-run"))
has_systemd = which("systemctl") and which("systemd-run")
runs_in_systemd = has_systemd and os.system('systemctl --user is-active --quiet ulauncher') == 0


class LaunchAppAction(BaseAction):
Expand Down Expand Up @@ -50,11 +51,15 @@ def run(self):
sanitized_exec = ['gtk-launch', app_id]
else:
sanitized_exec = shlex.split(sanitized_exec)
if hasSystemdRun and not app.get_boolean('X-Ulauncher-Inherit-Scope'):
if runs_in_systemd and not app.get_boolean('X-Ulauncher-Inherit-Scope'):
logger.warning("Will attempt to launch the app using systemd-run with --scope argument")
logger.warning("This prevents the apps from terminating if Ulauncher crashes or is restarted.")
logger.warning("On some systems with outdated systemd or incorrect permissions this doesn't work.")
logger.warning("If this happens to you, don't run Ulauncher from systemd.")
sanitized_exec = [
'systemd-run',
'--user',
'--remain-after-exit',
'--scope',
] + sanitized_exec

env = dict(os.environ.items())
Expand Down

0 comments on commit 6c410cc

Please sign in to comment.