Skip to content

Commit

Permalink
LaunchServer: Use GUI::AppFile
Browse files Browse the repository at this point in the history
  • Loading branch information
linusg authored and awesomekling committed Dec 27, 2020
1 parent 616c217 commit bb1d52e
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 31 deletions.
2 changes: 1 addition & 1 deletion Services/LaunchServer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ set(SOURCES
)

serenity_bin(LaunchServer)
target_link_libraries(LaunchServer LibCore LibIPC)
target_link_libraries(LaunchServer LibCore LibIPC LibGUI)
41 changes: 13 additions & 28 deletions Services/LaunchServer/Launcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
#include <AK/LexicalPath.h>
#include <AK/StringBuilder.h>
#include <LibCore/ConfigFile.h>
#include <LibCore/DirIterator.h>
#include <LibGUI/AppFile.h>
#include <serenity.h>
#include <spawn.h>
#include <stdio.h>
Expand Down Expand Up @@ -97,33 +97,18 @@ Launcher& Launcher::the()

void Launcher::load_handlers(const String& af_dir)
{
auto load_hashtable = [](auto& af, auto& key) {
HashTable<String> 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<String> file_types;
for (auto& file_type : af->launcher_file_types())
file_types.set(file_type);
HashTable<String> 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)
Expand Down
3 changes: 2 additions & 1 deletion Services/LaunchServer/Launcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <AK/HashTable.h>
#include <AK/URL.h>
#include <LibCore/ConfigFile.h>
#include <LibGUI/AppFile.h>

namespace LaunchServer {

Expand All @@ -56,7 +57,7 @@ class Launcher {
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<String> handlers_for_url(const URL&);
Expand Down
2 changes: 1 addition & 1 deletion Services/LaunchServer/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit bb1d52e

Please sign in to comment.