Process.cpp 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. /*
  2. * Copyright (c) 2022, MacDue <macdue@dueutil.tech>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <AK/Format.h>
  7. #include <AK/StringView.h>
  8. #include <LibGUI/MessageBox.h>
  9. #include <LibGUI/Process.h>
  10. template<typename StringType>
  11. void spawn_or_show_error(GUI::Window* parent_window, StringView path, Span<StringType const> arguments)
  12. {
  13. auto spawn_result = Core::Process::spawn(path, arguments);
  14. if (spawn_result.is_error())
  15. GUI::MessageBox::show_error(parent_window, String::formatted("Failed to spawn {}: {}", path, spawn_result.error()));
  16. }
  17. namespace GUI {
  18. void Process::spawn_or_show_error(Window* parent_window, StringView path, Span<String const> arguments)
  19. {
  20. ::spawn_or_show_error<String>(parent_window, path, arguments);
  21. }
  22. void Process::spawn_or_show_error(Window* parent_window, StringView path, Span<StringView const> arguments)
  23. {
  24. ::spawn_or_show_error<StringView>(parent_window, path, arguments);
  25. }
  26. void Process::spawn_or_show_error(Window* parent_window, StringView path, Span<char const* const> arguments)
  27. {
  28. ::spawn_or_show_error<char const*>(parent_window, path, arguments);
  29. }
  30. }