mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-08-01 03:12:04 +08:00
WebViewPanel: Javascript init flow error reporting (WIP)
This commit is contained in:
parent
e6eff5f57f
commit
07dbc5d7f0
@ -26,6 +26,7 @@
|
|||||||
#include <boost/log/trivial.hpp>
|
#include <boost/log/trivial.hpp>
|
||||||
#include <boost/log/expressions.hpp>
|
#include <boost/log/expressions.hpp>
|
||||||
#include <boost/log/utility/setup/file.hpp>
|
#include <boost/log/utility/setup/file.hpp>
|
||||||
|
#include <boost/log/utility/setup/console.hpp>
|
||||||
|
|
||||||
#if __APPLE__
|
#if __APPLE__
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
@ -52,7 +53,7 @@ int GUI_Run(GUI_InitParams ¶ms)
|
|||||||
#ifdef SLIC3R_LOG_TO_FILE
|
#ifdef SLIC3R_LOG_TO_FILE
|
||||||
auto sink = boost::log::add_file_log(get_default_datadir() + "/slicer.log");
|
auto sink = boost::log::add_file_log(get_default_datadir() + "/slicer.log");
|
||||||
sink->locked_backend()->auto_flush();
|
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
|
#endif // SLIC3R_LOG_TO_FILE
|
||||||
try {
|
try {
|
||||||
GUI::GUI_App* gui = new GUI::GUI_App(params.start_as_gcodeviewer ? GUI::GUI_App::EAppMode::GCodeViewer : GUI::GUI_App::EAppMode::Editor);
|
GUI::GUI_App* gui = new GUI::GUI_App(params.start_as_gcodeviewer ? GUI::GUI_App::EAppMode::GCodeViewer : GUI::GUI_App::EAppMode::Editor);
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
#include "slic3r/GUI/UserAccount.hpp"
|
#include "slic3r/GUI/UserAccount.hpp"
|
||||||
#include "slic3r/GUI/format.hpp"
|
#include "slic3r/GUI/format.hpp"
|
||||||
#include "slic3r/GUI/WebView.hpp"
|
#include "slic3r/GUI/WebView.hpp"
|
||||||
|
#include "slic3r/GUI/MsgDialog.hpp"
|
||||||
|
|
||||||
#include <wx/webview.h>
|
#include <wx/webview.h>
|
||||||
|
|
||||||
@ -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
|
// 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.
|
// the "Run Script" dialog box, it is shown there for convenient updating.
|
||||||
m_javascript = javascript;
|
m_javascript = javascript;
|
||||||
std::cout << "RunScript " << javascript << "\n";
|
BOOST_LOG_TRIVIAL(debug) << "RunScript " << javascript << "\n";
|
||||||
m_browser->RunScriptAsync(javascript);
|
m_browser->RunScriptAsync(javascript);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -363,7 +363,7 @@ void WebViewPanel::on_add_user_script(wxCommandEvent& WXUNUSED(evt))
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
const wxString& javascript = dialog.GetValue();
|
const wxString& javascript = dialog.GetValue();
|
||||||
std::cout << "RunScript " << javascript << "\n";
|
BOOST_LOG_TRIVIAL(debug) << "RunScript " << javascript << "\n";
|
||||||
if (!m_browser->AddUserScript(javascript))
|
if (!m_browser->AddUserScript(javascript))
|
||||||
wxLogError("Could not add user script");
|
wxLogError("Could not add user script");
|
||||||
}
|
}
|
||||||
@ -630,18 +630,21 @@ wxString ConnectWebViewPanel::get_login_script(bool refresh)
|
|||||||
R"(
|
R"(
|
||||||
console.log('Preparing login');
|
console.log('Preparing login');
|
||||||
function errorHandler(err) {
|
function errorHandler(err) {
|
||||||
window._prusaSlicer.postMessage({
|
const msg = {
|
||||||
action: 'ERROR',
|
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) {
|
.then(function (resp) {
|
||||||
console.log('Login resp', resp);
|
console.log('Login resp', resp);
|
||||||
resp.text()
|
resp.text()
|
||||||
.then(function (json) { console.log('Login resp body', json); })
|
.then(function (json) { console.log('Login resp body', json); })
|
||||||
.then(function (body) {
|
.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);
|
.catch(errorHandler);
|
||||||
@ -655,7 +658,7 @@ wxString ConnectWebViewPanel::get_login_script(bool refresh)
|
|||||||
void ConnectWebViewPanel::on_page_will_load()
|
void ConnectWebViewPanel::on_page_will_load()
|
||||||
{
|
{
|
||||||
auto javascript = get_login_script(false);
|
auto javascript = get_login_script(false);
|
||||||
std::cout << "RunScript " << javascript << "\n";
|
BOOST_LOG_TRIVIAL(debug) << "RunScript " << javascript << "\n";
|
||||||
m_browser->AddUserScript(javascript);
|
m_browser->AddUserScript(javascript);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -666,7 +669,7 @@ void ConnectWebViewPanel::on_user_token(UserAccountSuccessEvent& e)
|
|||||||
assert(!access_token.empty());
|
assert(!access_token.empty());
|
||||||
wxString javascript = get_login_script(true);
|
wxString javascript = get_login_script(true);
|
||||||
//m_browser->AddUserScript(javascript, wxWEBVIEW_INJECT_AT_DOCUMENT_END);
|
//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);
|
m_browser->RunScriptAsync(javascript);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -689,6 +692,20 @@ void ConnectWebViewPanel::on_navigation_request(wxWebViewEvent &evt)
|
|||||||
evt.Veto();
|
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()
|
void ConnectWebViewPanel::logout()
|
||||||
{
|
{
|
||||||
wxString script = L"window._prusaConnect_v1.logout()";
|
wxString script = L"window._prusaConnect_v1.logout()";
|
||||||
@ -706,7 +723,7 @@ void ConnectWebViewPanel::logout()
|
|||||||
)",
|
)",
|
||||||
plater->get_user_account()->get_access_token()
|
plater->get_user_account()->get_access_token()
|
||||||
);
|
);
|
||||||
std::cout << "RunScript " << javascript << "\n";
|
BOOST_LOG_TRIVIAL(debug) << "RunScript " << javascript << "\n";
|
||||||
m_browser->RunScript(javascript);
|
m_browser->RunScript(javascript);
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -767,7 +784,7 @@ void PrinterWebViewPanel::send_api_key()
|
|||||||
key);
|
key);
|
||||||
|
|
||||||
m_browser->RemoveAllUserScripts();
|
m_browser->RemoveAllUserScripts();
|
||||||
std::cout << "RunScript " << script << "\n";
|
BOOST_LOG_TRIVIAL(debug) << "RunScript " << script << "\n";
|
||||||
m_browser->AddUserScript(script);
|
m_browser->AddUserScript(script);
|
||||||
m_browser->Reload();
|
m_browser->Reload();
|
||||||
|
|
||||||
@ -793,7 +810,7 @@ void PrinterWebViewPanel::send_credentials()
|
|||||||
)", usr, psk);
|
)", usr, psk);
|
||||||
|
|
||||||
m_browser->RemoveAllUserScripts();
|
m_browser->RemoveAllUserScripts();
|
||||||
std::cout << "RunScript " << script << "\n";
|
BOOST_LOG_TRIVIAL(debug) << "RunScript " << script << "\n";
|
||||||
m_browser->AddUserScript(script);
|
m_browser->AddUserScript(script);
|
||||||
|
|
||||||
m_browser->Reload();
|
m_browser->Reload();
|
||||||
@ -1080,7 +1097,7 @@ void WebViewDialog::on_add_user_script(wxCommandEvent& WXUNUSED(evt))
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
const wxString& javascript = dialog.GetValue();
|
const wxString& javascript = dialog.GetValue();
|
||||||
std::cout << "RunScript " << javascript <<"\n";
|
BOOST_LOG_TRIVIAL(debug) << "RunScript " << javascript <<"\n";
|
||||||
if (!m_browser->AddUserScript(javascript))
|
if (!m_browser->AddUserScript(javascript))
|
||||||
wxLogError("Could not add user script");
|
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
|
// 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.
|
// the "Run Script" dialog box, it is shown there for convenient updating.
|
||||||
m_javascript = javascript;
|
m_javascript = javascript;
|
||||||
std::cout << "RunScript " << javascript << "\n";
|
BOOST_LOG_TRIVIAL(debug) << "RunScript " << javascript << "\n";
|
||||||
m_browser->RunScriptAsync(javascript);
|
m_browser->RunScriptAsync(javascript);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -207,6 +207,7 @@ protected:
|
|||||||
void on_connect_action_webapp_ready(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 run_script_bridge(const wxString& script) override {run_script(script); }
|
||||||
void on_page_will_load() override;
|
void on_page_will_load() override;
|
||||||
|
void on_connect_action_error(const std::string &message_data) override;
|
||||||
private:
|
private:
|
||||||
static wxString get_login_script(bool refresh);
|
static wxString get_login_script(bool refresh);
|
||||||
void on_user_token(UserAccountSuccessEvent& e);
|
void on_user_token(UserAccountSuccessEvent& e);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user