summaryrefslogtreecommitdiff
path: root/Userland/Applications
diff options
context:
space:
mode:
authorMacDue <macdue@dueutil.tech>2022-05-26 23:28:58 +0100
committerLinus Groh <mail@linusgroh.de>2022-06-03 12:29:56 +0100
commit5fd5a03d1f6ac0d4d0ad29cb01752502fe8ebc0d (patch)
treef6e70c3063932822ac3374da4326d29d40d6f4d5 /Userland/Applications
parent5e5a055455be0cd8d8784e83e9e80cb4822970ea (diff)
downloadserenity-5fd5a03d1f6ac0d4d0ad29cb01752502fe8ebc0d.zip
Applications: Use spawn_or_show_error() for common spawn pattern
Diffstat (limited to 'Userland/Applications')
-rw-r--r--Userland/Applications/Assistant/Providers.cpp14
-rw-r--r--Userland/Applications/ClockSettings/TimeZoneSettingsWidget.cpp11
-rw-r--r--Userland/Applications/ClockSettings/TimeZoneSettingsWidget.h2
-rw-r--r--Userland/Applications/CrashReporter/main.cpp10
-rw-r--r--Userland/Applications/KeyboardSettings/KeyboardSettingsWidget.cpp9
-rw-r--r--Userland/Applications/SystemMonitor/main.cpp16
6 files changed, 18 insertions, 44 deletions
diff --git a/Userland/Applications/Assistant/Providers.cpp b/Userland/Applications/Assistant/Providers.cpp
index e22789d618..933fc0d005 100644
--- a/Userland/Applications/Assistant/Providers.cpp
+++ b/Userland/Applications/Assistant/Providers.cpp
@@ -11,6 +11,7 @@
#include <LibCore/DirIterator.h>
#include <LibCore/ElapsedTimer.h>
#include <LibCore/File.h>
+#include <LibCore/Process.h>
#include <LibCore/StandardPaths.h>
#include <LibDesktop/Launcher.h>
#include <LibGUI/Clipboard.h>
@@ -48,15 +49,10 @@ void FileResult::activate() const
void TerminalResult::activate() const
{
- pid_t pid;
- char const* argv[] = { "Terminal", "-k", "-e", title().characters(), nullptr };
-
- if ((errno = posix_spawn(&pid, "/bin/Terminal", nullptr, nullptr, const_cast<char**>(argv), environ))) {
- perror("posix_spawn");
- } else {
- if (disown(pid) < 0)
- perror("disown");
- }
+ // FIXME: This should be a GUI::Process::spawn_or_show_error(), however this is a
+ // 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).
+ (void)Core::Process::spawn("/bin/Terminal", Array { "-k", "-e", title().characters() });
}
void URLResult::activate() const
diff --git a/Userland/Applications/ClockSettings/TimeZoneSettingsWidget.cpp b/Userland/Applications/ClockSettings/TimeZoneSettingsWidget.cpp
index 34ac562a4b..75a411ca4b 100644
--- a/Userland/Applications/ClockSettings/TimeZoneSettingsWidget.cpp
+++ b/Userland/Applications/ClockSettings/TimeZoneSettingsWidget.cpp
@@ -15,6 +15,7 @@
#include <LibGUI/Layout.h>
#include <LibGUI/Margins.h>
#include <LibGUI/Painter.h>
+#include <LibGUI/Process.h>
#include <LibGfx/Palette.h>
#include <LibTimeZone/TimeZone.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 };
}
-void TimeZoneSettingsWidget::set_time_zone() const
+void TimeZoneSettingsWidget::set_time_zone()
{
- pid_t child_pid = 0;
- 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);
- }
+ GUI::Process::spawn_or_show_error(window(), "/bin/timezone", Array { m_time_zone.characters() });
}
diff --git a/Userland/Applications/ClockSettings/TimeZoneSettingsWidget.h b/Userland/Applications/ClockSettings/TimeZoneSettingsWidget.h
index 768fb0b421..202c2c7ed6 100644
--- a/Userland/Applications/ClockSettings/TimeZoneSettingsWidget.h
+++ b/Userland/Applications/ClockSettings/TimeZoneSettingsWidget.h
@@ -26,7 +26,7 @@ private:
void set_time_zone_location();
Optional<Gfx::FloatPoint> compute_time_zone_location() const;
- void set_time_zone() const;
+ void set_time_zone();
String m_time_zone;
RefPtr<GUI::ComboBox> m_time_zone_combo_box;
diff --git a/Userland/Applications/CrashReporter/main.cpp b/Userland/Applications/CrashReporter/main.cpp
index 9a956b3970..aca49b9294 100644
--- a/Userland/Applications/CrashReporter/main.cpp
+++ b/Userland/Applications/CrashReporter/main.cpp
@@ -31,6 +31,7 @@
#include <LibGUI/Label.h>
#include <LibGUI/LinkLabel.h>
#include <LibGUI/MessageBox.h>
+#include <LibGUI/Process.h>
#include <LibGUI/Progressbar.h>
#include <LibGUI/TabWidget.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");
debug_button.set_icon(TRY(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/app-hack-studio.png")));
debug_button.on_click = [&](int) {
- pid_t child;
- 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");
- }
+ GUI::Process::spawn_or_show_error(window, "/bin/HackStudio", Array { "-c", coredump_path });
};
auto& save_backtrace_button = *widget->find_descendant_of_type_named<GUI::Button>("save_backtrace_button");
diff --git a/Userland/Applications/KeyboardSettings/KeyboardSettingsWidget.cpp b/Userland/Applications/KeyboardSettings/KeyboardSettingsWidget.cpp
index 27bccb2b6f..126f908e60 100644
--- a/Userland/Applications/KeyboardSettings/KeyboardSettingsWidget.cpp
+++ b/Userland/Applications/KeyboardSettings/KeyboardSettingsWidget.cpp
@@ -21,6 +21,7 @@
#include <LibGUI/Label.h>
#include <LibGUI/MessageBox.h>
#include <LibGUI/Model.h>
+#include <LibGUI/Process.h>
#include <LibGUI/Widget.h>
#include <LibGUI/Window.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)
{
- pid_t child_pid;
-
auto keymaps_string = String::join(',', keymaps);
- char const* argv[] = { "/bin/keymap", "-s", keymaps_string.characters(), "-m", active_keymap.characters(), nullptr };
- if ((errno = posix_spawn(&child_pid, "/bin/keymap", nullptr, nullptr, const_cast<char**>(argv), environ))) {
- perror("posix_spawn");
- exit(1);
- }
+ GUI::Process::spawn_or_show_error(window(), "/bin/keymap", Array { "-s", keymaps_string.characters(), "-m", active_keymap.characters() });
}
diff --git a/Userland/Applications/SystemMonitor/main.cpp b/Userland/Applications/SystemMonitor/main.cpp
index 17c9031f5c..a97f4c3a12 100644
--- a/Userland/Applications/SystemMonitor/main.cpp
+++ b/Userland/Applications/SystemMonitor/main.cpp
@@ -38,6 +38,7 @@
#include <LibGUI/Menubar.h>
#include <LibGUI/MessageBox.h>
#include <LibGUI/Painter.h>
+#include <LibGUI/Process.h>
#include <LibGUI/SeparatorWidget.h>
#include <LibGUI/SortingProxyModel.h>
#include <LibGUI/StackWidget.h>
@@ -470,17 +471,10 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
"&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&) {
pid_t pid = selected_id(ProcessModel::Column::PID);
- if (pid != -1) {
- auto pid_string = String::number(pid);
- pid_t child;
- const char* argv[] = { "/bin/Profiler", "--pid", pid_string.characters(), nullptr };
- if ((errno = posix_spawn(&child, "/bin/Profiler", nullptr, nullptr, const_cast<char**>(argv), environ))) {
- perror("posix_spawn");
- } else {
- if (disown(child) < 0)
- perror("disown");
- }
- }
+ if (pid == -1)
+ return;
+ auto pid_string = String::number(pid);
+ GUI::Process::spawn_or_show_error(window, "/bin/Profiler", Array { "--pid", pid_string.characters() });
},
&process_table_view);