From 7d67d42606749cdbc4fe649a2eacb99b6f229bcc Mon Sep 17 00:00:00 2001 From: FlyAndNotDown Date: Tue, 12 Aug 2025 22:33:22 +0800 Subject: [PATCH 1/2] feat: add web ui start up log --- Editor/Include/Editor/WebUIServer.h | 8 +++- Editor/Src/WebUIServer.cpp | 63 +++++++++++++++++++++++------ Editor/Src/Widget/WebWidget.cpp | 15 ++----- 3 files changed, 61 insertions(+), 25 deletions(-) diff --git a/Editor/Include/Editor/WebUIServer.h b/Editor/Include/Editor/WebUIServer.h index 3cc795531..6b16f66da 100644 --- a/Editor/Include/Editor/WebUIServer.h +++ b/Editor/Include/Editor/WebUIServer.h @@ -16,9 +16,13 @@ namespace Editor { void Start(); void Stop(); + const std::string& BaseUrl() const; private: - Common::UniquePtr serverThread; - Common::UniquePtr server; + WebUIServer(); + + std::string baseUrl; + Common::UniquePtr productServerThread; + Common::UniquePtr productServer; }; } diff --git a/Editor/Src/WebUIServer.cpp b/Editor/Src/WebUIServer.cpp index e9c3e33b1..fed37f041 100644 --- a/Editor/Src/WebUIServer.cpp +++ b/Editor/Src/WebUIServer.cpp @@ -2,13 +2,22 @@ // Created by johnk on 2025/8/8. // -#include #include +#include +#include static Core::CmdlineArgValue caWebUIPort( "webUIPort", "-webUIPort", 10907, "WebUI port"); +static Core::CmdlineArgValue caWebUIDev( + "webUIDev", "-webUIDev", false, + "Whether to enable hot reload for web UI"); + +static Core::CmdlineArgValue caWebUIDevServerPort( + "webUIDevServerPort", "-webUIDevServerPort", 5173, + "Port of web ui dev server, which works only when dev mode enabled"); + namespace Editor { WebUIServer& WebUIServer::Get() { @@ -16,23 +25,53 @@ namespace Editor { return webUIServer; } + WebUIServer::WebUIServer() = default; + void WebUIServer::Start() { - serverThread = std::make_unique("WebUIServerThread", [this]() -> void { - server = Common::MakeUnique(); - server->set_mount_point("/", "./Web"); - server->Get("/(.+)", [](const httplib::Request&, httplib::Response& res) { - res.set_file_content("./Web/index.html"); + uint32_t serverPort; + std::string serverMode; + + if (caWebUIDev.GetValue()) { + serverPort = caWebUIDevServerPort.GetValue(); + serverMode = "development"; + + httplib::Client client(std::format("http://localhost:{}", serverPort)); + auto res = client.Get("/"); + AssertWithReason( + res->status == 200, + "did you forget to start dev server, just call Script/start_editor_web_dev_server.py manually"); + } else { + serverPort = caWebUIPort.GetValue(); + serverMode = "product"; + productServerThread = std::make_unique("WebUIServerThread", [this, serverPort]() -> void { + productServer = Common::MakeUnique(); + productServer->set_mount_point("/", "./Web"); + productServer->Get("/(.+)", [](const httplib::Request&, httplib::Response& res) { + res.set_file_content("./Web/index.html"); + }); + productServer->listen("localhost", static_cast(serverPort)); }); - server->listen("localhost", caWebUIPort.GetValue()); - }); + } + + baseUrl = std::format("http://localhost:{}", serverPort); + LogInfo(WebUI, "{} web ui server listening on {}", serverMode, baseUrl); } void WebUIServer::Stop() { - server->stop(); - serverThread->Join(); - server.Reset(); - serverThread.Reset(); + if (productServer.Valid()) { + productServer->stop(); + } + if (productServerThread.Valid()) { + productServerThread->Join(); + } + productServer.Reset(); + productServerThread.Reset(); + } + + const std::string& WebUIServer::BaseUrl() const + { + return baseUrl; } } // namespace Editor diff --git a/Editor/Src/Widget/WebWidget.cpp b/Editor/Src/Widget/WebWidget.cpp index a3de910cc..569325e97 100644 --- a/Editor/Src/Widget/WebWidget.cpp +++ b/Editor/Src/Widget/WebWidget.cpp @@ -3,16 +3,9 @@ // #include -#include #include - -static Core::CmdlineArgValue caWebUIDev( - "webUIDev", "-webUIDev", false, - "Whether to enable hot reload for web UI"); - -static Core::CmdlineArgValue caWebUIDevServerPort( - "webUIDevServerPort", "-webUIDevServerPort", 5173, - "Port of web ui dev server, which works only when dev mode enabled"); +#include +#include namespace Editor { WebWidget::WebWidget(QWidget* inParent) @@ -29,8 +22,8 @@ namespace Editor { 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()); - const std::string fullUrl = baseUrl + inUrl; + const auto& baseUrl = WebUIServer::Get().BaseUrl(); + const auto fullUrl = baseUrl + inUrl; load(QUrl(fullUrl.c_str())); } From e5f538efb52fb17afabf90edc40bf4155833d388 Mon Sep 17 00:00:00 2001 From: FlyAndNotDown Date: Tue, 12 Aug 2025 22:38:54 +0800 Subject: [PATCH 2/2] feat: disable qt default application proxy --- Editor/Src/Main.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Editor/Src/Main.cpp b/Editor/Src/Main.cpp index 4067fa41e..ce5eb0c5c 100644 --- a/Editor/Src/Main.cpp +++ b/Editor/Src/Main.cpp @@ -3,6 +3,7 @@ // #include +#include #include #include @@ -73,7 +74,10 @@ static void InitializePreQtApp(EditorApplicationModel inModel) Runtime::EngineHolder::Load("Editor", params); } -static void InitializePostQtApp() {} +static void InitializePostQtApp() +{ + QNetworkProxy::setApplicationProxy(QNetworkProxy::NoProxy); +} static void Cleanup(EditorApplicationModel inModel) {