Skip to content

Commit

Permalink
Merge pull request #86 from regolith-linux/feat/systemd-run
Browse files Browse the repository at this point in the history
feat: launch apps and commands using systemd-run
  • Loading branch information
kgilmer authored Jun 29, 2024
2 parents 666a292 + 353aff8 commit 5d860c0
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
15 changes: 15 additions & 0 deletions src/Main.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
3 changes: 2 additions & 1 deletion src/apps/DesktopAppPage.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -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 ();
Expand Down
5 changes: 3 additions & 2 deletions src/commands/CommandPage.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}

Expand All @@ -242,4 +243,4 @@ namespace Ilia {
}
}
}
}
}

0 comments on commit 5d860c0

Please sign in to comment.