forked from ExplosionEngine/Explosion
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathWebWidget.cpp
More file actions
41 lines (33 loc) · 1.23 KB
/
WebWidget.cpp
File metadata and controls
41 lines (33 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
//
// Created by johnk on 2025/8/9.
//
#include <Editor/Widget/WebWidget.h>
#include <Core/Cmdline.h>
#include <Editor/Widget/moc_WebWidget.cpp>
static Core::CmdlineArgValue<bool> caWebUIDev(
"webUIDev", "-webUIDev", false,
"Whether to enable hot reload for web UI");
static Core::CmdlineArgValue<uint32_t> caWebUIDevServerPort(
"webUIDevServerPort", "-webUIDevServerPort", 5173,
"Port of web ui dev server, which works only when dev mode enabled");
namespace Editor {
WebWidget::WebWidget(QWidget* inParent)
: QWebEngineView(inParent)
{
webChannel = new QWebChannel(this);
page()->setWebChannel(webChannel);
}
WebWidget::~WebWidget() = default;
void WebWidget::Load(const std::string& inUrl)
{
static Core::CmdlineArg& caWebUIPort = Core::Cli::Get().GetArg("webUIPort");
Assert(inUrl.starts_with("/"));
const std::string baseUrl = std::format("http://localhost:{}", caWebUIDev.GetValue() ? caWebUIDevServerPort.GetValue() : caWebUIPort.GetValue<uint32_t>());
const std::string fullUrl = baseUrl + inUrl;
load(QUrl(fullUrl.c_str()));
}
QWebChannel* WebWidget::GetWebChannel() const
{
return webChannel;
}
} // namespace Editor