mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 12:37:44 +00:00
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:
parent
4983a972b0
commit
37cc110003
2 changed files with 18 additions and 6 deletions
|
@ -128,13 +128,14 @@ void TaskbarWindow::create_quick_launch_bar()
|
||||||
if (!af->is_valid())
|
if (!af->is_valid())
|
||||||
continue;
|
continue;
|
||||||
auto app_executable = af->executable();
|
auto app_executable = af->executable();
|
||||||
|
auto app_run_in_terminal = af->run_in_terminal();
|
||||||
const int button_size = 24;
|
const int button_size = 24;
|
||||||
auto& button = quick_launch_bar.add<GUI::Button>();
|
auto& button = quick_launch_bar.add<GUI::Button>();
|
||||||
button.set_fixed_size(button_size, button_size);
|
button.set_fixed_size(button_size, button_size);
|
||||||
button.set_button_style(Gfx::ButtonStyle::Coolbar);
|
button.set_button_style(Gfx::ButtonStyle::Coolbar);
|
||||||
button.set_icon(af->icon().bitmap_for_size(16));
|
button.set_icon(af->icon().bitmap_for_size(16));
|
||||||
button.set_tooltip(af->name());
|
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();
|
pid_t pid = fork();
|
||||||
if (pid < 0) {
|
if (pid < 0) {
|
||||||
perror("fork");
|
perror("fork");
|
||||||
|
@ -143,6 +144,9 @@ void TaskbarWindow::create_quick_launch_bar()
|
||||||
perror("chdir");
|
perror("chdir");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
if (app_run_in_terminal)
|
||||||
|
execl("/bin/Terminal", "Terminal", "-e", app_executable.characters(), nullptr);
|
||||||
|
else
|
||||||
execl(app_executable.characters(), app_executable.characters(), nullptr);
|
execl(app_executable.characters(), app_executable.characters(), nullptr);
|
||||||
perror("execl");
|
perror("execl");
|
||||||
VERIFY_NOT_REACHED();
|
VERIFY_NOT_REACHED();
|
||||||
|
|
|
@ -70,6 +70,7 @@ struct AppMetadata {
|
||||||
String executable;
|
String executable;
|
||||||
String name;
|
String name;
|
||||||
String category;
|
String category;
|
||||||
|
bool run_in_terminal;
|
||||||
};
|
};
|
||||||
Vector<AppMetadata> g_apps;
|
Vector<AppMetadata> g_apps;
|
||||||
|
|
||||||
|
@ -89,7 +90,7 @@ Vector<String> discover_apps_and_categories()
|
||||||
HashTable<String> seen_app_categories;
|
HashTable<String> seen_app_categories;
|
||||||
Desktop::AppFile::for_each([&](auto af) {
|
Desktop::AppFile::for_each([&](auto af) {
|
||||||
if (access(af->executable().characters(), X_OK) == 0) {
|
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());
|
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());
|
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](auto&) {
|
||||||
dbgln("Activated app with ID {}", app_identifier);
|
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;
|
pid_t child_pid;
|
||||||
const char* argv[] = { bin.characters(), nullptr };
|
if ((errno = posix_spawn(&child_pid, argv[0], nullptr, nullptr, const_cast<char**>(argv), environ))) {
|
||||||
if ((errno = posix_spawn(&child_pid, bin.characters(), nullptr, nullptr, const_cast<char**>(argv), environ))) {
|
|
||||||
perror("posix_spawn");
|
perror("posix_spawn");
|
||||||
} else {
|
} else {
|
||||||
if (disown(child_pid) < 0)
|
if (disown(child_pid) < 0)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue