mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 04:12:43 +00:00 
			
		
		
		
	 5e1499d104
			
		
	
	
		5e1499d104
		
	
	
	
	
		
			
			This commit un-deprecates DeprecatedString, and repurposes it as a byte
string.
As the null state has already been removed, there are no other
particularly hairy blockers in repurposing this type as a byte string
(what it _really_ is).
This commit is auto-generated:
  $ xs=$(ack -l \bDeprecatedString\b\|deprecated_string AK Userland \
    Meta Ports Ladybird Tests Kernel)
  $ perl -pie 's/\bDeprecatedString\b/ByteString/g;
    s/deprecated_string/byte_string/g' $xs
  $ clang-format --style=file -i \
    $(git diff --name-only | grep \.cpp\|\.h)
  $ gn format $(git ls-files '*.gn' '*.gni')
		
	
			
		
			
				
	
	
		
			62 lines
		
	
	
	
		
			2.1 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			62 lines
		
	
	
	
		
			2.1 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
| /*
 | |
|  * Copyright (c) 2020, Nicholas Hollett <niax@niax.co.uk>
 | |
|  *
 | |
|  * SPDX-License-Identifier: BSD-2-Clause
 | |
|  */
 | |
| 
 | |
| #pragma once
 | |
| 
 | |
| #include <AK/HashMap.h>
 | |
| #include <AK/HashTable.h>
 | |
| #include <AK/URL.h>
 | |
| #include <LibCore/ConfigFile.h>
 | |
| #include <LibDesktop/AppFile.h>
 | |
| 
 | |
| namespace LaunchServer {
 | |
| 
 | |
| struct Handler {
 | |
|     enum class Type {
 | |
|         Default = 0,
 | |
|         Application,
 | |
|         UserPreferred,
 | |
|         UserDefault
 | |
|     };
 | |
|     Type handler_type;
 | |
|     ByteString name;
 | |
|     ByteString executable;
 | |
|     HashTable<ByteString> mime_types {};
 | |
|     HashTable<ByteString> file_types {};
 | |
|     HashTable<ByteString> protocols {};
 | |
| 
 | |
|     static ByteString name_from_executable(StringView);
 | |
|     void from_executable(Type, ByteString const&);
 | |
|     ByteString to_details_str() const;
 | |
| };
 | |
| 
 | |
| class Launcher {
 | |
| public:
 | |
|     Launcher();
 | |
|     static Launcher& the();
 | |
| 
 | |
|     void load_handlers(ByteString const& af_dir = Desktop::AppFile::APP_FILES_DIRECTORY);
 | |
|     void load_config(Core::ConfigFile const&);
 | |
|     bool open_url(const URL&, ByteString const& handler_name);
 | |
|     Vector<ByteString> handlers_for_url(const URL&);
 | |
|     Vector<ByteString> handlers_with_details_for_url(const URL&);
 | |
| 
 | |
| private:
 | |
|     HashMap<ByteString, Handler> m_handlers;
 | |
|     HashMap<ByteString, ByteString> m_protocol_handlers;
 | |
|     HashMap<ByteString, ByteString> m_file_handlers;
 | |
|     HashMap<ByteString, ByteString> m_mime_handlers;
 | |
| 
 | |
|     bool has_mime_handlers(ByteString const&);
 | |
|     Optional<StringView> mime_type_for_file(ByteString path);
 | |
|     Handler get_handler_for_executable(Handler::Type, ByteString const&) const;
 | |
|     size_t for_each_handler(ByteString const& key, HashMap<ByteString, ByteString> const& user_preferences, Function<bool(Handler const&)> f);
 | |
|     void for_each_handler_for_path(ByteString const&, Function<bool(Handler const&)> f);
 | |
|     bool open_file_url(const URL&);
 | |
|     bool open_with_user_preferences(HashMap<ByteString, ByteString> const& user_preferences, ByteString const& key, Vector<ByteString> const& arguments, ByteString const& default_program = {});
 | |
|     bool open_with_handler_name(const URL&, ByteString const& handler_name);
 | |
| };
 | |
| }
 |