apps: Add run
Some checks failed
Build and test / build (push) Failing after 1m43s

This utility lets you run a process detached from the shell, using the magic of the launch server.
This commit is contained in:
apio 2024-03-20 19:58:45 +01:00
parent 06b8a41d2f
commit 3dc2c24ec5
Signed by: apio
GPG Key ID: B8A7D06E42258954
2 changed files with 36 additions and 0 deletions

View File

@ -51,3 +51,4 @@ luna_app(clock.cpp clock)
target_link_libraries(clock PUBLIC ui) target_link_libraries(clock PUBLIC ui)
luna_app(startui.cpp startui) luna_app(startui.cpp startui)
luna_app(launch.cpp launch) luna_app(launch.cpp launch)
luna_app(run.cpp run)

35
apps/run.cpp Normal file
View File

@ -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 <os/ArgumentParser.h>
#include <os/File.h>
#include <os/LocalClient.h>
#include <os/ipc/Launcher.h>
Result<int> 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<os::IPC::Client> 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;
}