Skip to content

Commit

Permalink
Merge pull request #952 from Ulauncher/support-DBusActivatable
Browse files Browse the repository at this point in the history
Support DBusActivatable apps
  • Loading branch information
friday committed Jan 14, 2022
2 parents 713a3cb + 8025554 commit 43b6c87
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions ulauncher/api/shared/action/LaunchAppAction.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import re
import shlex
from shutil import which
from pathlib import Path
import gi

gi.require_version("GLib", "2.0")
Expand Down Expand Up @@ -35,22 +34,27 @@ def keep_app_open(self):

def run(self):
app = read_desktop_file(self.filename)
app_id = Path(self.filename).with_suffix('').stem
app_id = app.get_id()
app_exec = app.get_string('Exec')
if not app_exec:
logger.error("No command to run %s", self.filename)
else:
if app.get_boolean('DBusActivatable'):
# https://wiki.gnome.org/HowDoI/DBusApplicationLaunching
exec = ['gapplication', 'launch', app_id.replace('.desktop', '')]
elif app_exec:
# strip field codes %f, %F, %u, %U, etc
stripped_app_exec = re.sub(r'\%[uUfFdDnNickvm]', '', app_exec).rstrip()
terminal_exec = shlex.split(settings.get_property('terminal-command'))
if app.get_boolean('Terminal'):
terminal_exec = settings.get_property('terminal-command')
if terminal_exec:
logger.info('Will run command in preferred terminal (%s)', terminal_exec)
exec = terminal_exec + [stripped_app_exec]
exec = shlex.split(terminal_exec) + [stripped_app_exec]
else:
exec = ['gtk-launch', app_id]
else:
exec = shlex.split(stripped_app_exec)

if not exec:
logger.error("No command to run %s", app_id)
else:
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.")
Expand All @@ -64,7 +68,7 @@ def run(self):
env.pop("GDK_BACKEND", None)

try:
logger.info('Run application %s (%s) Exec %s', app.get_name(), self.filename, app_exec)
logger.info('Run application %s (%s) Exec %s', app.get_name(), self.filename, exec)
envp = ["{}={}".format(k, v) for k, v in env.items()]
GLib.spawn_async(
argv=exec,
Expand Down

0 comments on commit 43b6c87

Please sign in to comment.