mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 07:27:45 +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
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue