ladybird/Userland/Libraries/LibDesktop/AppFile.h
Linus Groh 4983a972b0 LibDesktop: Add a RunInTerminal boolean field to app files
This is common enough to warrant its own setting by now - but it's also
partially a workaround. Since app files currently only support a single
executable path with no arguments, we resort to generating wrapper
scripts for port launchers with arguments - and then the executable is
that shell script. We also moved from manually specifying icon files to
embedding them in executables. As shell scripts can't have icons
embedded in them, a different solution is needed - this one solves the
common case of running a CLI program in a terminal, and still allows
embedding of icons in the executable itself as no shell script is
needed, meaning it will be shown in the taskbar and system menu.

The second use case of actually passing arguments to the executable
itself (and not just "Terminal -e ...") is not covered by this and still
requires an external script (meaning no icon for now), but I think that
can easily be solved by adding something like an "Arguments" field to
app files. :^)
2021-07-20 00:58:26 +01:00

46 lines
1.2 KiB
C++

/*
* Copyright (c) 2020, Linus Groh <linusg@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <LibCore/ConfigFile.h>
#include <LibGUI/FileIconProvider.h>
#include <LibGUI/Icon.h>
namespace Desktop {
class AppFile : public RefCounted<AppFile> {
public:
static constexpr const char* APP_FILES_DIRECTORY = "/res/apps";
static NonnullRefPtr<AppFile> get_for_app(const StringView& app_name);
static NonnullRefPtr<AppFile> open(const StringView& path);
static void for_each(Function<void(NonnullRefPtr<AppFile>)>, const StringView& directory = APP_FILES_DIRECTORY);
~AppFile();
bool is_valid() const { return m_valid; }
String filename() const { return m_config->filename(); }
String name() const;
String executable() const;
String category() const;
bool run_in_terminal() const;
Vector<String> launcher_file_types() const;
Vector<String> launcher_protocols() const;
bool spawn() const;
GUI::Icon icon() const { return GUI::FileIconProvider::icon_for_path(executable()); };
private:
explicit AppFile(const StringView& path);
bool validate() const;
RefPtr<Core::ConfigFile> m_config;
bool m_valid { false };
};
}