ENH: First Load MWWebPage When User Click OnlineModel Menu

JIRA: none
Change-Id: Id858dd80ae5b24bdb1e939e6a47099983f6bf4df
(cherry picked from commit 5a62a5236fc767283e4360e0b95bb85c18c5cf8e)
(cherry picked from commit 5730141311e2da20551fd811a9349f2b88c5c1b1)
This commit is contained in:
zorro.zhang 2024-06-20 11:33:09 +08:00 committed by Lane.Wei
parent 004fd02b2d
commit 294e60b80c
2 changed files with 59 additions and 69 deletions

View File

@ -36,6 +36,7 @@ WebViewPanel::WebViewPanel(wxWindow *parent)
: wxPanel(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize) : wxPanel(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize)
{ {
m_Region = wxGetApp().app_config->get_country_code(); m_Region = wxGetApp().app_config->get_country_code();
m_loginstatus = -1;
wxString UrlLeft = wxString::Format("file://%s/web/homepage3/left.html", from_u8(resources_dir())); wxString UrlLeft = wxString::Format("file://%s/web/homepage3/left.html", from_u8(resources_dir()));
wxString UrlRight = wxString::Format("file://%s/web/homepage3/home.html", from_u8(resources_dir())); wxString UrlRight = wxString::Format("file://%s/web/homepage3/home.html", from_u8(resources_dir()));
@ -98,21 +99,18 @@ WebViewPanel::WebViewPanel(wxWindow *parent)
wxLogError("Could not init m_browser"); wxLogError("Could not init m_browser");
return; return;
} }
m_onlinefirst = false;
m_online_spec_id = "";
auto host = wxGetApp().get_model_http_url(wxGetApp().app_config->get_country_code()); m_browserMW = WebView::CreateWebView(this, "about:blank");
std::string mwurl = (boost::format("%1%studio/webview?from=bambustudio") % host ).str();
m_browserMW = WebView::CreateWebView(this, mwurl);
if (m_browserMW == nullptr) { if (m_browserMW == nullptr) {
wxLogError("Could not init m_browserMW"); wxLogError("Could not init m_browserMW");
return; return;
} }
m_browserMW->Hide(); m_browserMW->Hide();
SetMakerworldModelID("");
m_onlinefirst = false;
m_leftfirst = false; m_leftfirst = false;
m_browserLeft = WebView::CreateWebView(this, UrlLeft); m_browserLeft = WebView::CreateWebView(this, UrlLeft);
//m_browserLeft = WebView::CreateWebView(this, "https://www.163.com");
if (m_browserLeft == nullptr) { if (m_browserLeft == nullptr) {
wxLogError("Could not init m_browser"); wxLogError("Could not init m_browser");
return; return;
@ -288,10 +286,8 @@ void WebViewPanel::ResetWholePage()
RunScript(strJS); RunScript(strJS);
//online //online
m_online_spec_id = ""; SetMakerworldModelID("");
auto host = wxGetApp().get_model_http_url(wxGetApp().app_config->get_country_code()); m_onlinefirst = false;
std::string mwurl = (boost::format("%1%studio/webview?from=bambustudio") % host).str();
m_browserMW->LoadURL(mwurl);
} }
void WebViewPanel::load_url(wxString& url) void WebViewPanel::load_url(wxString& url)
@ -477,8 +473,6 @@ void WebViewPanel::OnClose(wxCloseEvent& evt)
void WebViewPanel::OnFreshLoginStatus(wxTimerEvent &event) void WebViewPanel::OnFreshLoginStatus(wxTimerEvent &event)
{ {
static int loginstatus = -1;
//wxString mwnow = m_browserMW->GetCurrentURL(); //wxString mwnow = m_browserMW->GetCurrentURL();
auto mainframe = Slic3r::GUI::wxGetApp().mainframe; auto mainframe = Slic3r::GUI::wxGetApp().mainframe;
@ -486,17 +480,19 @@ void WebViewPanel::OnFreshLoginStatus(wxTimerEvent &event)
Slic3r::GUI::wxGetApp().get_login_info(); Slic3r::GUI::wxGetApp().get_login_info();
if (wxGetApp().is_user_login()) { if (wxGetApp().is_user_login()) {
if (loginstatus != 1) if (m_loginstatus != 1)
{ {
loginstatus = 1; m_loginstatus = 1;
UpdateMakerworldLoginStatus(); if (m_onlinefirst)
UpdateMakerworldLoginStatus();
} }
} else { } else {
if (loginstatus != 0) { if (m_loginstatus != 0) {
loginstatus = 0; m_loginstatus = 0;
SetMakerworldPageLoginStatus(false); if (m_onlinefirst)
SetMakerworldPageLoginStatus(false);
} }
} }
} }
@ -667,7 +663,7 @@ void WebViewPanel::OpenModelDetail(std::string id, NetworkAgent *agent)
{ {
SwitchLeftMenu("online"); SwitchLeftMenu("online");
m_online_spec_id = id; SetMakerworldModelID(id);
} }
@ -811,16 +807,8 @@ void WebViewPanel::SetMakerworldPageLoginStatus(bool login ,wxString ticket)
if (m_browserMW == nullptr) return; if (m_browserMW == nullptr) return;
wxString mw_currenturl; wxString mw_currenturl;
if (m_online_spec_id != "") { if (m_online_LastUrl != "") {
auto host = wxGetApp().get_model_http_url(wxGetApp().app_config->get_country_code()); mw_currenturl = m_online_LastUrl;
wxString language_code = wxGetApp().current_language_code().BeforeFirst('_');
language_code = language_code.ToStdString();
mw_currenturl = (boost::format("%1%%2%/studio/webview?modelid=%3%&from=%4%") % host % language_code.mb_str() % m_online_spec_id % m_online_type.mb_str()).str();
m_onlinefirst = true;
m_online_spec_id = "";
} else { } else {
mw_currenturl = m_browserMW->GetCurrentURL(); mw_currenturl = m_browserMW->GetCurrentURL();
mw_currenturl.Replace("modelid=", ""); mw_currenturl.Replace("modelid=", "");
@ -830,8 +818,10 @@ void WebViewPanel::SetMakerworldPageLoginStatus(bool login ,wxString ticket)
wxString mw_jumpurl = ""; wxString mw_jumpurl = "";
bool b = GetJumpUrl(login, ticket, mw_currenturl, mw_jumpurl); bool b = GetJumpUrl(login, ticket, mw_currenturl, mw_jumpurl);
if (b) if (b) {
m_browserMW->LoadURL(mw_jumpurl); m_browserMW->LoadURL(mw_jumpurl);
m_online_LastUrl = "";
}
} }
@ -935,11 +925,11 @@ void WebViewPanel::OnNavigationRequest(wxWebViewEvent& evt)
void WebViewPanel::OnNavigationComplete(wxWebViewEvent& evt) void WebViewPanel::OnNavigationComplete(wxWebViewEvent& evt)
{ {
if (m_browserMW!=nullptr && evt.GetId() == m_browserMW->GetId()) if (m_browserMW!=nullptr && evt.GetId() == m_browserMW->GetId())
{ {
auto host = wxGetApp().get_model_http_url(wxGetApp().app_config->get_country_code()); std::string TmpNowUrl = m_browserMW->GetCurrentURL().ToStdString();
if(m_browserMW->GetCurrentURL().Contains(host)) std::string mwHost = wxGetApp().get_model_http_url(wxGetApp().app_config->get_country_code());
m_onlinefirst = true; if (TmpNowUrl.find(mwHost) != std::string::npos) m_onlinefirst = true;
if (m_contentname == "online") { // conf save if (m_contentname == "online") { // conf save
SetWebviewShow("right", false); SetWebviewShow("right", false);
SetWebviewShow("online", true); SetWebviewShow("online", true);
@ -1246,6 +1236,8 @@ void WebViewPanel::OnSelectAll(wxCommandEvent& WXUNUSED(evt))
*/ */
void WebViewPanel::OnError(wxWebViewEvent& evt) void WebViewPanel::OnError(wxWebViewEvent& evt)
{ {
BOOST_LOG_TRIVIAL(info) << "HomePage OnError, Url = " << evt.GetURL() << " , Message: "<<evt.GetString();
#define WX_ERROR_CASE(type) \ #define WX_ERROR_CASE(type) \
case type: \ case type: \
category = #type; \ category = #type; \
@ -1275,8 +1267,7 @@ void WebViewPanel::OnError(wxWebViewEvent& evt)
//m_info->ShowMessage(_L("An error occurred loading ") + evt.GetURL() + "\n" + "'" + category + "'", wxICON_ERROR); //m_info->ShowMessage(_L("An error occurred loading ") + evt.GetURL() + "\n" + "'" + category + "'", wxICON_ERROR);
if (evt.GetInt() == wxWEBVIEW_NAV_ERR_CONNECTION && evt.GetId() == m_browserMW->GetId()) if (evt.GetInt() == wxWEBVIEW_NAV_ERR_CONNECTION && evt.GetId() == m_browserMW->GetId())
{ {
m_onlinefirst = false;
m_online_LastUrl = m_browserMW->GetCurrentURL(); m_online_LastUrl = m_browserMW->GetCurrentURL();
if (m_contentname == "online") if (m_contentname == "online")
@ -1300,6 +1291,19 @@ void WebViewPanel::OnError(wxWebViewEvent& evt)
UpdateState(); UpdateState();
} }
void WebViewPanel::SetMakerworldModelID(std::string ModelID)
{
auto host = wxGetApp().get_model_http_url(wxGetApp().app_config->get_country_code());
wxString language_code = wxGetApp().current_language_code().BeforeFirst('_');
language_code = language_code.ToStdString();
if (ModelID != "")
m_online_LastUrl = (boost::format("%1%%2%/studio/webview?modelid=%3%&from=bambustudio") % host % language_code.mb_str() % ModelID).str();
else
m_online_LastUrl = (boost::format("%1%%2%/studio/webview?from=bambustudio") % host % language_code.mb_str()).str();
}
void WebViewPanel::SwitchWebContent(std::string modelname, int refresh) void WebViewPanel::SwitchWebContent(std::string modelname, int refresh)
{ {
m_contentname = modelname; m_contentname = modelname;
@ -1329,41 +1333,26 @@ void WebViewPanel::SwitchWebContent(std::string modelname, int refresh)
return; return;
} else if (modelname.compare("online") == 0) { } else if (modelname.compare("online") == 0) {
if (m_online_spec_id != "") {
auto host = wxGetApp().get_model_http_url(wxGetApp().app_config->get_country_code());
wxString language_code = wxGetApp().current_language_code().BeforeFirst('_'); if (!m_onlinefirst) {
language_code = language_code.ToStdString(); if (m_loginstatus == 1) {
UpdateMakerworldLoginStatus();
std::string mwurl = (boost::format("%1%%2%/studio/webview?modelid=%3%&from=%4%") % host % language_code.mb_str() % m_online_spec_id % m_online_type.mb_str()).str();
m_onlinefirst = true;
m_browserMW->LoadURL(mwurl);
SetWebviewShow("online", true);
SetWebviewShow("right", false);
m_online_spec_id = "";
} else {
if (m_onlinefirst == false) {
refresh = 1; // Force Refresh
if (m_online_LastUrl != "") {
m_browserMW->LoadURL(m_online_LastUrl);
m_online_LastUrl = "";
}
else
m_browserMW->Reload();
} else { } else {
if (refresh == 1) SetMakerworldPageLoginStatus(false);
m_browserMW->Reload(); }
else { } else {
SetWebviewShow("online", true); if (m_online_LastUrl != "") {
SetWebviewShow("right", false); m_browserMW->LoadURL(m_online_LastUrl);
}
m_online_LastUrl = "";
} else {
//m_browserMW->Reload();
} }
} }
SetWebviewShow("online", true);
SetWebviewShow("right", false);
GetSizer()->Layout(); GetSizer()->Layout();
// conf save // conf save

View File

@ -96,7 +96,7 @@ public:
public: public:
void ResetWholePage(); void ResetWholePage();
void SetMakerworldModelID(std::string ModelID) { m_online_spec_id = ModelID; } void SetMakerworldModelID(std::string ModelID);
void SwitchWebContent(std::string modelname, int refresh=0); void SwitchWebContent(std::string modelname, int refresh=0);
void SwitchLeftMenu(std::string strMenu); void SwitchLeftMenu(std::string strMenu);
void OpenOneMakerlab(std::string url); void OpenOneMakerlab(std::string url);
@ -131,6 +131,7 @@ private:
wxBoxSizer *topsizer; wxBoxSizer *topsizer;
int m_loginstatus;
wxBoxSizer* m_home_web; wxBoxSizer* m_home_web;
wxWebView* m_browser; wxWebView* m_browser;
wxWebView* m_browserLeft; wxWebView* m_browserLeft;
@ -138,7 +139,7 @@ private:
std::string m_contentname; std::string m_contentname;
bool m_leftfirst; //Left First Loaded bool m_leftfirst; //Left First Loaded
bool m_onlinefirst; //Online Page First Load bool m_onlinefirst; //Online Page First Load
std::string m_online_spec_id; //Online Page Spec_ID //std::string m_online_spec_id; // Online Page Spec_ID
wxString m_online_type; //recommend & browse wxString m_online_type; //recommend & browse
wxString m_online_LastUrl; //PageLastError Url wxString m_online_LastUrl; //PageLastError Url