mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 12:17:44 +00:00
Taskbar: Use GUI::Process::spawn_or_show_error() to launch apps
And while here make a partial fix for launching terminal apps that require root and contain spaces in their name/path.
This commit is contained in:
parent
0af3e37f5d
commit
c9043280ec
1 changed files with 14 additions and 29 deletions
|
@ -176,42 +176,27 @@ ErrorOr<NonnullRefPtr<GUI::Menu>> build_system_menu(GUI::Window& window)
|
||||||
}
|
}
|
||||||
|
|
||||||
auto parent_menu = app_category_menus.get(app.category).value_or(system_menu.ptr());
|
auto parent_menu = app_category_menus.get(app.category).value_or(system_menu.ptr());
|
||||||
parent_menu->add_action(GUI::Action::create(app.name, icon, [app_identifier](auto&) {
|
parent_menu->add_action(GUI::Action::create(app.name, icon, [app_identifier, &window](auto&) {
|
||||||
dbgln("Activated app with ID {}", app_identifier);
|
dbgln("Activated app with ID {}", app_identifier);
|
||||||
auto& app = g_apps[app_identifier];
|
auto& app = g_apps[app_identifier];
|
||||||
char const* argv[4] { nullptr, nullptr, nullptr, nullptr };
|
StringView executable;
|
||||||
auto pls_with_executable = DeprecatedString::formatted("/bin/pls {}", app.executable);
|
Vector<char const*, 2> arguments;
|
||||||
|
// FIXME: These single quotes won't be enough for executables with single quotes in their name.
|
||||||
|
auto pls_with_executable = DeprecatedString::formatted("/bin/pls '{}'", app.executable);
|
||||||
if (app.run_in_terminal && !app.requires_root) {
|
if (app.run_in_terminal && !app.requires_root) {
|
||||||
argv[0] = "/bin/Terminal";
|
executable = "/bin/Terminal"sv;
|
||||||
argv[1] = "-e";
|
arguments = { "-e", app.executable.characters() };
|
||||||
argv[2] = app.executable.characters();
|
|
||||||
} else if (!app.run_in_terminal && app.requires_root) {
|
} else if (!app.run_in_terminal && app.requires_root) {
|
||||||
argv[0] = "/bin/Escalator";
|
executable = "/bin/Escalator"sv;
|
||||||
argv[1] = app.executable.characters();
|
arguments = { app.executable.characters() };
|
||||||
} else if (app.run_in_terminal && app.requires_root) {
|
} else if (app.run_in_terminal && app.requires_root) {
|
||||||
argv[0] = "/bin/Terminal";
|
executable = "/bin/Terminal"sv;
|
||||||
argv[1] = "-e";
|
arguments = { "-e", pls_with_executable.characters() };
|
||||||
argv[2] = pls_with_executable.characters();
|
|
||||||
} else {
|
} else {
|
||||||
argv[0] = app.executable.characters();
|
executable = app.executable;
|
||||||
}
|
}
|
||||||
|
GUI::Process::spawn_or_show_error(&window, executable, arguments,
|
||||||
posix_spawn_file_actions_t spawn_actions;
|
app.working_directory.is_empty() ? Core::StandardPaths::home_directory() : app.working_directory);
|
||||||
posix_spawn_file_actions_init(&spawn_actions);
|
|
||||||
auto home_directory = Core::StandardPaths::home_directory();
|
|
||||||
if (app.working_directory.is_empty())
|
|
||||||
posix_spawn_file_actions_addchdir(&spawn_actions, home_directory.characters());
|
|
||||||
else
|
|
||||||
posix_spawn_file_actions_addchdir(&spawn_actions, app.working_directory.characters());
|
|
||||||
|
|
||||||
pid_t child_pid;
|
|
||||||
if ((errno = posix_spawn(&child_pid, argv[0], &spawn_actions, nullptr, const_cast<char**>(argv), environ))) {
|
|
||||||
perror("posix_spawn");
|
|
||||||
} else {
|
|
||||||
if (disown(child_pid) < 0)
|
|
||||||
perror("disown");
|
|
||||||
}
|
|
||||||
posix_spawn_file_actions_destroy(&spawn_actions);
|
|
||||||
}));
|
}));
|
||||||
++app_identifier;
|
++app_identifier;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue