mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 14:17:36 +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:
parent
0a38d246f9
commit
3403b1fd77
1 changed files with 19 additions and 11 deletions
|
@ -18,6 +18,7 @@
|
||||||
#include <AK/ByteBuffer.h>
|
#include <AK/ByteBuffer.h>
|
||||||
#include <AK/Format.h>
|
#include <AK/Format.h>
|
||||||
#include <AK/HashTable.h>
|
#include <AK/HashTable.h>
|
||||||
|
#include <AK/LexicalPath.h>
|
||||||
#include <AK/NonnullOwnPtr.h>
|
#include <AK/NonnullOwnPtr.h>
|
||||||
#include <AK/StringBuilder.h>
|
#include <AK/StringBuilder.h>
|
||||||
#include <AK/Types.h>
|
#include <AK/Types.h>
|
||||||
|
@ -53,6 +54,7 @@
|
||||||
#include <LibWebSocket/ConnectionInfo.h>
|
#include <LibWebSocket/ConnectionInfo.h>
|
||||||
#include <LibWebSocket/Message.h>
|
#include <LibWebSocket/Message.h>
|
||||||
#include <LibWebSocket/WebSocket.h>
|
#include <LibWebSocket/WebSocket.h>
|
||||||
|
#include <QApplication>
|
||||||
#include <QCursor>
|
#include <QCursor>
|
||||||
#include <QIcon>
|
#include <QIcon>
|
||||||
#include <QLineEdit>
|
#include <QLineEdit>
|
||||||
|
@ -75,15 +77,7 @@ QString qstring_from_akstring(AK::String const& akstring)
|
||||||
return QString::fromUtf8(akstring.characters(), akstring.length());
|
return QString::fromUtf8(akstring.characters(), akstring.length());
|
||||||
}
|
}
|
||||||
|
|
||||||
String s_serenity_resource_root = [] {
|
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);
|
|
||||||
}();
|
|
||||||
|
|
||||||
class HeadlessBrowserPageClient final : public Web::PageClient {
|
class HeadlessBrowserPageClient final : public Web::PageClient {
|
||||||
public:
|
public:
|
||||||
|
@ -777,19 +771,33 @@ static void platform_init()
|
||||||
#ifdef AK_OS_ANDROID
|
#ifdef AK_OS_ANDROID
|
||||||
extern void android_platform_init();
|
extern void android_platform_init();
|
||||||
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
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void initialize_web_engine()
|
void initialize_web_engine()
|
||||||
{
|
{
|
||||||
|
platform_init();
|
||||||
|
|
||||||
Web::Platform::EventLoopPlugin::install(*new Ladybird::EventLoopPluginQt);
|
Web::Platform::EventLoopPlugin::install(*new Ladybird::EventLoopPluginQt);
|
||||||
Web::Platform::ImageCodecPlugin::install(*new Ladybird::ImageCodecPluginLadybird);
|
Web::Platform::ImageCodecPlugin::install(*new Ladybird::ImageCodecPluginLadybird);
|
||||||
|
|
||||||
Web::ResourceLoader::initialize(RequestManagerQt::create());
|
Web::ResourceLoader::initialize(RequestManagerQt::create());
|
||||||
Web::WebSockets::WebSocketClientManager::initialize(HeadlessWebSocketClientManager::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::FrameLoader::set_default_favicon_path(String::formatted("{}/res/icons/16x16/app-browser.png", s_serenity_resource_root));
|
||||||
|
|
||||||
Web::Platform::FontPlugin::install(*new Ladybird::FontPluginQt);
|
Web::Platform::FontPlugin::install(*new Ladybird::FontPluginQt);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue