1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 15:07:45 +00:00

Applications: Use spawn_or_show_error() for common spawn pattern

This commit is contained in:
MacDue 2022-05-26 23:28:58 +01:00 committed by Linus Groh
parent 5e5a055455
commit 5fd5a03d1f
6 changed files with 18 additions and 44 deletions

View file

@ -11,6 +11,7 @@
#include <LibCore/DirIterator.h> #include <LibCore/DirIterator.h>
#include <LibCore/ElapsedTimer.h> #include <LibCore/ElapsedTimer.h>
#include <LibCore/File.h> #include <LibCore/File.h>
#include <LibCore/Process.h>
#include <LibCore/StandardPaths.h> #include <LibCore/StandardPaths.h>
#include <LibDesktop/Launcher.h> #include <LibDesktop/Launcher.h>
#include <LibGUI/Clipboard.h> #include <LibGUI/Clipboard.h>
@ -48,15 +49,10 @@ void FileResult::activate() const
void TerminalResult::activate() const void TerminalResult::activate() const
{ {
pid_t pid; // FIXME: This should be a GUI::Process::spawn_or_show_error(), however this is a
char const* argv[] = { "Terminal", "-k", "-e", title().characters(), nullptr }; // Assistant::Result object, which does not have access to the application's GUI::Window* pointer
// (which spawn_or_show_error() needs incase it has to open a error message box).
if ((errno = posix_spawn(&pid, "/bin/Terminal", nullptr, nullptr, const_cast<char**>(argv), environ))) { (void)Core::Process::spawn("/bin/Terminal", Array { "-k", "-e", title().characters() });
perror("posix_spawn");
} else {
if (disown(pid) < 0)
perror("disown");
}
} }
void URLResult::activate() const void URLResult::activate() const

View file

@ -15,6 +15,7 @@
#include <LibGUI/Layout.h> #include <LibGUI/Layout.h>
#include <LibGUI/Margins.h> #include <LibGUI/Margins.h>
#include <LibGUI/Painter.h> #include <LibGUI/Painter.h>
#include <LibGUI/Process.h>
#include <LibGfx/Palette.h> #include <LibGfx/Palette.h>
#include <LibTimeZone/TimeZone.h> #include <LibTimeZone/TimeZone.h>
#include <LibUnicode/DateTimeFormat.h> #include <LibUnicode/DateTimeFormat.h>
@ -156,13 +157,7 @@ Optional<Gfx::FloatPoint> TimeZoneSettingsWidget::compute_time_zone_location() c
return Gfx::FloatPoint { mercadian_x, mercadian_y }; return Gfx::FloatPoint { mercadian_x, mercadian_y };
} }
void TimeZoneSettingsWidget::set_time_zone() const void TimeZoneSettingsWidget::set_time_zone()
{ {
pid_t child_pid = 0; GUI::Process::spawn_or_show_error(window(), "/bin/timezone", Array { m_time_zone.characters() });
char const* argv[] = { "/bin/timezone", m_time_zone.characters(), nullptr };
if ((errno = posix_spawn(&child_pid, "/bin/timezone", nullptr, nullptr, const_cast<char**>(argv), environ))) {
perror("posix_spawn");
exit(1);
}
} }

View file

@ -26,7 +26,7 @@ private:
void set_time_zone_location(); void set_time_zone_location();
Optional<Gfx::FloatPoint> compute_time_zone_location() const; Optional<Gfx::FloatPoint> compute_time_zone_location() const;
void set_time_zone() const; void set_time_zone();
String m_time_zone; String m_time_zone;
RefPtr<GUI::ComboBox> m_time_zone_combo_box; RefPtr<GUI::ComboBox> m_time_zone_combo_box;

View file

@ -31,6 +31,7 @@
#include <LibGUI/Label.h> #include <LibGUI/Label.h>
#include <LibGUI/LinkLabel.h> #include <LibGUI/LinkLabel.h>
#include <LibGUI/MessageBox.h> #include <LibGUI/MessageBox.h>
#include <LibGUI/Process.h>
#include <LibGUI/Progressbar.h> #include <LibGUI/Progressbar.h>
#include <LibGUI/TabWidget.h> #include <LibGUI/TabWidget.h>
#include <LibGUI/TextEditor.h> #include <LibGUI/TextEditor.h>
@ -264,14 +265,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
auto& debug_button = *widget->find_descendant_of_type_named<GUI::Button>("debug_button"); auto& debug_button = *widget->find_descendant_of_type_named<GUI::Button>("debug_button");
debug_button.set_icon(TRY(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/app-hack-studio.png"))); debug_button.set_icon(TRY(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/app-hack-studio.png")));
debug_button.on_click = [&](int) { debug_button.on_click = [&](int) {
pid_t child; GUI::Process::spawn_or_show_error(window, "/bin/HackStudio", Array { "-c", coredump_path });
const char* argv[4] = { "HackStudio", "-c", coredump_path, nullptr };
if ((errno = posix_spawn(&child, "/bin/HackStudio", nullptr, nullptr, const_cast<char**>(argv), environ))) {
perror("posix_spawn");
} else {
if (disown(child) < 0)
perror("disown");
}
}; };
auto& save_backtrace_button = *widget->find_descendant_of_type_named<GUI::Button>("save_backtrace_button"); auto& save_backtrace_button = *widget->find_descendant_of_type_named<GUI::Button>("save_backtrace_button");

View file

@ -21,6 +21,7 @@
#include <LibGUI/Label.h> #include <LibGUI/Label.h>
#include <LibGUI/MessageBox.h> #include <LibGUI/MessageBox.h>
#include <LibGUI/Model.h> #include <LibGUI/Model.h>
#include <LibGUI/Process.h>
#include <LibGUI/Widget.h> #include <LibGUI/Widget.h>
#include <LibGUI/Window.h> #include <LibGUI/Window.h>
#include <LibGfx/Font/FontDatabase.h> #include <LibGfx/Font/FontDatabase.h>
@ -281,12 +282,6 @@ void KeyboardSettingsWidget::apply_settings()
void KeyboardSettingsWidget::set_keymaps(Vector<String> const& keymaps, String const& active_keymap) void KeyboardSettingsWidget::set_keymaps(Vector<String> const& keymaps, String const& active_keymap)
{ {
pid_t child_pid;
auto keymaps_string = String::join(',', keymaps); auto keymaps_string = String::join(',', keymaps);
char const* argv[] = { "/bin/keymap", "-s", keymaps_string.characters(), "-m", active_keymap.characters(), nullptr }; GUI::Process::spawn_or_show_error(window(), "/bin/keymap", Array { "-s", keymaps_string.characters(), "-m", active_keymap.characters() });
if ((errno = posix_spawn(&child_pid, "/bin/keymap", nullptr, nullptr, const_cast<char**>(argv), environ))) {
perror("posix_spawn");
exit(1);
}
} }

View file

@ -38,6 +38,7 @@
#include <LibGUI/Menubar.h> #include <LibGUI/Menubar.h>
#include <LibGUI/MessageBox.h> #include <LibGUI/MessageBox.h>
#include <LibGUI/Painter.h> #include <LibGUI/Painter.h>
#include <LibGUI/Process.h>
#include <LibGUI/SeparatorWidget.h> #include <LibGUI/SeparatorWidget.h>
#include <LibGUI/SortingProxyModel.h> #include <LibGUI/SortingProxyModel.h>
#include <LibGUI/StackWidget.h> #include <LibGUI/StackWidget.h>
@ -470,17 +471,10 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
"&Profile Process", { Mod_Ctrl, Key_P }, "&Profile Process", { Mod_Ctrl, Key_P },
Gfx::Bitmap::try_load_from_file("/res/icons/16x16/app-profiler.png").release_value_but_fixme_should_propagate_errors(), [&](auto&) { Gfx::Bitmap::try_load_from_file("/res/icons/16x16/app-profiler.png").release_value_but_fixme_should_propagate_errors(), [&](auto&) {
pid_t pid = selected_id(ProcessModel::Column::PID); pid_t pid = selected_id(ProcessModel::Column::PID);
if (pid != -1) { if (pid == -1)
auto pid_string = String::number(pid); return;
pid_t child; auto pid_string = String::number(pid);
const char* argv[] = { "/bin/Profiler", "--pid", pid_string.characters(), nullptr }; GUI::Process::spawn_or_show_error(window, "/bin/Profiler", Array { "--pid", pid_string.characters() });
if ((errno = posix_spawn(&child, "/bin/Profiler", nullptr, nullptr, const_cast<char**>(argv), environ))) {
perror("posix_spawn");
} else {
if (disown(child) < 0)
perror("disown");
}
}
}, },
&process_table_view); &process_table_view);