1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 04:08:11 +00:00

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.
This commit is contained in:
Andrew Kaster 2022-09-16 04:01:25 -06:00
parent 0a38d246f9
commit 3403b1fd77

View file

@ -18,6 +18,7 @@
#include <AK/ByteBuffer.h>
#include <AK/Format.h>
#include <AK/HashTable.h>
#include <AK/LexicalPath.h>
#include <AK/NonnullOwnPtr.h>
#include <AK/StringBuilder.h>
#include <AK/Types.h>
@ -53,6 +54,7 @@
#include <LibWebSocket/ConnectionInfo.h>
#include <LibWebSocket/Message.h>
#include <LibWebSocket/WebSocket.h>
#include <QApplication>
#include <QCursor>
#include <QIcon>
#include <QLineEdit>
@ -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);