mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-06-12 23:13:32 +00:00
Support file uploads and the device details page for Elegoo Centauri Carbon 2 (#13212)
* Support file uploads and the device details page for CC2 printers. * Resolved build issues for Linux and macOS. * 1. Added `ElegooPrinterWebViewHandler` to handle WebUI messages for Elegoo printers. Other printers will keep the current behavior. 2. Added a static `get_print_host_webui` method in `PrintHost` to retrieve the printer WebUI URL. * Improved timeout handling for CC2 file upload and SN info APIs. --------- Co-authored-by: SoftFever <softfeverever@gmail.com>
This commit is contained in:
@@ -1,16 +1,17 @@
|
||||
#include "PrinterWebView.hpp"
|
||||
|
||||
#include "I18N.hpp"
|
||||
#include "PrinterWebViewHandler.hpp"
|
||||
#include "slic3r/GUI/PrinterWebView.hpp"
|
||||
#include "slic3r/GUI/wxExtensions.hpp"
|
||||
#include "slic3r/GUI/GUI_App.hpp"
|
||||
#include "slic3r/GUI/MainFrame.hpp"
|
||||
#include "libslic3r_version.h"
|
||||
|
||||
#include <boost/filesystem/path.hpp>
|
||||
#include <wx/sizer.h>
|
||||
#include <wx/string.h>
|
||||
#include <wx/toolbar.h>
|
||||
#include <wx/textdlg.h>
|
||||
|
||||
#include <slic3r/GUI/Widgets/WebView.hpp>
|
||||
#include <wx/webview.h>
|
||||
@@ -19,13 +20,17 @@
|
||||
#include <webkit2/webkit2.h>
|
||||
#endif
|
||||
|
||||
namespace pt = boost::property_tree;
|
||||
|
||||
namespace Slic3r {
|
||||
namespace GUI {
|
||||
|
||||
PrinterWebView::PrinterWebView(wxWindow *parent)
|
||||
: wxPanel(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize)
|
||||
, m_browser(nullptr)
|
||||
, m_zoomFactor(100)
|
||||
, m_apikey()
|
||||
, m_apikey_sent(false)
|
||||
, m_url_deferred()
|
||||
, m_handler(std::make_unique<PrinterWebViewHandler>(*this))
|
||||
{
|
||||
|
||||
wxBoxSizer* topsizer = new wxBoxSizer(wxVERTICAL);
|
||||
@@ -47,6 +52,8 @@ PrinterWebView::PrinterWebView(wxWindow *parent)
|
||||
|
||||
m_browser->Bind(wxEVT_WEBVIEW_ERROR, &PrinterWebView::OnError, this);
|
||||
m_browser->Bind(wxEVT_WEBVIEW_LOADED, &PrinterWebView::OnLoaded, this);
|
||||
m_browser->Bind(wxEVT_WEBVIEW_NEWWINDOW, &PrinterWebView::OnNewWindow, this);
|
||||
m_browser->Bind(wxEVT_WEBVIEW_SCRIPT_MESSAGE_RECEIVED, &PrinterWebView::OnScriptMessage, this);
|
||||
|
||||
SetSizer(topsizer);
|
||||
|
||||
@@ -64,9 +71,6 @@ PrinterWebView::PrinterWebView(wxWindow *parent)
|
||||
}
|
||||
*/
|
||||
|
||||
//Zoom
|
||||
m_zoomFactor = 100;
|
||||
|
||||
//Connect the idle events
|
||||
Bind(wxEVT_CLOSE_WINDOW, &PrinterWebView::OnClose, this);
|
||||
|
||||
@@ -76,11 +80,18 @@ PrinterWebView::~PrinterWebView()
|
||||
{
|
||||
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " Start";
|
||||
SetEvtHandlerEnabled(false);
|
||||
m_handler.reset();
|
||||
|
||||
// Destroy the webview
|
||||
if(m_browser){
|
||||
m_browser->Destroy();
|
||||
m_browser = nullptr;
|
||||
}
|
||||
|
||||
|
||||
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " End";
|
||||
}
|
||||
|
||||
|
||||
void PrinterWebView::load_url(wxString& url, wxString apikey)
|
||||
{
|
||||
// this->Show();
|
||||
@@ -89,6 +100,7 @@ void PrinterWebView::load_url(wxString& url, wxString apikey)
|
||||
return;
|
||||
m_apikey = apikey;
|
||||
m_apikey_sent = false;
|
||||
m_handler = create_printer_webview_handler(*this);
|
||||
|
||||
if (this->IsShown()) {
|
||||
//ORCA: m_url_deferred will be cleared on load success
|
||||
@@ -190,14 +202,34 @@ void PrinterWebView::OnError(wxWebViewEvent &evt)
|
||||
BOOST_LOG_TRIVIAL(info) << __FUNCTION__<< boost::format(": error loading page %1% %2% %3% %4%") %evt.GetURL() %evt.GetTarget() %e %evt.GetString();
|
||||
}
|
||||
|
||||
void PrinterWebView::OnLoaded(wxWebViewEvent &evt)
|
||||
void PrinterWebView::OnLoaded(wxWebViewEvent& evt)
|
||||
{
|
||||
if (evt.GetURL().IsEmpty())
|
||||
return;
|
||||
//ORCA: url loaded successfully, safe to clear
|
||||
m_url_deferred.clear();
|
||||
SendAPIKey();
|
||||
|
||||
if (m_handler != nullptr) {
|
||||
m_handler->on_loaded(evt);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void PrinterWebView::OnNewWindow(wxWebViewEvent& evt)
|
||||
{
|
||||
const wxString url = evt.GetURL();
|
||||
if (!url.empty())
|
||||
wxLaunchDefaultBrowser(url);
|
||||
evt.Veto();
|
||||
}
|
||||
|
||||
void PrinterWebView::OnScriptMessage(wxWebViewEvent& evt)
|
||||
{
|
||||
if (m_handler != nullptr)
|
||||
m_handler->on_script_message(evt);
|
||||
}
|
||||
|
||||
|
||||
} // GUI
|
||||
} // Slic3r
|
||||
|
||||
Reference in New Issue
Block a user