mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-08-01 08:41:59 +08:00
ConnectWebViewPanel: fixed segfault on quit (accessing already deleted plater in on_activate handler), WebView scripts can now use _prusaSlicer.postMessage({action: 'LOG', ...}) to write logs into OS console
This commit is contained in:
parent
74ab2d24b7
commit
f9164da380
@ -1449,7 +1449,10 @@ bool GUI_App::on_init_inner()
|
|||||||
});
|
});
|
||||||
|
|
||||||
Bind(wxEVT_ACTIVATE_APP, [this](const wxActivateEvent &evt) {
|
Bind(wxEVT_ACTIVATE_APP, [this](const wxActivateEvent &evt) {
|
||||||
plater_->get_user_account()->on_activate_app(evt.GetActive());
|
if (plater_) {
|
||||||
|
if (auto user_account = plater_->get_user_account())
|
||||||
|
user_account->on_activate_app(evt.GetActive());
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -499,6 +499,7 @@ ConnectRequestHandler::ConnectRequestHandler()
|
|||||||
m_actions["PRINT"] = std::bind(&ConnectRequestHandler::on_connect_action_print, 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["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);
|
m_actions["ERROR"] = std::bind(&ConnectRequestHandler::on_connect_action_error, this, std::placeholders::_1);
|
||||||
|
m_actions["LOG"] = std::bind(&ConnectRequestHandler::on_connect_action_log, this, std::placeholders::_1);
|
||||||
}
|
}
|
||||||
ConnectRequestHandler::~ConnectRequestHandler()
|
ConnectRequestHandler::~ConnectRequestHandler()
|
||||||
{
|
{
|
||||||
@ -547,6 +548,11 @@ void ConnectRequestHandler::resend_config()
|
|||||||
on_connect_action_request_config({});
|
on_connect_action_request_config({});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ConnectRequestHandler::on_connect_action_log(const std::string& message_data)
|
||||||
|
{
|
||||||
|
BOOST_LOG_TRIVIAL(info) << "WebKit log: " << message_data;
|
||||||
|
}
|
||||||
|
|
||||||
void ConnectRequestHandler::on_connect_action_request_config(const std::string& message_data)
|
void ConnectRequestHandler::on_connect_action_request_config(const std::string& message_data)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
@ -641,17 +647,24 @@ wxString ConnectWebViewPanel::get_login_script(bool refresh)
|
|||||||
R"(
|
R"(
|
||||||
if (window._prusaSlicer_initLogin !== undefined) {
|
if (window._prusaSlicer_initLogin !== undefined) {
|
||||||
console.log('Refreshing login');
|
console.log('Refreshing login');
|
||||||
|
_prusaSlicer.postMessage({action: 'LOG', message: 'Refreshing login'});
|
||||||
_prusaSlicer_initLogin('%s');
|
_prusaSlicer_initLogin('%s');
|
||||||
} else {
|
} else {
|
||||||
console.log('Refreshing login skipped as no _prusaSlicer_initLogin defined (yet?)');
|
console.log('Refreshing login skipped as no _prusaSlicer_initLogin defined (yet?)');
|
||||||
|
if (window._prusaSlicer === undefined) {
|
||||||
|
console.log('Message handler _prusaSlicer not defined yet');
|
||||||
|
} else {
|
||||||
|
_prusaSlicer.postMessage({action: 'LOG', message: 'Refreshing login skipped as no _prusaSlicer_initLogin defined (yet?)'});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
)"
|
)"
|
||||||
:
|
:
|
||||||
R"(
|
R"(
|
||||||
|
function _prusaSlicer_log(msg) { console.log(msg); _prusaSlicer.postMessage({action: 'LOG', message: msg}); }
|
||||||
function _prusaSlicer_errorHandler(err) {
|
function _prusaSlicer_errorHandler(err) {
|
||||||
const msg = {
|
const msg = {
|
||||||
action: 'ERROR',
|
action: 'ERROR',
|
||||||
error: JSON.stringify(err),
|
error: typeof(err) === 'string' ? err : JSON.stringify(err),
|
||||||
critical: false
|
critical: false
|
||||||
};
|
};
|
||||||
console.error('Login error occurred', msg);
|
console.error('Login error occurred', msg);
|
||||||
@ -669,7 +682,7 @@ wxString ConnectWebViewPanel::get_login_script(bool refresh)
|
|||||||
const claims = JSON.parse(atob(parts[1]));
|
const claims = JSON.parse(atob(parts[1]));
|
||||||
const now = new Date().getTime() / 1000;
|
const now = new Date().getTime() / 1000;
|
||||||
if (claims.exp <= now) {
|
if (claims.exp <= now) {
|
||||||
console.log('Skipping initLogin as token is expired');
|
_prusaSlicer_log('Skipping initLogin as token is expired');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -681,10 +694,10 @@ wxString ConnectWebViewPanel::get_login_script(bool refresh)
|
|||||||
let error = false;
|
let error = false;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
console.log('Slicer Login request');
|
_prusaSlicer_log('Slicer Login request');
|
||||||
let resp = await fetch('/slicer/login', {method: 'POST', headers: {Authorization: 'Bearer ' + token}});
|
let resp = await fetch('/slicer/login', {method: 'POST', headers: {Authorization: 'Bearer ' + token}});
|
||||||
let body = await resp.text();
|
let body = await resp.text();
|
||||||
console.log('Slicer Login resp', resp.status, body);
|
_prusaSlicer_log('Slicer Login resp ' + resp.status + ' body: ' + body);
|
||||||
if (resp.status >= 500 || resp.status == 408) {
|
if (resp.status >= 500 || resp.status == 408) {
|
||||||
retry = true;
|
retry = true;
|
||||||
} else {
|
} else {
|
||||||
@ -693,6 +706,7 @@ wxString ConnectWebViewPanel::get_login_script(bool refresh)
|
|||||||
_prusaSlicer_errorHandler({status: resp.status, body});
|
_prusaSlicer_errorHandler({status: resp.status, body});
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
_prusaSlicer_log('Slicer Login failed: ' + e.toString());
|
||||||
console.error('Slicer Login failed', e.toString());
|
console.error('Slicer Login failed', e.toString());
|
||||||
retry = true;
|
retry = true;
|
||||||
}
|
}
|
||||||
|
@ -184,6 +184,7 @@ public:
|
|||||||
void resend_config();
|
void resend_config();
|
||||||
protected:
|
protected:
|
||||||
// action callbacs stored in m_actions
|
// action callbacs stored in m_actions
|
||||||
|
virtual void on_connect_action_log(const std::string& message_data);
|
||||||
virtual void on_connect_action_error(const std::string& message_data);
|
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_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_request_open_in_browser(const std::string& message_data);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user