mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-09-23 08:53:05 +00:00
fix: startup crash on macOS when a printer has a print host set (#14747)
This commit is contained in:
@@ -242,8 +242,15 @@ public:
|
||||
g_webviews.erase(iter);
|
||||
}
|
||||
wxWebView *m_webView;
|
||||
// Guards against registering the "wx" handler twice (a duplicate throws on WKWebView).
|
||||
bool m_script_handler_added = false;
|
||||
};
|
||||
|
||||
static WebViewRef *webview_ref(wxWebView *webView)
|
||||
{
|
||||
return webView ? static_cast<WebViewRef *>(webView->GetRefData()) : nullptr;
|
||||
}
|
||||
|
||||
wxWebView* WebView::CreateWebView(wxWindow * parent, wxString const & url)
|
||||
{
|
||||
#if wxUSE_WEBVIEW_EDGE
|
||||
@@ -304,10 +311,17 @@ wxWebView* WebView::CreateWebView(wxWindow * parent, wxString const & url)
|
||||
Slic3r::GUI::WKWebView_setTransparentBackground(wkWebView);
|
||||
#endif
|
||||
auto addScriptMessageHandler = [] (wxWebView *webView) {
|
||||
// Skip if SendAPIKey() already registered "wx"; a duplicate add throws an
|
||||
// uncatchable NSException on WKWebView, killing the app at startup.
|
||||
WebViewRef *ref = webview_ref(webView);
|
||||
if (ref && ref->m_script_handler_added)
|
||||
return;
|
||||
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ": begin to add script message handler for wx.";
|
||||
Slic3r::GUI::wxGetApp().set_adding_script_handler(true);
|
||||
if (!webView->AddScriptMessageHandler("wx"))
|
||||
wxLogError("Could not add script message handler");
|
||||
else if (ref)
|
||||
ref->m_script_handler_added = true;
|
||||
Slic3r::GUI::wxGetApp().set_adding_script_handler(false);
|
||||
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ": finished add script message handler for wx.";
|
||||
};
|
||||
@@ -336,6 +350,12 @@ wxWebView* WebView::CreateWebView(wxWindow * parent, wxString const & url)
|
||||
g_webviews.push_back(webView);
|
||||
return webView;
|
||||
}
|
||||
|
||||
void WebView::MarkScriptMessageHandlerAdded(wxWebView * webView)
|
||||
{
|
||||
if (WebViewRef *ref = webview_ref(webView))
|
||||
ref->m_script_handler_added = true;
|
||||
}
|
||||
#if wxUSE_WEBVIEW_EDGE
|
||||
bool WebView::CheckWebViewRuntime()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user