From 3dc2c24ec566f4cd03be17838f4d02df7c6f9b29 Mon Sep 17 00:00:00 2001 From: apio Date: Wed, 20 Mar 2024 19:58:45 +0100 Subject: [PATCH] apps: Add run This utility lets you run a process detached from the shell, using the magic of the launch server. --- apps/CMakeLists.txt | 1 + apps/run.cpp | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 apps/run.cpp diff --git a/apps/CMakeLists.txt b/apps/CMakeLists.txt index 23f29d4a..9ff9d10a 100644 --- a/apps/CMakeLists.txt +++ b/apps/CMakeLists.txt @@ -51,3 +51,4 @@ luna_app(clock.cpp clock) target_link_libraries(clock PUBLIC ui) luna_app(startui.cpp startui) luna_app(launch.cpp launch) +luna_app(run.cpp run) diff --git a/apps/run.cpp b/apps/run.cpp new file mode 100644 index 00000000..9025a837 --- /dev/null +++ b/apps/run.cpp @@ -0,0 +1,35 @@ +/** + * @file run.cpp + * @author apio (cloudapio.eu) + * @brief Tiny command-line utility to start a detached program in the current GUI session. + * + * @copyright Copyright (c) 2024, the Luna authors. + * + */ + +#include +#include +#include +#include + +Result luna_main(int argc, char** argv) +{ + StringView program; + + os::ArgumentParser parser; + parser.add_description("Start a detached program in the current GUI session."_sv); + parser.add_system_program_info("run"_sv); + parser.add_positional_argument(program, "program", true); + parser.parse(argc, argv); + + OwnedPtr launcher_client = TRY(os::IPC::Client::connect("/tmp/launch.sock", false)); + + os::println("Requesting to start program '%s'...", program.chars()); + + os::Launcher::LaunchDetachedRequest request; + SET_IPC_STRING(request.command, program.chars()); + request.search_in_path = true; + launcher_client->send_async(request); + + return 0; +}