From 353aff879c8e598066ccc0aa0c3e20abe0677dcb Mon Sep 17 00:00:00 2001 From: Soumya Ranjan Patnaik Date: Sat, 29 Jun 2024 11:36:03 +0530 Subject: [PATCH] feat: launch apps and commands using systemd-run --- src/Main.vala | 15 +++++++++++++++ src/apps/DesktopAppPage.vala | 3 ++- src/commands/CommandPage.vala | 5 +++-- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/Main.vala b/src/Main.vala index 8771896..a6daa22 100644 --- a/src/Main.vala +++ b/src/Main.vala @@ -251,3 +251,18 @@ string? get_wm_cli() { } return null; } + + +/* Get AppInfo object used to run a command */ +public AppInfo get_runner_app_info (AppInfo app_info) throws GLib.Error { + string systemd_run_path = GLib.Environment.find_program_in_path ("systemd-run"); + if (systemd_run_path == null) { + return app_info; + } + string app_id = app_info.get_id (); + string exec = app_info.get_commandline (); + string random_suffix = Uuid.string_random ().slice (0, 8); + string unit_name = "run_ilia_" + app_id + "_" + random_suffix + ".scope"; + string systemd_launch = "systemd-run --user --scope --unit "+ unit_name + " " + exec; + return AppInfo.create_from_commandline (systemd_launch, app_id, AppInfoCreateFlags.NONE); +} diff --git a/src/apps/DesktopAppPage.vala b/src/apps/DesktopAppPage.vala index cbabd6c..0d14e14 100644 --- a/src/apps/DesktopAppPage.vala +++ b/src/apps/DesktopAppPage.vala @@ -342,6 +342,7 @@ namespace Ilia { filter.@get (selection, ITEM_VIEW_COLUMN_APPINFO, out app_info); try { + AppInfo runner = get_runner_app_info (app_info); AppLaunchContext ctx = new AppLaunchContext(); ctx.launched.connect ((info, platform_data) => { @@ -359,7 +360,7 @@ namespace Ilia { // TODO ~ perhaps add some visual hint that launch process has begun }); - var result = app_info.launch (null, ctx); + var result = runner.launch (null, ctx); if (result) { string key = app_info.get_id (); diff --git a/src/commands/CommandPage.vala b/src/commands/CommandPage.vala index e2448b2..1291338 100644 --- a/src/commands/CommandPage.vala +++ b/src/commands/CommandPage.vala @@ -231,8 +231,9 @@ namespace Ilia { try { var app_info = AppInfo.create_from_commandline (commandline, null, GLib.AppInfoCreateFlags.NONE); + var runner = get_runner_app_info (app_info); - if (!app_info.launch (null, null)) { + if (!runner.launch (null, null)) { stderr.printf ("Error: execute_command failed\n"); } @@ -242,4 +243,4 @@ namespace Ilia { } } } -} \ No newline at end of file +}