LibDesktop+LaunchServer: Propagate AppFile arguments over IPC

This will allow clients (namely FileManager) to use the arguments
specified in the AppFile.
This commit is contained in:
Timothy Flynn 2024-04-30 12:29:32 -04:00 committed by Andrew Kaster
parent b5e5354515
commit 7dd961c39f
4 changed files with 16 additions and 1 deletions

View file

@ -20,6 +20,11 @@ auto Launcher::Details::from_details_str(ByteString const& details_str) -> Nonnu
auto const& obj = json.as_object();
details->executable = obj.get_byte_string("executable"sv).value_or({});
details->name = obj.get_byte_string("name"sv).value_or({});
obj.get_array("arguments"sv).value().for_each([&](JsonValue const& argument) {
details->arguments.append(argument.as_string());
});
if (auto type_value = obj.get_byte_string("type"sv); type_value.has_value()) {
auto const& type_str = type_value.value();
if (type_str == "app")

View file

@ -26,6 +26,7 @@ public:
struct Details : public RefCounted<Details> {
ByteString name;
ByteString executable;
Vector<ByteString> arguments;
LauncherType launcher_type { LauncherType::Default };
static NonnullRefPtr<Details> from_details_str(ByteString const&);

View file

@ -50,6 +50,12 @@ ByteString Handler::to_details_str() const
auto obj = MUST(JsonObjectSerializer<>::try_create(builder));
MUST(obj.add("executable"sv, executable));
MUST(obj.add("name"sv, name));
auto arguments = MUST(obj.add_array("arguments"sv));
for (auto const& argument : this->arguments)
MUST(arguments.add(argument));
MUST(arguments.finish());
switch (handler_type) {
case Type::Application:
MUST(obj.add("type"sv, "app"));
@ -63,6 +69,7 @@ ByteString Handler::to_details_str() const
default:
break;
}
MUST(obj.finish());
return builder.to_byte_string();
}
@ -84,6 +91,7 @@ void Launcher::load_handlers(ByteString const& af_dir)
Desktop::AppFile::for_each([&](auto af) {
auto app_name = af->name();
auto app_executable = af->executable();
auto app_arguments = af->arguments();
HashTable<ByteString> mime_types;
for (auto& mime_type : af->launcher_mime_types())
mime_types.set(mime_type);
@ -94,7 +102,7 @@ void Launcher::load_handlers(ByteString const& af_dir)
for (auto& protocol : af->launcher_protocols())
protocols.set(protocol);
if (access(app_executable.characters(), X_OK) == 0)
m_handlers.set(app_executable, { Handler::Type::Default, app_name, app_executable, mime_types, file_types, protocols });
m_handlers.set(app_executable, { Handler::Type::Default, app_name, app_executable, move(app_arguments), mime_types, file_types, protocols });
},
af_dir);
}

View file

@ -24,6 +24,7 @@ struct Handler {
Type handler_type;
ByteString name;
ByteString executable;
Vector<ByteString> arguments;
HashTable<ByteString> mime_types {};
HashTable<ByteString> file_types {};
HashTable<ByteString> protocols {};