AppFile.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. namespace Desktop {
  12. class AppFile : public RefCounted<AppFile> {
  13. public:
  14. static constexpr auto APP_FILES_DIRECTORY = "/res/apps"sv;
  15. static bool exists_for_app(StringView app_name);
  16. static ByteString file_for_app(StringView app_name);
  17. static ByteString app_file_path_for_app(StringView app_name);
  18. static NonnullRefPtr<AppFile> get_for_app(StringView app_name);
  19. static NonnullRefPtr<AppFile> open(StringView path);
  20. static void for_each(Function<void(NonnullRefPtr<AppFile>)>, StringView directory = APP_FILES_DIRECTORY);
  21. ~AppFile() = default;
  22. bool is_valid() const { return m_valid; }
  23. ByteString filename() const { return m_config->filename(); }
  24. ByteString name() const;
  25. ByteString menu_name() const;
  26. ByteString executable() const;
  27. ByteString category() const;
  28. ByteString description() const;
  29. ByteString working_directory() const;
  30. ByteString icon_path() const;
  31. GUI::Icon icon() const;
  32. bool run_in_terminal() const;
  33. bool requires_root() const;
  34. bool exclude_from_system_menu() const;
  35. Vector<ByteString> launcher_mime_types() const;
  36. Vector<ByteString> launcher_file_types() const;
  37. Vector<ByteString> launcher_protocols() const;
  38. bool spawn(ReadonlySpan<StringView> arguments = {}) const;
  39. private:
  40. explicit AppFile(StringView path);
  41. bool validate() const;
  42. RefPtr<Core::ConfigFile> m_config;
  43. bool m_valid { false };
  44. };
  45. }