diff --git a/Userland/Libraries/LibGUI/CMakeLists.txt b/Userland/Libraries/LibGUI/CMakeLists.txt index d503ad53ff..11c8c58905 100644 --- a/Userland/Libraries/LibGUI/CMakeLists.txt +++ b/Userland/Libraries/LibGUI/CMakeLists.txt @@ -79,6 +79,7 @@ set(SOURCES PasswordInputDialog.cpp PasswordInputDialogGML.h PersistentModelIndex.cpp + Process.cpp ProcessChooser.cpp Progressbar.cpp RadioButton.cpp diff --git a/Userland/Libraries/LibGUI/Process.cpp b/Userland/Libraries/LibGUI/Process.cpp new file mode 100644 index 0000000000..612a93d9eb --- /dev/null +++ b/Userland/Libraries/LibGUI/Process.cpp @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2022, MacDue + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include +#include +#include +#include + +template +void spawn_or_show_error(GUI::Window* parent_window, StringView path, Span arguments) +{ + auto spawn_result = Core::Process::spawn(path, arguments); + if (spawn_result.is_error()) + GUI::MessageBox::show_error(parent_window, String::formatted("Failed to spawn {}: {}", path, spawn_result.error())); +} + +namespace GUI { + +void Process::spawn_or_show_error(Window* parent_window, StringView path, Span arguments) +{ + ::spawn_or_show_error(parent_window, path, arguments); +} + +void Process::spawn_or_show_error(Window* parent_window, StringView path, Span arguments) +{ + ::spawn_or_show_error(parent_window, path, arguments); +} + +void Process::spawn_or_show_error(Window* parent_window, StringView path, Span arguments) +{ + ::spawn_or_show_error(parent_window, path, arguments); +} + +} diff --git a/Userland/Libraries/LibGUI/Process.h b/Userland/Libraries/LibGUI/Process.h new file mode 100644 index 0000000000..5504ba8334 --- /dev/null +++ b/Userland/Libraries/LibGUI/Process.h @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2022, MacDue + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include +#include + +namespace GUI { + +struct Process { + static void spawn_or_show_error(Window* parent_window, StringView path, Span arguments); + static void spawn_or_show_error(Window* parent_window, StringView path, Span arguments); + static void spawn_or_show_error(Window* parent_window, StringView path, Span arguments = {}); +}; + +}