From 3403b1fd77e9e9bd237e3d4d5174ca94a43b048b Mon Sep 17 00:00:00 2001 From: Andrew Kaster Date: Fri, 16 Sep 2022 04:01:25 -0600 Subject: [PATCH] Ladybird/WebView: Search for resources using installed location Reorganize the logic for initializing s_serenity_resource_root. Now, we initialize it in platform_init(), and move platform_init to the top of initialize_web_engine. Add a branch at the end of the function to check ``QApplication::applicationDirPath()`` for the location of the executable, and base the location of resources on that. In an installed configuration, this will be /some/path/bin, with the resource root set to /some/path/share/, looking for files in /some/path/share/res/resource-type. This matches up with some upcoming CMake changes to install resources in CMAKE_INSTALL_DATADIR. --- Ladybird/WebView.cpp | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/Ladybird/WebView.cpp b/Ladybird/WebView.cpp index 53bf19d21a..36a30b9a72 100644 --- a/Ladybird/WebView.cpp +++ b/Ladybird/WebView.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -53,6 +54,7 @@ #include #include #include +#include #include #include #include @@ -75,15 +77,7 @@ QString qstring_from_akstring(AK::String const& akstring) return QString::fromUtf8(akstring.characters(), akstring.length()); } -String s_serenity_resource_root = [] { - auto const* source_dir = getenv("SERENITY_SOURCE_DIR"); - if (source_dir) { - return String::formatted("{}/Base", source_dir); - } - auto* home = getenv("XDG_CONFIG_HOME") ?: getenv("HOME"); - VERIFY(home); - return String::formatted("{}/.lagom", home); -}(); +String s_serenity_resource_root; class HeadlessBrowserPageClient final : public Web::PageClient { public: @@ -777,19 +771,33 @@ static void platform_init() #ifdef AK_OS_ANDROID extern void android_platform_init(); android_platform_init(); +#else + s_serenity_resource_root = [] { + auto const* source_dir = getenv("SERENITY_SOURCE_DIR"); + if (source_dir) { + return String::formatted("{}/Base", source_dir); + } + auto* home = getenv("XDG_CONFIG_HOME") ?: getenv("HOME"); + VERIFY(home); + auto home_lagom = String::formatted("{}/.lagom", home); + if (Core::File::is_directory(home_lagom)) + return home_lagom; + auto app_dir = akstring_from_qstring(QApplication::applicationDirPath()); + return LexicalPath(app_dir).parent().append("share"sv).string(); + }(); #endif } void initialize_web_engine() { + platform_init(); + Web::Platform::EventLoopPlugin::install(*new Ladybird::EventLoopPluginQt); Web::Platform::ImageCodecPlugin::install(*new Ladybird::ImageCodecPluginLadybird); Web::ResourceLoader::initialize(RequestManagerQt::create()); Web::WebSockets::WebSocketClientManager::initialize(HeadlessWebSocketClientManager::create()); - platform_init(); - Web::FrameLoader::set_default_favicon_path(String::formatted("{}/res/icons/16x16/app-browser.png", s_serenity_resource_root)); Web::Platform::FontPlugin::install(*new Ladybird::FontPluginQt);