mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-08-03 00:02:14 +00:00
fix: startup crash on macOS when a printer has a print host set (#14747)
This commit is contained in:
@@ -246,7 +246,10 @@ void PrinterWebView::SendAPIKey()
|
|||||||
// RemoveAllUserScripts causes WebView to forget about our script message handler,
|
// RemoveAllUserScripts causes WebView to forget about our script message handler,
|
||||||
// so re-add it here.
|
// so re-add it here.
|
||||||
m_browser->RemoveScriptMessageHandler("wx");
|
m_browser->RemoveScriptMessageHandler("wx");
|
||||||
m_browser->AddScriptMessageHandler("wx");
|
if (m_browser->AddScriptMessageHandler("wx"))
|
||||||
|
WebView::MarkScriptMessageHandlerAdded(m_browser);
|
||||||
|
else
|
||||||
|
wxLogError("Could not add script message handler");
|
||||||
|
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
// Re-inject the vue-resize/WebKitGTK workaround that RemoveAllUserScripts just cleared.
|
// Re-inject the vue-resize/WebKitGTK workaround that RemoveAllUserScripts just cleared.
|
||||||
|
|||||||
@@ -242,8 +242,15 @@ public:
|
|||||||
g_webviews.erase(iter);
|
g_webviews.erase(iter);
|
||||||
}
|
}
|
||||||
wxWebView *m_webView;
|
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)
|
wxWebView* WebView::CreateWebView(wxWindow * parent, wxString const & url)
|
||||||
{
|
{
|
||||||
#if wxUSE_WEBVIEW_EDGE
|
#if wxUSE_WEBVIEW_EDGE
|
||||||
@@ -304,10 +311,17 @@ wxWebView* WebView::CreateWebView(wxWindow * parent, wxString const & url)
|
|||||||
Slic3r::GUI::WKWebView_setTransparentBackground(wkWebView);
|
Slic3r::GUI::WKWebView_setTransparentBackground(wkWebView);
|
||||||
#endif
|
#endif
|
||||||
auto addScriptMessageHandler = [] (wxWebView *webView) {
|
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.";
|
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");
|
||||||
|
else if (ref)
|
||||||
|
ref->m_script_handler_added = true;
|
||||||
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.";
|
||||||
};
|
};
|
||||||
@@ -336,6 +350,12 @@ wxWebView* WebView::CreateWebView(wxWindow * parent, wxString const & url)
|
|||||||
g_webviews.push_back(webView);
|
g_webviews.push_back(webView);
|
||||||
return webView;
|
return webView;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WebView::MarkScriptMessageHandlerAdded(wxWebView * webView)
|
||||||
|
{
|
||||||
|
if (WebViewRef *ref = webview_ref(webView))
|
||||||
|
ref->m_script_handler_added = true;
|
||||||
|
}
|
||||||
#if wxUSE_WEBVIEW_EDGE
|
#if wxUSE_WEBVIEW_EDGE
|
||||||
bool WebView::CheckWebViewRuntime()
|
bool WebView::CheckWebViewRuntime()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -18,6 +18,9 @@ public:
|
|||||||
|
|
||||||
static bool RunScript(wxWebView * webView, wxString const & msg);
|
static bool RunScript(wxWebView * webView, wxString const & msg);
|
||||||
|
|
||||||
|
// Marks "wx" as registered so CreateWebView's deferred add skips the duplicate.
|
||||||
|
static void MarkScriptMessageHandlerAdded(wxWebView * webView);
|
||||||
|
|
||||||
static void RecreateAll();
|
static void RecreateAll();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user