AppFile.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*
  2. * Copyright (c) 2020, Linus Groh <linusg@serenityos.org>
  3. * Copyright (c) 2022, the SerenityOS developers.
  4. *
  5. * SPDX-License-Identifier: BSD-2-Clause
  6. */
  7. #pragma once
  8. #include <LibCore/ConfigFile.h>
  9. #include <LibGUI/FileIconProvider.h>
  10. #include <LibGUI/Icon.h>
  11. #include <LibGUI/Window.h>
  12. namespace Desktop {
  13. class AppFile : public RefCounted<AppFile> {
  14. public:
  15. static constexpr auto APP_FILES_DIRECTORY = "/res/apps"sv;
  16. static bool exists_for_app(StringView app_name);
  17. static ByteString file_for_app(StringView app_name);
  18. static ByteString app_file_path_for_app(StringView app_name);
  19. static NonnullRefPtr<AppFile> get_for_app(StringView app_name);
  20. static NonnullRefPtr<AppFile> open(StringView path);
  21. static void for_each(Function<void(NonnullRefPtr<AppFile>)>, StringView directory = APP_FILES_DIRECTORY);
  22. ~AppFile() = default;
  23. bool is_valid() const { return m_valid; }
  24. ByteString filename() const { return m_config->filename(); }
  25. ByteString name() const;
  26. ByteString menu_name() const;
  27. ByteString executable() const;
  28. ByteString category() const;
  29. ByteString description() const;
  30. ByteString working_directory() const;
  31. ByteString icon_path() const;
  32. GUI::Icon icon() const;
  33. bool run_in_terminal() const;
  34. bool requires_root() const;
  35. bool exclude_from_system_menu() const;
  36. Vector<ByteString> launcher_mime_types() const;
  37. Vector<ByteString> launcher_file_types() const;
  38. Vector<ByteString> launcher_protocols() const;
  39. bool spawn(ReadonlySpan<StringView> arguments = {}) const;
  40. bool spawn_with_escalation(ReadonlySpan<StringView> arguments = {}) const;
  41. void spawn_with_escalation_or_show_error(GUI::Window&, ReadonlySpan<StringView> arguments = {}) const;
  42. private:
  43. explicit AppFile(StringView path);
  44. bool validate() const;
  45. RefPtr<Core::ConfigFile> m_config;
  46. bool m_valid { false };
  47. };
  48. }