FIX: [STUDIO-2631] call AddScriptMessageHandler queued

Change-Id: I6a71c2db3ed1b3d06931f53428a8d78881399b4d
This commit is contained in:
chunmao.guo 2023-04-06 16:18:23 +08:00 committed by Lane.Wei
parent e11c004de4
commit 0aea102bd3

View file

@ -128,6 +128,7 @@ class FakeWebView : public wxWebView
wxDEFINE_EVENT(EVT_WEBVIEW_RECREATED, wxCommandEvent); wxDEFINE_EVENT(EVT_WEBVIEW_RECREATED, wxCommandEvent);
static std::vector<wxWebView*> g_webviews; static std::vector<wxWebView*> g_webviews;
static std::vector<wxWebView*> g_delay_webviews;
class WebViewRef : public wxObjectRefData class WebViewRef : public wxObjectRefData
{ {
@ -193,16 +194,27 @@ wxWebView* WebView::CreateWebView(wxWindow * parent, wxString const & url)
WKWebView * wkWebView = (WKWebView *) webView->GetNativeBackend(); WKWebView * wkWebView = (WKWebView *) webView->GetNativeBackend();
Slic3r::GUI::WKWebView_setTransparentBackground(wkWebView); Slic3r::GUI::WKWebView_setTransparentBackground(wkWebView);
#endif #endif
#ifndef __WIN32__ auto addScriptMessageHandler = [] (wxWebView *webView) {
webView->CallAfter([webView] {
#endif
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ": begin to add script message handler for wx."; BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ": begin to add script message handler for wx.";
Slic3r::GUI::wxGetApp().set_adding_script_handler(true); Slic3r::GUI::wxGetApp().set_adding_script_handler(true);
if (!webView->AddScriptMessageHandler("wx")) if (!webView->AddScriptMessageHandler("wx"))
wxLogError("Could not add script message handler"); wxLogError("Could not add script message handler");
Slic3r::GUI::wxGetApp().set_adding_script_handler(false); Slic3r::GUI::wxGetApp().set_adding_script_handler(false);
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ": finished add script message handler for wx."; BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ": finished add script message handler for wx.";
};
#ifndef __WIN32__
webView->CallAfter([webView, addScriptMessageHandler] {
#endif
if (Slic3r::GUI::wxGetApp().is_adding_script_handler()) {
g_delay_webviews.push_back(webView);
} else {
addScriptMessageHandler(webView);
while (!g_delay_webviews.empty()) {
auto views = std::move(g_delay_webviews);
for (auto wv : views)
addScriptMessageHandler(wv);
}
}
#ifndef __WIN32__ #ifndef __WIN32__
}); });
#endif #endif