This commit is contained in:
SoftFever
2026-01-26 20:12:55 +08:00
parent 3ed07d5f9b
commit e93f50702e
9 changed files with 24 additions and 234 deletions

View File

@@ -264,15 +264,10 @@ void ZUserLogin::OnFullScreenChanged(wxWebViewEvent &evt)
void ZUserLogin::OnScriptMessage(wxWebViewEvent &evt)
{
wxString str_input = evt.GetString();
BOOST_LOG_TRIVIAL(debug) << "[WebUserLoginDialog] OnScriptMessage received: " << str_input.ToStdString();
try {
json j = json::parse(into_u8(str_input));
BOOST_LOG_TRIVIAL(debug) << "[WebUserLoginDialog] Parsed JSON successfully";
wxString strCmd = j["command"];
BOOST_LOG_TRIVIAL(debug) << "[WebUserLoginDialog] Command: " << strCmd.ToStdString();
NetworkAgent* agent = wxGetApp().getAgent();
if (agent && strCmd == "get_login_cmd" && agent->get_cloud_agent()) {
@@ -323,30 +318,21 @@ void ZUserLogin::OnScriptMessage(wxWebViewEvent &evt)
if (strCmd == "autotest_token")
{
m_AutotestToken = j["data"]["token"];
BOOST_LOG_TRIVIAL(debug) << "[WebUserLoginDialog] Stored autotest_token";
}
if (strCmd == "user_login") {
BOOST_LOG_TRIVIAL(debug) << "[WebUserLoginDialog] Processing user_login command";
BOOST_LOG_TRIVIAL(debug) << "[WebUserLoginDialog] User data: " << j["data"].dump();
j["data"]["autotest_token"] = m_AutotestToken;
std::string message_json = j.dump();
BOOST_LOG_TRIVIAL(debug) << "[WebUserLoginDialog] Calling handle_script_message with: " << message_json;
// End modal dialog first to unblock event loop before processing callbacks
BOOST_LOG_TRIVIAL(debug) << "[WebUserLoginDialog] Ending modal dialog";
EndModal(wxID_OK);
// Handle message after modal dialog ends to avoid deadlock
// Use wxTheApp->CallAfter to ensure it runs after modal loop exits
wxTheApp->CallAfter([message_json]() {
BOOST_LOG_TRIVIAL(debug) << "[WebUserLoginDialog] Processing login message after modal ended";
wxGetApp().handle_script_message(message_json);
});
}
else if (strCmd == "get_localhost_url") {
BOOST_LOG_TRIVIAL(debug) << "thirdparty_login: get_localhost_url";
int loopback_port = m_loopback_port > 0 ? m_loopback_port : LOCALHOST_PORT;
wxGetApp().start_http_server(loopback_port);
std::string sequence_id = j["sequence_id"].get<std::string>();
@@ -362,7 +348,6 @@ void ZUserLogin::OnScriptMessage(wxWebViewEvent &evt)
});
}
else if (strCmd == "thirdparty_login") {
BOOST_LOG_TRIVIAL(info) << "thirdparty_login: thirdparty_login";
if (j["data"].contains("url")) {
std::string jump_url = j["data"]["url"].get<std::string>();
int loopback_port = m_loopback_port > 0 ? m_loopback_port : LOCALHOST_PORT;