2020-12-27 18:50:50 +01:00
|
|
|
/*
|
2021-04-22 22:51:19 +02:00
|
|
|
* Copyright (c) 2020, Linus Groh <linusg@serenityos.org>
|
2022-02-26 10:30:59 -07:00
|
|
|
* Copyright (c) 2022, the SerenityOS developers.
|
2020-12-27 18:50:50 +01:00
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-12-27 18:50:50 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <LibCore/ConfigFile.h>
|
|
|
|
|
#include <LibGUI/FileIconProvider.h>
|
|
|
|
|
#include <LibGUI/Icon.h>
|
2024-01-05 17:20:33 +13:00
|
|
|
#include <LibGUI/Window.h>
|
2020-12-27 18:50:50 +01:00
|
|
|
|
2020-12-28 01:06:38 +01:00
|
|
|
namespace Desktop {
|
2020-12-27 18:50:50 +01:00
|
|
|
|
|
|
|
|
class AppFile : public RefCounted<AppFile> {
|
|
|
|
|
public:
|
2022-07-11 17:32:29 +00:00
|
|
|
static constexpr auto APP_FILES_DIRECTORY = "/res/apps"sv;
|
|
|
|
|
|
2023-11-04 19:31:08 +01:00
|
|
|
static bool exists_for_app(StringView app_name);
|
2023-12-16 17:49:34 +03:30
|
|
|
static ByteString file_for_app(StringView app_name);
|
|
|
|
|
static ByteString app_file_path_for_app(StringView app_name);
|
2023-11-04 19:31:08 +01:00
|
|
|
|
2021-11-11 00:55:02 +01:00
|
|
|
static NonnullRefPtr<AppFile> get_for_app(StringView app_name);
|
|
|
|
|
static NonnullRefPtr<AppFile> open(StringView path);
|
|
|
|
|
static void for_each(Function<void(NonnullRefPtr<AppFile>)>, StringView directory = APP_FILES_DIRECTORY);
|
2022-02-26 10:32:57 -07:00
|
|
|
~AppFile() = default;
|
2020-12-27 18:50:50 +01:00
|
|
|
|
|
|
|
|
bool is_valid() const { return m_valid; }
|
2023-12-16 17:49:34 +03:30
|
|
|
ByteString filename() const { return m_config->filename(); }
|
|
|
|
|
|
|
|
|
|
ByteString name() const;
|
2024-01-04 08:19:34 +13:00
|
|
|
ByteString menu_name() const;
|
2023-12-16 17:49:34 +03:30
|
|
|
ByteString executable() const;
|
|
|
|
|
ByteString category() const;
|
|
|
|
|
ByteString description() const;
|
|
|
|
|
ByteString working_directory() const;
|
|
|
|
|
ByteString icon_path() const;
|
2021-08-04 13:16:26 +02:00
|
|
|
GUI::Icon icon() const;
|
2021-07-19 22:00:34 +01:00
|
|
|
bool run_in_terminal() const;
|
2022-10-03 20:08:34 -04:00
|
|
|
bool requires_root() const;
|
2023-01-02 11:59:48 -05:00
|
|
|
bool exclude_from_system_menu() const;
|
2023-12-16 17:49:34 +03:30
|
|
|
Vector<ByteString> launcher_mime_types() const;
|
|
|
|
|
Vector<ByteString> launcher_file_types() const;
|
|
|
|
|
Vector<ByteString> launcher_protocols() const;
|
2023-01-20 21:50:53 +00:00
|
|
|
bool spawn(ReadonlySpan<StringView> arguments = {}) const;
|
2024-01-05 17:20:33 +13:00
|
|
|
bool spawn_with_escalation(ReadonlySpan<StringView> arguments = {}) const;
|
|
|
|
|
void spawn_with_escalation_or_show_error(GUI::Window&, ReadonlySpan<StringView> arguments = {}) const;
|
2020-12-27 18:50:50 +01:00
|
|
|
|
|
|
|
|
private:
|
2021-11-11 00:55:02 +01:00
|
|
|
explicit AppFile(StringView path);
|
2020-12-27 18:50:50 +01:00
|
|
|
|
|
|
|
|
bool validate() const;
|
|
|
|
|
|
|
|
|
|
RefPtr<Core::ConfigFile> m_config;
|
|
|
|
|
bool m_valid { false };
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|