Taskbar: Launch apps in Terminal when RunInTerminal=true is specified

This feels a bit awkward right now, and needs code duplication - I think
adding a mechanism to the AppFile class to run the executable would be
neat, especially if we add an arguments field to app files - but this
will do for now.
This commit is contained in:
Linus Groh 2021-07-19 22:03:50 +01:00
parent 4983a972b0
commit 37cc110003
Notes: sideshowbarker 2024-07-18 08:43:47 +09:00
2 changed files with 18 additions and 6 deletions

View file

@ -128,13 +128,14 @@ void TaskbarWindow::create_quick_launch_bar()
if (!af->is_valid())
continue;
auto app_executable = af->executable();
auto app_run_in_terminal = af->run_in_terminal();
const int button_size = 24;
auto& button = quick_launch_bar.add<GUI::Button>();
button.set_fixed_size(button_size, button_size);
button.set_button_style(Gfx::ButtonStyle::Coolbar);
button.set_icon(af->icon().bitmap_for_size(16));
button.set_tooltip(af->name());
button.on_click = [app_executable](auto) {
button.on_click = [app_executable, app_run_in_terminal](auto) {
pid_t pid = fork();
if (pid < 0) {
perror("fork");
@ -143,7 +144,10 @@ void TaskbarWindow::create_quick_launch_bar()
perror("chdir");
exit(1);
}
execl(app_executable.characters(), app_executable.characters(), nullptr);
if (app_run_in_terminal)
execl("/bin/Terminal", "Terminal", "-e", app_executable.characters(), nullptr);
else
execl(app_executable.characters(), app_executable.characters(), nullptr);
perror("execl");
VERIFY_NOT_REACHED();
} else {

View file

@ -70,6 +70,7 @@ struct AppMetadata {
String executable;
String name;
String category;
bool run_in_terminal;
};
Vector<AppMetadata> g_apps;
@ -89,7 +90,7 @@ Vector<String> discover_apps_and_categories()
HashTable<String> seen_app_categories;
Desktop::AppFile::for_each([&](auto af) {
if (access(af->executable().characters(), X_OK) == 0) {
g_apps.append({ af->executable(), af->name(), af->category() });
g_apps.append({ af->executable(), af->name(), af->category(), af->run_in_terminal() });
seen_app_categories.set(af->category());
}
});
@ -173,10 +174,17 @@ NonnullRefPtr<GUI::Menu> build_system_menu()
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&) {
dbgln("Activated app with ID {}", app_identifier);
const auto& bin = g_apps[app_identifier].executable;
auto& app = g_apps[app_identifier];
char const* argv[4] { nullptr, nullptr, nullptr, nullptr };
if (app.run_in_terminal) {
argv[0] = "/bin/Terminal";
argv[1] = "-e";
argv[2] = app.executable.characters();
} else {
argv[0] = app.executable.characters();
}
pid_t child_pid;
const char* argv[] = { bin.characters(), nullptr };
if ((errno = posix_spawn(&child_pid, bin.characters(), nullptr, nullptr, const_cast<char**>(argv), environ))) {
if ((errno = posix_spawn(&child_pid, argv[0], nullptr, nullptr, const_cast<char**>(argv), environ))) {
perror("posix_spawn");
} else {
if (disown(child_pid) < 0)