From e70ee320d927f3f0ca070c5daa90477edac78af0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Ba=C5=99tip=C3=A1n?= Date: Thu, 20 Jun 2024 10:36:08 +0200 Subject: [PATCH 1/6] ConnectWebViewPanel: Connect login flow start moved from ctor to on_page_will_load --- src/slic3r/GUI/WebViewDialog.cpp | 31 +++++++++++++++++++++++-------- src/slic3r/GUI/WebViewDialog.hpp | 5 +++++ 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/src/slic3r/GUI/WebViewDialog.cpp b/src/slic3r/GUI/WebViewDialog.cpp index 2688d1798b..7eb2f2d0ef 100644 --- a/src/slic3r/GUI/WebViewDialog.cpp +++ b/src/slic3r/GUI/WebViewDialog.cpp @@ -145,6 +145,8 @@ void WebViewPanel::load_url(const wxString& url) if (!m_browser) return; + this->on_page_will_load(); + this->Show(); this->Raise(); #ifdef DEBUG_URL_PANEL @@ -258,6 +260,10 @@ void WebViewPanel::on_navigation_request(wxWebViewEvent &evt) { } +void WebViewPanel::on_page_will_load() +{ +} + /** * Invoked when user selects the "View Source" menu item */ @@ -560,7 +566,21 @@ ConnectWebViewPanel::ConnectWebViewPanel(wxWindow* parent) { //m_browser->RegisterHandler(wxSharedPtr(new WebViewHandler("https"))); + wxGetApp().plater()->Bind(EVT_UA_ID_USER_SUCCESS, &ConnectWebViewPanel::on_user_token, this); +} + +ConnectWebViewPanel::~ConnectWebViewPanel() +{ + m_browser->Unbind(EVT_UA_ID_USER_SUCCESS, &ConnectWebViewPanel::on_user_token, this); +} + +void ConnectWebViewPanel::on_page_will_load() +{ Plater* plater = wxGetApp().plater(); + const std::string& access_token = plater->get_user_account()->get_access_token(); + + assert(!access_token.empty()); + m_browser->AddUserScript(wxString::Format( #if AUTH_VIA_FETCH_OVERRIDE @@ -594,7 +614,7 @@ ConnectWebViewPanel::ConnectWebViewPanel(wxWindow* parent) window.__access_token_version = 0; )", #else - R"( + R"( console.log('Preparing login'); window.fetch('/slicer/login', {method: 'POST', headers: {Authorization: 'Bearer %s'}}) .then((resp) => { @@ -603,19 +623,14 @@ ConnectWebViewPanel::ConnectWebViewPanel(wxWindow* parent) }); )", #endif - plater->get_user_account()->get_access_token() + access_token )); - plater->Bind(EVT_UA_ID_USER_SUCCESS, &ConnectWebViewPanel::on_user_token, this); -} - -ConnectWebViewPanel::~ConnectWebViewPanel() -{ - m_browser->Unbind(EVT_UA_ID_USER_SUCCESS, &ConnectWebViewPanel::on_user_token, this); } void ConnectWebViewPanel::on_user_token(UserAccountSuccessEvent& e) { e.Skip(); + assert(!access_token.empty()); wxString javascript = wxString::Format( #if AUTH_VIA_FETCH_OVERRIDE "window.__access_token = '%s';window.__access_token_version = (window.__access_token_version || 0) + 1;console.log('Updated Auth token', window.__access_token);", diff --git a/src/slic3r/GUI/WebViewDialog.hpp b/src/slic3r/GUI/WebViewDialog.hpp index 8f4c9af4b7..0d7fccd937 100644 --- a/src/slic3r/GUI/WebViewDialog.hpp +++ b/src/slic3r/GUI/WebViewDialog.hpp @@ -59,6 +59,10 @@ public: void set_default_url(const wxString& url) { m_default_url = url; } virtual void sys_color_changed(); +protected: + + virtual void on_page_will_load(); + protected: wxWebView* m_browser { nullptr }; @@ -201,6 +205,7 @@ protected: void on_connect_action_print(const std::string& message_data) override; void on_connect_action_webapp_ready(const std::string& message_data) override {} void run_script_bridge(const wxString& script) override {run_script(script); } + void on_page_will_load() override; private: void on_user_token(UserAccountSuccessEvent& e); bool m_reached_default_url {false}; From 0ea1f9f89a6d80ade1503dea06bec5f77c37e318 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Ba=C5=99tip=C3=A1n?= Date: Thu, 20 Jun 2024 10:39:35 +0200 Subject: [PATCH 2/6] WebViewPanel: enable dev tools --- src/slic3r/GUI/WebViewDialog.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/slic3r/GUI/WebViewDialog.cpp b/src/slic3r/GUI/WebViewDialog.cpp index 7eb2f2d0ef..aeb7dc0da9 100644 --- a/src/slic3r/GUI/WebViewDialog.cpp +++ b/src/slic3r/GUI/WebViewDialog.cpp @@ -129,6 +129,9 @@ WebViewPanel::WebViewPanel(wxWindow *parent, const wxString& default_url, const #endif //Connect the idle events Bind(wxEVT_IDLE, &WebViewPanel::on_idle, this); + + m_browser->EnableContextMenu(true); + m_browser->EnableAccessToDevTools(true); } WebViewPanel::~WebViewPanel() From dcfb9651928c70eb45db72b9b4e0995f9dc49853 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Ba=C5=99tip=C3=A1n?= Date: Thu, 20 Jun 2024 14:32:06 +0200 Subject: [PATCH 3/6] WebViewPanel: logging RunScript just via std::cout --- src/slic3r/GUI/WebViewDialog.cpp | 47 ++++++++++++++++++++------------ 1 file changed, 30 insertions(+), 17 deletions(-) diff --git a/src/slic3r/GUI/WebViewDialog.cpp b/src/slic3r/GUI/WebViewDialog.cpp index aeb7dc0da9..b8def1502b 100644 --- a/src/slic3r/GUI/WebViewDialog.cpp +++ b/src/slic3r/GUI/WebViewDialog.cpp @@ -327,7 +327,7 @@ void WebViewPanel::run_script(const wxString& javascript) // Remember the script we run in any case, so the next time the user opens // the "Run Script" dialog box, it is shown there for convenient updating. m_javascript = javascript; - BOOST_LOG_TRIVIAL(debug) << "RunScript " << javascript; + std::cout << "RunScript " << javascript << "\n"; m_browser->RunScriptAsync(javascript); } @@ -362,7 +362,9 @@ void WebViewPanel::on_add_user_script(wxCommandEvent& WXUNUSED(evt)) if (dialog.ShowModal() != wxID_OK) return; - if (!m_browser->AddUserScript(dialog.GetValue())) + const wxString& javascript = dialog.GetValue(); + std::cout << "RunScript " << javascript << "\n"; + if (!m_browser->AddUserScript(javascript)) wxLogError("Could not add user script"); } @@ -583,11 +585,10 @@ void ConnectWebViewPanel::on_page_will_load() const std::string& access_token = plater->get_user_account()->get_access_token(); assert(!access_token.empty()); - - m_browser->AddUserScript(wxString::Format( + auto javascript = wxString::Format( #if AUTH_VIA_FETCH_OVERRIDE - /* + /* * Notes: * - The fetch() function has two distinct prototypes (i.e. input args): * 1. fetch(url: string, options: object | undefined) @@ -595,8 +596,8 @@ void ConnectWebViewPanel::on_page_will_load() * - For some reason I can't explain the headers can be extended only via Request object * i.e. the fetch prototype (2). So we need to convert (1) call into (2) before * - */ - R"( + */ + R"( if (window.__fetch === undefined) { window.__fetch = fetch; window.fetch = function(req, opts = {}) { @@ -617,7 +618,7 @@ void ConnectWebViewPanel::on_page_will_load() window.__access_token_version = 0; )", #else - R"( + R"( console.log('Preparing login'); window.fetch('/slicer/login', {method: 'POST', headers: {Authorization: 'Bearer %s'}}) .then((resp) => { @@ -626,13 +627,16 @@ void ConnectWebViewPanel::on_page_will_load() }); )", #endif - access_token - )); + access_token + ); + std::cout << "RunScript " << javascript << "\n"; + m_browser->AddUserScript(javascript); } void ConnectWebViewPanel::on_user_token(UserAccountSuccessEvent& e) { e.Skip(); + auto access_token = wxGetApp().plater()->get_user_account()->get_access_token(); assert(!access_token.empty()); wxString javascript = wxString::Format( #if AUTH_VIA_FETCH_OVERRIDE @@ -647,9 +651,10 @@ void ConnectWebViewPanel::on_user_token(UserAccountSuccessEvent& e) }); )", #endif - wxGetApp().plater()->get_user_account()->get_access_token() + access_token ); //m_browser->AddUserScript(javascript, wxWEBVIEW_INJECT_AT_DOCUMENT_END); + std::cout << "RunScript " << javascript << "\n"; m_browser->RunScriptAsync(javascript); } @@ -678,8 +683,8 @@ void ConnectWebViewPanel::logout() run_script(script); Plater* plater = wxGetApp().plater(); - m_browser->RunScript(wxString::Format( - R"( + auto javascript = wxString::Format( + R"( console.log('Preparing login'); window.fetch('/slicer/logout', {method: 'POST', headers: {Authorization: 'Bearer %s'}}) .then((resp) => { @@ -687,8 +692,11 @@ void ConnectWebViewPanel::logout() resp.text().then((json) => console.log('Login resp body', json)); }); )", - plater->get_user_account()->get_access_token() - )); + plater->get_user_account()->get_access_token() + ); + std::cout << "RunScript " << javascript << "\n"; + m_browser->RunScript(javascript); + } void ConnectWebViewPanel::sys_color_changed() @@ -747,6 +755,7 @@ void PrinterWebViewPanel::send_api_key() key); m_browser->RemoveAllUserScripts(); + std::cout << "RunScript " << script << "\n"; m_browser->AddUserScript(script); m_browser->Reload(); @@ -772,7 +781,9 @@ void PrinterWebViewPanel::send_credentials() )", usr, psk); m_browser->RemoveAllUserScripts(); + std::cout << "RunScript " << script << "\n"; m_browser->AddUserScript(script); + m_browser->Reload(); } @@ -1056,7 +1067,9 @@ void WebViewDialog::on_add_user_script(wxCommandEvent& WXUNUSED(evt)) if (dialog.ShowModal() != wxID_OK) return; - if (!m_browser->AddUserScript(dialog.GetValue())) + const wxString& javascript = dialog.GetValue(); + std::cout << "RunScript " << javascript <<"\n"; + if (!m_browser->AddUserScript(javascript)) wxLogError("Could not add user script"); } @@ -1163,7 +1176,7 @@ void WebViewDialog::run_script(const wxString& javascript) // Remember the script we run in any case, so the next time the user opens // the "Run Script" dialog box, it is shown there for convenient updating. m_javascript = javascript; - BOOST_LOG_TRIVIAL(debug) << "RunScript " << javascript; + std::cout << "RunScript " << javascript << "\n"; m_browser->RunScriptAsync(javascript); } From e6eff5f57f3802a8d079942685c2a1779169c69a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Ba=C5=99tip=C3=A1n?= Date: Thu, 20 Jun 2024 15:49:58 +0200 Subject: [PATCH 4/6] WebViewPanel: JS arrow function rewritten to old function notation --- src/slic3r/GUI/WebViewDialog.cpp | 68 +++++++++++++++++++------------- src/slic3r/GUI/WebViewDialog.hpp | 2 + 2 files changed, 42 insertions(+), 28 deletions(-) diff --git a/src/slic3r/GUI/WebViewDialog.cpp b/src/slic3r/GUI/WebViewDialog.cpp index b8def1502b..bbeedac62c 100644 --- a/src/slic3r/GUI/WebViewDialog.cpp +++ b/src/slic3r/GUI/WebViewDialog.cpp @@ -489,6 +489,7 @@ ConnectRequestHandler::ConnectRequestHandler() m_actions["SELECT_PRINTER"] = std::bind(&ConnectRequestHandler::on_connect_action_select_printer, this, std::placeholders::_1); m_actions["PRINT"] = std::bind(&ConnectRequestHandler::on_connect_action_print, this, std::placeholders::_1); m_actions["REQUEST_OPEN_IN_BROWSER"] = std::bind(&ConnectRequestHandler::on_connect_action_request_open_in_browser, this, std::placeholders::_1); + m_actions["ERROR"] = std::bind(&ConnectRequestHandler::on_connect_action_error, this, std::placeholders::_1); } ConnectRequestHandler::~ConnectRequestHandler() { @@ -527,6 +528,11 @@ void ConnectRequestHandler::handle_message(const std::string& message) } } +void ConnectRequestHandler::on_connect_action_error(const std::string &message_data) +{ + BOOST_LOG_TRIVIAL(error) << "WebKit runtime error: " << message_data; +} + void ConnectRequestHandler::resend_config() { on_connect_action_request_config({}); @@ -579,16 +585,19 @@ ConnectWebViewPanel::~ConnectWebViewPanel() m_browser->Unbind(EVT_UA_ID_USER_SUCCESS, &ConnectWebViewPanel::on_user_token, this); } -void ConnectWebViewPanel::on_page_will_load() +wxString ConnectWebViewPanel::get_login_script(bool refresh) { Plater* plater = wxGetApp().plater(); const std::string& access_token = plater->get_user_account()->get_access_token(); - assert(!access_token.empty()); auto javascript = wxString::Format( #if AUTH_VIA_FETCH_OVERRIDE - /* + refresh + ? + "window.__access_token = '%s';window.__access_token_version = (window.__access_token_version || 0) + 1;console.log('Updated Auth token', window.__access_token);" + : + /* * Notes: * - The fetch() function has two distinct prototypes (i.e. input args): * 1. fetch(url: string, options: object | undefined) @@ -596,8 +605,8 @@ void ConnectWebViewPanel::on_page_will_load() * - For some reason I can't explain the headers can be extended only via Request object * i.e. the fetch prototype (2). So we need to convert (1) call into (2) before * - */ - R"( + */ + R"( if (window.__fetch === undefined) { window.__fetch = fetch; window.fetch = function(req, opts = {}) { @@ -618,17 +627,34 @@ void ConnectWebViewPanel::on_page_will_load() window.__access_token_version = 0; )", #else - R"( + R"( console.log('Preparing login'); - window.fetch('/slicer/login', {method: 'POST', headers: {Authorization: 'Bearer %s'}}) - .then((resp) => { - console.log('Login resp', resp); - resp.text().then((json) => console.log('Login resp body', json)); + function errorHandler(err) { + window._prusaSlicer.postMessage({ + action: 'ERROR', + error: err }); + }; + window.fetch('/slicer/login', {method: 'POST', headers: {Authorization: 'Bearer %s'}}) + .then(function (resp) { + console.log('Login resp', resp); + resp.text() + .then(function (json) { console.log('Login resp body', json); }) + .then(function (body) { + if (resp.status >= 400) window._prusaSlicer.postMessage({action: 'ERROR', error: body}); + }); + }) + .catch(errorHandler); )", #endif - access_token + access_token ); + return javascript; +} + +void ConnectWebViewPanel::on_page_will_load() +{ + auto javascript = get_login_script(false); std::cout << "RunScript " << javascript << "\n"; m_browser->AddUserScript(javascript); } @@ -638,21 +664,7 @@ void ConnectWebViewPanel::on_user_token(UserAccountSuccessEvent& e) e.Skip(); auto access_token = wxGetApp().plater()->get_user_account()->get_access_token(); assert(!access_token.empty()); - wxString javascript = wxString::Format( -#if AUTH_VIA_FETCH_OVERRIDE - "window.__access_token = '%s';window.__access_token_version = (window.__access_token_version || 0) + 1;console.log('Updated Auth token', window.__access_token);", -#else - R"( - console.log('Preparing login'); - window.fetch('/slicer/login', {method: 'POST', headers: {Authorization: 'Bearer %s'}}) - .then((resp) => { - console.log('Login resp', resp); - resp.text().then((json) => console.log('Login resp body', json)); - }); - )", -#endif - access_token - ); + wxString javascript = get_login_script(true); //m_browser->AddUserScript(javascript, wxWEBVIEW_INJECT_AT_DOCUMENT_END); std::cout << "RunScript " << javascript << "\n"; m_browser->RunScriptAsync(javascript); @@ -687,9 +699,9 @@ void ConnectWebViewPanel::logout() R"( console.log('Preparing login'); window.fetch('/slicer/logout', {method: 'POST', headers: {Authorization: 'Bearer %s'}}) - .then((resp) => { + .then(function (resp){ console.log('Login resp', resp); - resp.text().then((json) => console.log('Login resp body', json)); + resp.text().then(function (json) { console.log('Login resp body', json) }); }); )", plater->get_user_account()->get_access_token() diff --git a/src/slic3r/GUI/WebViewDialog.hpp b/src/slic3r/GUI/WebViewDialog.hpp index 0d7fccd937..214944109d 100644 --- a/src/slic3r/GUI/WebViewDialog.hpp +++ b/src/slic3r/GUI/WebViewDialog.hpp @@ -181,6 +181,7 @@ public: void resend_config(); protected: // action callbacs stored in m_actions + virtual void on_connect_action_error(const std::string& message_data); virtual void on_connect_action_request_config(const std::string& message_data); virtual void on_connect_action_request_open_in_browser(const std::string& message_data); virtual void on_connect_action_select_printer(const std::string& message_data) = 0; @@ -207,6 +208,7 @@ protected: void run_script_bridge(const wxString& script) override {run_script(script); } void on_page_will_load() override; private: + static wxString get_login_script(bool refresh); void on_user_token(UserAccountSuccessEvent& e); bool m_reached_default_url {false}; }; From 07dbc5d7f01fbb9cd0aceeda340f841deded349b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Ba=C5=99tip=C3=A1n?= Date: Fri, 21 Jun 2024 10:58:52 +0200 Subject: [PATCH 5/6] WebViewPanel: Javascript init flow error reporting (WIP) --- src/slic3r/GUI/GUI_Init.cpp | 3 +- src/slic3r/GUI/WebViewDialog.cpp | 47 ++++++++++++++++++++++---------- src/slic3r/GUI/WebViewDialog.hpp | 1 + 3 files changed, 35 insertions(+), 16 deletions(-) diff --git a/src/slic3r/GUI/GUI_Init.cpp b/src/slic3r/GUI/GUI_Init.cpp index 2c74971ce2..155bdc92c0 100644 --- a/src/slic3r/GUI/GUI_Init.cpp +++ b/src/slic3r/GUI/GUI_Init.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #if __APPLE__ #include @@ -52,7 +53,7 @@ int GUI_Run(GUI_InitParams ¶ms) #ifdef SLIC3R_LOG_TO_FILE auto sink = boost::log::add_file_log(get_default_datadir() + "/slicer.log"); sink->locked_backend()->auto_flush(); - boost::log::core::get()->set_filter(boost::log::trivial::severity >= boost::log::trivial::info); + boost::log::add_console_log(); #endif // SLIC3R_LOG_TO_FILE try { GUI::GUI_App* gui = new GUI::GUI_App(params.start_as_gcodeviewer ? GUI::GUI_App::EAppMode::GCodeViewer : GUI::GUI_App::EAppMode::Editor); diff --git a/src/slic3r/GUI/WebViewDialog.cpp b/src/slic3r/GUI/WebViewDialog.cpp index bbeedac62c..df8d394865 100644 --- a/src/slic3r/GUI/WebViewDialog.cpp +++ b/src/slic3r/GUI/WebViewDialog.cpp @@ -7,7 +7,7 @@ #include "slic3r/GUI/UserAccount.hpp" #include "slic3r/GUI/format.hpp" #include "slic3r/GUI/WebView.hpp" - +#include "slic3r/GUI/MsgDialog.hpp" #include @@ -327,7 +327,7 @@ void WebViewPanel::run_script(const wxString& javascript) // Remember the script we run in any case, so the next time the user opens // the "Run Script" dialog box, it is shown there for convenient updating. m_javascript = javascript; - std::cout << "RunScript " << javascript << "\n"; + BOOST_LOG_TRIVIAL(debug) << "RunScript " << javascript << "\n"; m_browser->RunScriptAsync(javascript); } @@ -363,7 +363,7 @@ void WebViewPanel::on_add_user_script(wxCommandEvent& WXUNUSED(evt)) return; const wxString& javascript = dialog.GetValue(); - std::cout << "RunScript " << javascript << "\n"; + BOOST_LOG_TRIVIAL(debug) << "RunScript " << javascript << "\n"; if (!m_browser->AddUserScript(javascript)) wxLogError("Could not add user script"); } @@ -630,18 +630,21 @@ wxString ConnectWebViewPanel::get_login_script(bool refresh) R"( console.log('Preparing login'); function errorHandler(err) { - window._prusaSlicer.postMessage({ + const msg = { action: 'ERROR', - error: err - }); + error: JSON.stringify(err), + critical: false + }; + console.error('Login error occurred', msg); + window._prusaSlicer.postMessage(msg); }; - window.fetch('/slicer/login', {method: 'POST', headers: {Authorization: 'Bearer %s'}}) + window.fetch('/slicer/loginx', {method: 'POST', headers: {Authorization: 'Bearer %s'}}) .then(function (resp) { console.log('Login resp', resp); resp.text() .then(function (json) { console.log('Login resp body', json); }) .then(function (body) { - if (resp.status >= 400) window._prusaSlicer.postMessage({action: 'ERROR', error: body}); + if (resp.status >= 400) errorHandler({status: resp.status, body}); }); }) .catch(errorHandler); @@ -655,7 +658,7 @@ wxString ConnectWebViewPanel::get_login_script(bool refresh) void ConnectWebViewPanel::on_page_will_load() { auto javascript = get_login_script(false); - std::cout << "RunScript " << javascript << "\n"; + BOOST_LOG_TRIVIAL(debug) << "RunScript " << javascript << "\n"; m_browser->AddUserScript(javascript); } @@ -666,7 +669,7 @@ void ConnectWebViewPanel::on_user_token(UserAccountSuccessEvent& e) assert(!access_token.empty()); wxString javascript = get_login_script(true); //m_browser->AddUserScript(javascript, wxWEBVIEW_INJECT_AT_DOCUMENT_END); - std::cout << "RunScript " << javascript << "\n"; + BOOST_LOG_TRIVIAL(debug) << "RunScript " << javascript << "\n"; m_browser->RunScriptAsync(javascript); } @@ -689,6 +692,20 @@ void ConnectWebViewPanel::on_navigation_request(wxWebViewEvent &evt) evt.Veto(); } } + +void ConnectWebViewPanel::on_connect_action_error(const std::string &message_data) +{ + ConnectRequestHandler::on_connect_action_error(message_data); + MessageDialog dialog( + this, + GUI::format_wxstr(_L("WebKit Runtime Error encountered:\n\n%s"), message_data), + "WebKit Runtime Error", + wxOK + ); + dialog.ShowModal(); + +} + void ConnectWebViewPanel::logout() { wxString script = L"window._prusaConnect_v1.logout()"; @@ -706,7 +723,7 @@ void ConnectWebViewPanel::logout() )", plater->get_user_account()->get_access_token() ); - std::cout << "RunScript " << javascript << "\n"; + BOOST_LOG_TRIVIAL(debug) << "RunScript " << javascript << "\n"; m_browser->RunScript(javascript); } @@ -767,7 +784,7 @@ void PrinterWebViewPanel::send_api_key() key); m_browser->RemoveAllUserScripts(); - std::cout << "RunScript " << script << "\n"; + BOOST_LOG_TRIVIAL(debug) << "RunScript " << script << "\n"; m_browser->AddUserScript(script); m_browser->Reload(); @@ -793,7 +810,7 @@ void PrinterWebViewPanel::send_credentials() )", usr, psk); m_browser->RemoveAllUserScripts(); - std::cout << "RunScript " << script << "\n"; + BOOST_LOG_TRIVIAL(debug) << "RunScript " << script << "\n"; m_browser->AddUserScript(script); m_browser->Reload(); @@ -1080,7 +1097,7 @@ void WebViewDialog::on_add_user_script(wxCommandEvent& WXUNUSED(evt)) return; const wxString& javascript = dialog.GetValue(); - std::cout << "RunScript " << javascript <<"\n"; + BOOST_LOG_TRIVIAL(debug) << "RunScript " << javascript <<"\n"; if (!m_browser->AddUserScript(javascript)) wxLogError("Could not add user script"); } @@ -1188,7 +1205,7 @@ void WebViewDialog::run_script(const wxString& javascript) // Remember the script we run in any case, so the next time the user opens // the "Run Script" dialog box, it is shown there for convenient updating. m_javascript = javascript; - std::cout << "RunScript " << javascript << "\n"; + BOOST_LOG_TRIVIAL(debug) << "RunScript " << javascript << "\n"; m_browser->RunScriptAsync(javascript); } diff --git a/src/slic3r/GUI/WebViewDialog.hpp b/src/slic3r/GUI/WebViewDialog.hpp index 214944109d..7c8d6ea33e 100644 --- a/src/slic3r/GUI/WebViewDialog.hpp +++ b/src/slic3r/GUI/WebViewDialog.hpp @@ -207,6 +207,7 @@ protected: void on_connect_action_webapp_ready(const std::string& message_data) override {} void run_script_bridge(const wxString& script) override {run_script(script); } void on_page_will_load() override; + void on_connect_action_error(const std::string &message_data) override; private: static wxString get_login_script(bool refresh); void on_user_token(UserAccountSuccessEvent& e); From 6255d57e5e3d481306b51b77e9cb106c3f7b80f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Ba=C5=99tip=C3=A1n?= Date: Fri, 21 Jun 2024 14:18:03 +0200 Subject: [PATCH 6/6] ConnectWebViewPanel: disable error reporting via dialog (only reporting to console), disable dev tools --- src/slic3r/GUI/WebViewDialog.cpp | 80 ++++++++++++++++---------------- 1 file changed, 39 insertions(+), 41 deletions(-) diff --git a/src/slic3r/GUI/WebViewDialog.cpp b/src/slic3r/GUI/WebViewDialog.cpp index df8d394865..48241f5ca6 100644 --- a/src/slic3r/GUI/WebViewDialog.cpp +++ b/src/slic3r/GUI/WebViewDialog.cpp @@ -27,12 +27,37 @@ namespace Slic3r { namespace GUI { +WebViewPanel::~WebViewPanel() +{ + SetEvtHandlerEnabled(false); +#ifdef DEBUG_URL_PANEL + delete m_tools_menu; +#endif +} + +void WebViewPanel::load_url(const wxString& url) +{ + if (!m_browser) + return; + + this->on_page_will_load(); + + this->Show(); + this->Raise(); +#ifdef DEBUG_URL_PANEL + m_url->SetLabelText(url); +#endif + m_browser->LoadURL(url); + m_browser->SetFocus(); +} + + WebViewPanel::WebViewPanel(wxWindow *parent, const wxString& default_url, const std::vector& message_handler_names, const std::string& loading_html/* = "loading"*/) - : wxPanel(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize) - , m_default_url (default_url) - , m_loading_html(loading_html) - , m_script_message_hadler_names(message_handler_names) - { + : wxPanel(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize) + , m_default_url (default_url) + , m_loading_html(loading_html) + , m_script_message_hadler_names(message_handler_names) +{ wxBoxSizer* topsizer = new wxBoxSizer(wxVERTICAL); #ifdef DEBUG_URL_PANEL // Create the button @@ -91,7 +116,7 @@ WebViewPanel::WebViewPanel(wxWindow *parent, const wxString& default_url, const m_tools_menu->AppendSeparator(); wxMenu* script_menu = new wxMenu; - + m_script_custom = script_menu->Append(wxID_ANY, "Custom script"); m_tools_menu->AppendSubMenu(script_menu, "Run Script"); wxMenuItem* addUserScript = m_tools_menu->Append(wxID_ANY, "Add user script"); @@ -129,34 +154,6 @@ WebViewPanel::WebViewPanel(wxWindow *parent, const wxString& default_url, const #endif //Connect the idle events Bind(wxEVT_IDLE, &WebViewPanel::on_idle, this); - - m_browser->EnableContextMenu(true); - m_browser->EnableAccessToDevTools(true); - } - -WebViewPanel::~WebViewPanel() -{ - SetEvtHandlerEnabled(false); -#ifdef DEBUG_URL_PANEL - delete m_tools_menu; -#endif -} - - -void WebViewPanel::load_url(const wxString& url) -{ - if (!m_browser) - return; - - this->on_page_will_load(); - - this->Show(); - this->Raise(); -#ifdef DEBUG_URL_PANEL - m_url->SetLabelText(url); -#endif - m_browser->LoadURL(url); - m_browser->SetFocus(); } void WebViewPanel::load_default_url_delayed() @@ -696,13 +693,14 @@ void ConnectWebViewPanel::on_navigation_request(wxWebViewEvent &evt) void ConnectWebViewPanel::on_connect_action_error(const std::string &message_data) { ConnectRequestHandler::on_connect_action_error(message_data); - MessageDialog dialog( - this, - GUI::format_wxstr(_L("WebKit Runtime Error encountered:\n\n%s"), message_data), - "WebKit Runtime Error", - wxOK - ); - dialog.ShowModal(); + // TODO: make this more user friendly (and make sure only once opened if multiple errors happen) +// MessageDialog dialog( +// this, +// GUI::format_wxstr(_L("WebKit Runtime Error encountered:\n\n%s"), message_data), +// "WebKit Runtime Error", +// wxOK +// ); +// dialog.ShowModal(); }