diff --git a/Services/LaunchServer/CMakeLists.txt b/Services/LaunchServer/CMakeLists.txt index b51a413b12..997a72775e 100644 --- a/Services/LaunchServer/CMakeLists.txt +++ b/Services/LaunchServer/CMakeLists.txt @@ -10,4 +10,4 @@ set(SOURCES ) serenity_bin(LaunchServer) -target_link_libraries(LaunchServer LibCore LibIPC) +target_link_libraries(LaunchServer LibCore LibIPC LibGUI) diff --git a/Services/LaunchServer/Launcher.cpp b/Services/LaunchServer/Launcher.cpp index 35bd24bcdf..292cd0daee 100644 --- a/Services/LaunchServer/Launcher.cpp +++ b/Services/LaunchServer/Launcher.cpp @@ -32,7 +32,7 @@ #include #include #include -#include +#include #include #include #include @@ -97,33 +97,18 @@ Launcher& Launcher::the() void Launcher::load_handlers(const String& af_dir) { - auto load_hashtable = [](auto& af, auto& key) { - HashTable table; - - auto config_value = af->read_entry("Launcher", key, {}); - for (auto& entry : config_value.split(',')) { - auto key = entry.trim_whitespace().to_lowercase(); - if (key.is_empty()) - continue; - table.set(key); - } - - return table; - }; - - Core::DirIterator dt(af_dir, Core::DirIterator::SkipDots); - while (dt.has_next()) { - auto af_name = dt.next_path(); - auto af_path = String::format("%s/%s", af_dir.characters(), af_name.characters()); - auto af = Core::ConfigFile::open(af_path); - if (!af->has_key("App", "Name") || !af->has_key("App", "Executable")) - continue; - auto app_name = af->read_entry("App", "Name"); - auto app_executable = af->read_entry("App", "Executable"); - auto file_types = load_hashtable(af, "FileTypes"); - auto protocols = load_hashtable(af, "Protocols"); - m_handlers.set(app_executable, { Handler::Type::Default, move(app_name), app_executable, move(file_types), move(protocols) }); - } + GUI::AppFile::for_each([&](auto af) { + auto app_name = af->name(); + auto app_executable = af->executable(); + HashTable file_types; + for (auto& file_type : af->launcher_file_types()) + file_types.set(file_type); + HashTable protocols; + for (auto& protocol : af->launcher_protocols()) + protocols.set(protocol); + m_handlers.set(app_executable, { Handler::Type::Default, app_name, app_executable, file_types, protocols }); + }, + af_dir); } void Launcher::load_config(const Core::ConfigFile& cfg) diff --git a/Services/LaunchServer/Launcher.h b/Services/LaunchServer/Launcher.h index 7f64e66bb1..745f72342e 100644 --- a/Services/LaunchServer/Launcher.h +++ b/Services/LaunchServer/Launcher.h @@ -30,6 +30,7 @@ #include #include #include +#include namespace LaunchServer { @@ -56,7 +57,7 @@ public: Launcher(); static Launcher& the(); - void load_handlers(const String& af_dir); + void load_handlers(const String& af_dir = GUI::AppFile::APP_FILES_DIRECTORY); void load_config(const Core::ConfigFile&); bool open_url(const URL&, const String& handler_name); Vector handlers_for_url(const URL&); diff --git a/Services/LaunchServer/main.cpp b/Services/LaunchServer/main.cpp index af647292c9..b88a49fe8b 100644 --- a/Services/LaunchServer/main.cpp +++ b/Services/LaunchServer/main.cpp @@ -39,7 +39,7 @@ int main([[maybe_unused]] int argc, [[maybe_unused]] char** argv) auto launcher = LaunchServer::Launcher(); - launcher.load_handlers("/res/apps"); + launcher.load_handlers(); launcher.load_config(Core::ConfigFile::get_for_app("LaunchServer")); if (pledge("stdio accept rpath proc exec", nullptr) < 0) {