/* * Copyright (c) 2020, Nicholas Hollett * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include #include #include namespace LaunchServer { struct Handler { enum class Type { Default = 0, Application, UserPreferred, UserDefault }; Type handler_type; String name; String executable; HashTable file_types {}; HashTable protocols {}; static String name_from_executable(const StringView&); void from_executable(Type, const String&); String to_details_str() const; }; class Launcher { public: Launcher(); static Launcher& the(); void load_handlers(const String& af_dir = Desktop::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&); Vector handlers_with_details_for_url(const URL&); private: HashMap m_handlers; HashMap m_protocol_handlers; HashMap m_file_handlers; Handler get_handler_for_executable(Handler::Type, const String&) const; void for_each_handler(const String& key, HashMap& user_preferences, Function f); void for_each_handler_for_path(const String&, Function f); bool open_file_url(const URL&); bool open_with_user_preferences(const HashMap& user_preferences, const String& key, const Vector& arguments, const String& default_program = {}); bool open_with_handler_name(const URL&, const String& handler_name); }; }