diff --git a/src/slic3r/GUI/MainFrame.cpp b/src/slic3r/GUI/MainFrame.cpp index 5d8ce03be..ae10d79a4 100644 --- a/src/slic3r/GUI/MainFrame.cpp +++ b/src/slic3r/GUI/MainFrame.cpp @@ -57,6 +57,7 @@ #include "MarkdownTip.hpp" #include "NetworkTestDialog.hpp" #include "ConfigWizard.hpp" +#include "Widgets/WebView.hpp" #ifdef _WIN32 #include @@ -1783,6 +1784,8 @@ void MainFrame::on_sys_color_changed() MenuFactory::sys_color_changed(m_menubar); + WebView::RecreateAll(); + this->Refresh(); } diff --git a/src/slic3r/GUI/MarkdownTip.cpp b/src/slic3r/GUI/MarkdownTip.cpp index cb62678d2..80490f38c 100644 --- a/src/slic3r/GUI/MarkdownTip.cpp +++ b/src/slic3r/GUI/MarkdownTip.cpp @@ -81,6 +81,16 @@ MarkdownTip::MarkdownTip() _timer = new wxTimer; _timer->Bind(wxEVT_TIMER, &MarkdownTip::OnTimer, this); + + Bind(EVT_WEBVIEW_RECREATED, [this](auto &evt) { + Hide(); + _lastTip.clear(); +#ifdef __WXMSW__ + _tipView = dynamic_cast(evt.GetEventObject()); + GetSizer()->Add(_tipView, wxSizerFlags().Expand().Proportion(1)); + Layout(); +#endif + }); } MarkdownTip::~MarkdownTip() { delete _timer; } diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 98c06ea85..3098c0d42 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -505,7 +505,6 @@ Sidebar::Sidebar(Plater *parent) PlaterPresetComboBox* combo_printer = new PlaterPresetComboBox(p->m_panel_printer_content, Preset::TYPE_PRINTER); ScalableButton* edit_btn = new ScalableButton(p->m_panel_printer_content, wxID_ANY, "edit"); - edit_btn->SetBackgroundColour(wxColour(255, 255, 255)); edit_btn->SetToolTip(_L("Click to edit preset")); edit_btn->Bind(wxEVT_BUTTON, [this, combo_printer](wxCommandEvent) { @@ -863,7 +862,6 @@ void Sidebar::init_filament_combo(PlaterPresetComboBox **combo, const int filame combo_and_btn_sizer->Add(del_btn, 0, wxALIGN_CENTER_VERTICAL, 5 * em / 10); */ ScalableButton* edit_btn = new ScalableButton(p->m_panel_filament_content, wxID_ANY, "edit"); - edit_btn->SetBackgroundColour(wxColour(255, 255, 255)); edit_btn->SetToolTip(_L("Click to edit preset")); PlaterPresetComboBox* combobox = (*combo); diff --git a/src/slic3r/GUI/WebViewDialog.cpp b/src/slic3r/GUI/WebViewDialog.cpp index 1e815ac10..3b9406ab9 100644 --- a/src/slic3r/GUI/WebViewDialog.cpp +++ b/src/slic3r/GUI/WebViewDialog.cpp @@ -35,7 +35,6 @@ WebViewPanel::WebViewPanel(wxWindow *parent) std::string strlang = wxGetApp().app_config->get("language"); if (strlang != "") url = wxString::Format("file://%s/web/homepage/index.html?lang=%s", from_u8(resources_dir()), strlang); - m_bbl_user_agent = wxString::Format("BBL-Slicer/v%s", SLIC3R_VERSION); wxBoxSizer* topsizer = new wxBoxSizer(wxVERTICAL); @@ -87,6 +86,18 @@ WebViewPanel::WebViewPanel(wxWindow *parent) topsizer->Add(m_browser, wxSizerFlags().Expand().Proportion(1)); + Bind(EVT_WEBVIEW_RECREATED, [this](auto &evt) { +#ifdef __WXMSW__ + m_browser = dynamic_cast(evt.GetEventObject()); + if (m_browser == nullptr) { + wxLogError("Could not recreate browser"); + return; + } + GetSizer()->Add(m_browser, wxSizerFlags().Expand().Proportion(1)); + GetSizer()->Layout(); +#endif + }); + // Log backend information if (wxGetApp().get_mode() == comDevelop) { wxLogMessage(wxWebView::GetBackendVersionInfo().ToString()); @@ -95,7 +106,6 @@ WebViewPanel::WebViewPanel(wxWindow *parent) wxLogMessage("User Agent: %s", m_browser->GetUserAgent()); } - // Create the Tools menu m_tools_menu = new wxMenu(); wxMenuItem* viewSource = m_tools_menu->Append(wxID_ANY, _L("View Source")); diff --git a/src/slic3r/GUI/WebViewDialog.hpp b/src/slic3r/GUI/WebViewDialog.hpp index 01bbdb40e..1eab6db15 100644 --- a/src/slic3r/GUI/WebViewDialog.hpp +++ b/src/slic3r/GUI/WebViewDialog.hpp @@ -145,8 +145,6 @@ private: wxString m_javascript; wxString m_response_js; - wxString m_bbl_user_agent; - DECLARE_EVENT_TABLE() }; diff --git a/src/slic3r/GUI/Widgets/WebView.cpp b/src/slic3r/GUI/Widgets/WebView.cpp index d78552545..251dfe007 100644 --- a/src/slic3r/GUI/Widgets/WebView.cpp +++ b/src/slic3r/GUI/Widgets/WebView.cpp @@ -67,6 +67,23 @@ class FakeWebView : public wxWebView virtual void DoSetPage(const wxString& html, const wxString& baseUrl) override { } }; +wxDEFINE_EVENT(EVT_WEBVIEW_RECREATED, wxCommandEvent); + +static std::vector g_webviews; + +class WebViewRef : public wxObjectRefData +{ +public: + WebViewRef(wxWebView *webView) : m_webView(webView) {} + ~WebViewRef() { + auto iter = std::find(g_webviews.begin(), g_webviews.end(), m_webView); + assert(iter != g_webviews.end()); + if (iter != g_webviews.end()) + g_webviews.erase(iter); + } + wxWebView *m_webView; +}; + wxWebView* WebView::CreateWebView(wxWindow * parent, wxString const & url) { #if wxUSE_WEBVIEW_EDGE @@ -90,11 +107,13 @@ wxWebView* WebView::CreateWebView(wxWindow * parent, wxString const & url) auto webView = wxWebView::New(); if (webView) { #ifdef __WIN32__ - webView->SetUserAgent(wxString::Format("BBL-Slicer/v%s", SLIC3R_VERSION)); + webView->SetUserAgent(wxString::Format("BBL-Slicer/v%s (%s) Mozilla/5.0 (Windows NT 10.0; Win64; x64) " + "AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36 Edg/107.0.1418.52", SLIC3R_VERSION, + Slic3r::GUI::wxGetApp().dark_mode() ? "dark" : "light")); webView->Create(parent, wxID_ANY, url2, wxDefaultPosition, wxDefaultSize); - //We register the wxfs:// protocol for testing purposes + // We register the wxfs:// protocol for testing purposes webView->RegisterHandler(wxSharedPtr(new wxWebViewArchiveHandler("bbl"))); - //And the memory: file system + // And the memory: file system webView->RegisterHandler(wxSharedPtr(new wxWebViewFSHandler("memory"))); #else // With WKWebView handlers need to be registered before creation @@ -102,7 +121,8 @@ wxWebView* WebView::CreateWebView(wxWindow * parent, wxString const & url) // And the memory: file system webView->RegisterHandler(wxSharedPtr(new wxWebViewFSHandler("memory"))); webView->Create(parent, wxID_ANY, url2, wxDefaultPosition, wxDefaultSize); - webView->SetUserAgent(wxString::Format("BBL-Slicer/v%s", SLIC3R_VERSION)); + webView->SetUserAgent(wxString::Format("BBL-Slicer/v%s (%s) Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko)", SLIC3R_VERSION, + Slic3r::GUI::wxGetApp().dark_mode() ? "dark" : "light")); #endif #ifndef __WIN32__ Slic3r::GUI::wxGetApp().CallAfter([webView] { @@ -121,6 +141,8 @@ wxWebView* WebView::CreateWebView(wxWindow * parent, wxString const & url) BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ": failed. Use fake web view."; webView = new FakeWebView; } + webView->SetRefData(new WebViewRef(webView)); + g_webviews.push_back(webView); return webView; } @@ -172,3 +194,35 @@ bool WebView::RunScript(wxWebView *webView, wxString const &javascript) return false; } } + +void WebView::RecreateAll() +{ +#ifdef __WXMSW__ + auto webviews = g_webviews; + std::vector parents; + std::vector urls; + for (auto web : webviews) { + parents.push_back(web->GetParent()); + urls.push_back(web->GetCurrentURL()); + delete web; + } + assert(g_webviews.empty()); + for (int i = 0; i < parents.size(); ++i) { + auto webView = CreateWebView(parents[i], urls[i]); + if (webView) { + wxCommandEvent evt(EVT_WEBVIEW_RECREATED); + evt.SetEventObject(webView); + wxPostEvent(parents[i], evt); + } + } +#else + for (auto webView : g_webviews) { + webView->SetUserAgent(wxString::Format("BBL-Slicer/v%s (%s) Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko)", SLIC3R_VERSION, + Slic3r::GUI::wxGetApp().dark_mode() ? "dark" : "light")); + webView->Reload(); + wxCommandEvent evt(EVT_WEBVIEW_RECREATED); + evt.SetEventObject(webView); + wxPostEvent(webView->GetParent(), evt); + } +#endif +} diff --git a/src/slic3r/GUI/Widgets/WebView.hpp b/src/slic3r/GUI/Widgets/WebView.hpp index ce142913f..f4ca3d389 100644 --- a/src/slic3r/GUI/Widgets/WebView.hpp +++ b/src/slic3r/GUI/Widgets/WebView.hpp @@ -3,6 +3,8 @@ #include +wxDECLARE_EVENT(EVT_WEBVIEW_RECREATED, wxCommandEvent); + class WebView { public: @@ -11,6 +13,8 @@ public: static void LoadUrl(wxWebView * webView, wxString const &url); static bool RunScript(wxWebView * webView, wxString const & msg); + + static void RecreateAll(); }; #endif // !slic3r_GUI_WebView_hpp_