From 5ac94944836f79b1564b2255eaa3441bfca6ba83 Mon Sep 17 00:00:00 2001 From: bitwitch Date: Mon, 21 Jun 2021 15:16:09 -0400 Subject: [PATCH] LaunchServer: Make all file handlers configurable including directories This commit gets rid of hard coded file handlers in Launcher.cpp in favor of using values in the LaunchServer.ini config file. The previous commit adds checks for the existence of handler programs while registering handlers. This commit takes advantage of that and ensures that LaunchServer will not attempt to open a file with a nonexistent program and can properly report failure before spawning a new child process. Resolves #8120 --- Base/home/anon/.config/LaunchServer.ini | 1 + Userland/Services/LaunchServer/Launcher.cpp | 28 ++++++++++++++------- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/Base/home/anon/.config/LaunchServer.ini b/Base/home/anon/.config/LaunchServer.ini index afa150f254..3307da38ae 100644 --- a/Base/home/anon/.config/LaunchServer.ini +++ b/Base/home/anon/.config/LaunchServer.ini @@ -17,6 +17,7 @@ font=/bin/FontEditor sheets=/bin/Spreadsheet gml=/bin/Playground pdf=/bin/PDFViewer +directory=/bin/FileManager *=/bin/TextEditor [Protocol] diff --git a/Userland/Services/LaunchServer/Launcher.cpp b/Userland/Services/LaunchServer/Launcher.cpp index ed3baa0fd1..1d3c39e748 100644 --- a/Userland/Services/LaunchServer/Launcher.cpp +++ b/Userland/Services/LaunchServer/Launcher.cpp @@ -257,9 +257,12 @@ void Launcher::for_each_handler_for_path(const String& path, Function fm_arguments; if (url.fragment().is_empty()) { @@ -293,7 +295,13 @@ bool Launcher::open_file_url(const URL& url) fm_arguments.append("-r"); fm_arguments.append(String::formatted("{}/{}", url.path(), url.fragment())); } - return spawn("/bin/FileManager", fm_arguments); + + auto handler_optional = m_file_handlers.get("directory"); + if (!handler_optional.has_value()) + return false; + auto& handler = handler_optional.value(); + + return spawn(handler, fm_arguments); } if ((st.st_mode & S_IFMT) == S_IFREG && st.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH)) @@ -304,7 +312,12 @@ bool Launcher::open_file_url(const URL& url) if (extension_parts.size() > 1) extension = extension_parts.last(); - // Additional parameters parsing, specific for the file protocol and TextEditor + auto handler_optional = m_file_handlers.get("txt"); + if (!handler_optional.has_value()) + return false; + auto& default_handler = handler_optional.value(); + + // Additional parameters parsing, specific for the file protocol and txt file handlers Vector additional_parameters; String filepath = url.path(); @@ -318,9 +331,6 @@ bool Launcher::open_file_url(const URL& url) filepath = String::formatted("{}:{}", filepath, line.value()); } } - - additional_parameters.append(filepath); - - return open_with_user_preferences(m_file_handlers, extension, additional_parameters, "/bin/TextEditor"); + return open_with_user_preferences(m_file_handlers, extension, additional_parameters, default_handler); } }