From e8de4b7199d0a1b999a57ca9306f402b6e6b638b Mon Sep 17 00:00:00 2001
From: David Kocik
Date: Tue, 20 Aug 2024 12:24:07 +0200
Subject: [PATCH 01/12] Create Printables tab
---
src/slic3r/GUI/MainFrame.cpp | 28 ++++++++++++++++++++++++++++
src/slic3r/GUI/MainFrame.hpp | 14 ++++++++++----
src/slic3r/GUI/Plater.cpp | 4 ++++
3 files changed, 42 insertions(+), 4 deletions(-)
diff --git a/src/slic3r/GUI/MainFrame.cpp b/src/slic3r/GUI/MainFrame.cpp
index f67643b55d..cbfba459a5 100644
--- a/src/slic3r/GUI/MainFrame.cpp
+++ b/src/slic3r/GUI/MainFrame.cpp
@@ -803,6 +803,7 @@ void MainFrame::create_preset_tabs()
m_connect_webview = new ConnectWebViewPanel(m_tabpanel);
m_printer_webview = new PrinterWebViewPanel(m_tabpanel, L"");
+ m_printables_webview = new WebViewPanel(m_tabpanel, GUI::from_u8("https://www.printables.com"), { "_prusaSlicer" });
// new created tabs have to be hidden by default
m_connect_webview->Hide();
m_printer_webview->Hide();
@@ -849,6 +850,33 @@ void MainFrame::show_connect_tab(const wxString& url)
m_connect_webview->load_url(url);
}
+void MainFrame::add_printables_webview_tab()
+{
+ if (m_printables_webview_added) {
+ return;
+ }
+
+ int n = m_tabpanel->FindPage(m_connect_webview) + 1;
+ wxWindow* page = m_printables_webview;
+ const wxString text(L"Printables");
+ const std::string bmp_name = "";
+ bool bSelect = false;
+ m_tabpanel->InsertNewPage(n, page, text, bmp_name, bSelect);
+ m_printables_webview->load_default_url_delayed();
+ m_printables_webview_added = true;
+}
+void MainFrame::remove_printables_webview_tab()
+{
+ if (!m_printables_webview_added) {
+ return;
+ }
+ int n = m_tabpanel->FindPage(m_printables_webview);
+ if (m_tabpanel->GetSelection() == n)
+ m_tabpanel->SetSelection(0);
+ m_tabpanel->RemovePage(size_t(n));
+ m_printables_webview_added = false;
+}
+
void MainFrame::show_printer_webview_tab(DynamicPrintConfig* dpc)
{
// if physical printer is selected
diff --git a/src/slic3r/GUI/MainFrame.hpp b/src/slic3r/GUI/MainFrame.hpp
index 4b2306ec23..4cb184605d 100644
--- a/src/slic3r/GUI/MainFrame.hpp
+++ b/src/slic3r/GUI/MainFrame.hpp
@@ -47,6 +47,7 @@ class PreferencesDialog;
class GalleryDialog;
class ConnectWebViewPanel;
class PrinterWebViewPanel;
+class WebViewPanel;
enum QuickSlice
{
@@ -98,10 +99,12 @@ class MainFrame : public DPIFrame
size_t m_last_selected_tab;
Search::OptionsSearcher m_searcher;
- ConnectWebViewPanel* m_connect_webview{ nullptr };
- bool m_connect_webview_added{ false };
- PrinterWebViewPanel* m_printer_webview{ nullptr };
- bool m_printer_webview_added{ false };
+ ConnectWebViewPanel* m_connect_webview{ nullptr };
+ bool m_connect_webview_added{ false };
+ WebViewPanel* m_printables_webview{ nullptr };
+ bool m_printables_webview_added{ false };
+ PrinterWebViewPanel* m_printer_webview{ nullptr };
+ bool m_printer_webview_added{ false };
std::string get_base_name(const wxString &full_name, const char *extension = nullptr) const;
std::string get_dir_name(const wxString &full_name) const;
@@ -218,6 +221,9 @@ public:
void remove_connect_webview_tab();
void show_connect_tab(const wxString &url);
+ void add_printables_webview_tab();
+ void remove_printables_webview_tab();
+
void show_printer_webview_tab(DynamicPrintConfig* dpc);
void add_printer_webview_tab(const wxString& url);
diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp
index 681d12ca83..3d84240587 100644
--- a/src/slic3r/GUI/Plater.cpp
+++ b/src/slic3r/GUI/Plater.cpp
@@ -921,6 +921,7 @@ Plater::priv::priv(Plater *q, MainFrame *main_frame)
this->notification_manager->close_notification_of_type(NotificationType::UserAccountID);
this->notification_manager->push_notification(NotificationType::UserAccountID, NotificationManager::NotificationLevel::ImportantNotificationLevel, text);
this->main_frame->remove_connect_webview_tab();
+ this->main_frame->remove_printables_webview_tab();
this->main_frame->refresh_account_menu(true);
// Update sidebar printer status
sidebar->update_printer_presets_combobox();
@@ -946,6 +947,7 @@ Plater::priv::priv(Plater *q, MainFrame *main_frame)
this->notification_manager->push_notification(NotificationType::UserAccountID, NotificationManager::NotificationLevel::ImportantNotificationLevel, text);
}
this->main_frame->add_connect_webview_tab();
+ this->main_frame->add_printables_webview_tab();
// Update User name in TopBar
this->main_frame->refresh_account_menu();
wxGetApp().update_wizard_login_page();
@@ -959,6 +961,7 @@ Plater::priv::priv(Plater *q, MainFrame *main_frame)
this->notification_manager->close_notification_of_type(NotificationType::UserAccountID);
this->notification_manager->push_notification(NotificationType::UserAccountID, NotificationManager::NotificationLevel::WarningNotificationLevel, _u8L("Failed to connect to Prusa Account."));
this->main_frame->remove_connect_webview_tab();
+ this->main_frame->remove_printables_webview_tab();
// Update User name in TopBar
this->main_frame->refresh_account_menu(true);
// Update sidebar printer status
@@ -972,6 +975,7 @@ Plater::priv::priv(Plater *q, MainFrame *main_frame)
this->notification_manager->close_notification_of_type(NotificationType::UserAccountID);
this->notification_manager->push_notification(NotificationType::UserAccountID, NotificationManager::NotificationLevel::WarningNotificationLevel, _u8L("Failed to connect to Prusa Account."));
this->main_frame->remove_connect_webview_tab();
+ this->main_frame->remove_printables_webview_tab();
// Update User name in TopBar
this->main_frame->refresh_account_menu(true);
// Update sidebar printer status
From 1040332c87b89e1870d80756d8eb5fd7483f9c2b Mon Sep 17 00:00:00 2001
From: David Kocik
Date: Wed, 4 Sep 2024 15:06:19 +0200
Subject: [PATCH 02/12] SPE-2468: Printables WebView class
read address and download model
Printables as pernament tab
webview debug panel
adding token to request header
Logout to Printables
Correct user-agent
Receiving printables events
Improved refreshing of token to printables
User settings to printables url
merge changes
Changed login to Printables during runtime
Logging in plater fix
---
src/slic3r/CMakeLists.txt | 4 +
src/slic3r/GUI/ConnectRequestHandler.cpp | 133 +++
src/slic3r/GUI/ConnectRequestHandler.hpp | 44 +
src/slic3r/GUI/Downloader.cpp | 41 +-
src/slic3r/GUI/DownloaderFileGet.cpp | 15 -
src/slic3r/GUI/DownloaderFileGet.hpp | 1 -
src/slic3r/GUI/GUI_App.cpp | 7 +-
src/slic3r/GUI/GUI_App.hpp | 2 +-
src/slic3r/GUI/MainFrame.cpp | 36 +-
src/slic3r/GUI/MainFrame.hpp | 13 +-
src/slic3r/GUI/Plater.cpp | 27 +-
src/slic3r/GUI/UserAccountSession.cpp | 2 +
src/slic3r/GUI/UserAccountSession.hpp | 1 +
src/slic3r/GUI/WebView.cpp | 11 +-
src/slic3r/GUI/WebViewDialog.cpp | 903 ---------------
src/slic3r/GUI/WebViewDialog.hpp | 177 +--
src/slic3r/GUI/WebViewPanel.cpp | 1077 ++++++++++++++++++
src/slic3r/GUI/WebViewPanel.hpp | 195 ++++
src/slic3r/GUI/WebViewPlatformUtils.hpp | 3 +
src/slic3r/GUI/WebViewPlatformUtilsLinux.cpp | 39 +-
src/slic3r/GUI/WebViewPlatformUtilsMac.mm | 22 +-
src/slic3r/GUI/WebViewPlatformUtilsWin32.cpp | 145 +++
src/slic3r/Utils/ServiceConfig.cpp | 5 +-
src/slic3r/Utils/ServiceConfig.hpp | 3 +
24 files changed, 1769 insertions(+), 1137 deletions(-)
create mode 100644 src/slic3r/GUI/ConnectRequestHandler.cpp
create mode 100644 src/slic3r/GUI/ConnectRequestHandler.hpp
create mode 100644 src/slic3r/GUI/WebViewPanel.cpp
create mode 100644 src/slic3r/GUI/WebViewPanel.hpp
diff --git a/src/slic3r/CMakeLists.txt b/src/slic3r/CMakeLists.txt
index 608043efdf..9604c77d66 100644
--- a/src/slic3r/CMakeLists.txt
+++ b/src/slic3r/CMakeLists.txt
@@ -29,6 +29,10 @@ set(SLIC3R_GUI_SOURCES
GUI/UserAccount.hpp
GUI/WebViewDialog.cpp
GUI/WebViewDialog.hpp
+ GUI/WebViewPanel.cpp
+ GUI/WebViewPanel.hpp
+ GUI/ConnectRequestHandler.cpp
+ GUI/ConnectRequestHandler.hpp
GUI/WebView.cpp
GUI/WebView.hpp
GUI/WebViewPlatformUtils.hpp
diff --git a/src/slic3r/GUI/ConnectRequestHandler.cpp b/src/slic3r/GUI/ConnectRequestHandler.cpp
new file mode 100644
index 0000000000..7a156bc78b
--- /dev/null
+++ b/src/slic3r/GUI/ConnectRequestHandler.cpp
@@ -0,0 +1,133 @@
+#include "ConnectRequestHandler.hpp"
+
+#include "slic3r/GUI/I18N.hpp"
+#include "slic3r/GUI/format.hpp"
+#include "slic3r/GUI/GUI_App.hpp"
+#include "slic3r/GUI/GUI.hpp"
+#include "slic3r/GUI/Plater.hpp"
+#include "slic3r/GUI/UserAccount.hpp"
+
+#include
+#include
+#include
+
+namespace pt = boost::property_tree;
+
+namespace Slic3r::GUI {
+
+ConnectRequestHandler::ConnectRequestHandler()
+{
+ m_actions["REQUEST_LOGIN"] = std::bind(&ConnectRequestHandler::on_connect_action_request_login, this, std::placeholders::_1);
+ m_actions["REQUEST_CONFIG"] = std::bind(&ConnectRequestHandler::on_connect_action_request_config, this, std::placeholders::_1);
+ m_actions["WEBAPP_READY"] = std::bind(&ConnectRequestHandler::on_connect_action_webapp_ready,this, std::placeholders::_1);
+ 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);
+ m_actions["LOG"] = std::bind(&ConnectRequestHandler::on_connect_action_log, this, std::placeholders::_1);
+}
+ConnectRequestHandler::~ConnectRequestHandler()
+{
+}
+void ConnectRequestHandler::handle_message(const std::string& message)
+{
+ // read msg and choose action
+ /*
+ v0:
+ {"type":"request","detail":{"action":"requestAccessToken"}}
+ v1:
+ {"action":"REQUEST_ACCESS_TOKEN"}
+ */
+ std::string action_string;
+ try {
+ std::stringstream ss(message);
+ pt::ptree ptree;
+ pt::read_json(ss, ptree);
+ // v1:
+ if (const auto action = ptree.get_optional("action"); action) {
+ action_string = *action;
+ }
+ }
+ catch (const std::exception& e) {
+ BOOST_LOG_TRIVIAL(error) << "Could not parse _prusaConnect message. " << e.what();
+ return;
+ }
+
+ if (action_string.empty()) {
+ BOOST_LOG_TRIVIAL(error) << "Recieved invalid message from _prusaConnect (missing action). Message: " << message;
+ return;
+ }
+ assert(m_actions.find(action_string) != m_actions.end()); // this assert means there is a action that has no handling.
+ if (m_actions.find(action_string) != m_actions.end()) {
+ m_actions[action_string](message);
+ }
+}
+
+void ConnectRequestHandler::on_connect_action_error(const std::string &message_data)
+{
+ BOOST_LOG_TRIVIAL(error) << "WebView runtime error: " << message_data;
+}
+
+void ConnectRequestHandler::resend_config()
+{
+ on_connect_action_request_config({});
+}
+
+void ConnectRequestHandler::on_connect_action_log(const std::string& message_data)
+{
+ BOOST_LOG_TRIVIAL(info) << "WebView log: " << message_data;
+}
+
+void ConnectRequestHandler::on_connect_action_request_login(const std::string &message_data)
+{}
+
+void ConnectRequestHandler::on_connect_action_request_config(const std::string& message_data)
+{
+ /*
+ accessToken?: string;
+ clientVersion?: string;
+ colorMode?: "LIGHT" | "DARK";
+ language?: ConnectLanguage;
+ sessionId?: string;
+ */
+ const std::string token = wxGetApp().plater()->get_user_account()->get_access_token();
+ //const std::string sesh = wxGetApp().plater()->get_user_account()->get_shared_session_key();
+ const std::string dark_mode = wxGetApp().dark_mode() ? "DARK" : "LIGHT";
+ wxString language = GUI::wxGetApp().current_language_code();
+ language = language.SubString(0, 1);
+ const std::string init_options = GUI::format("{\"accessToken\": \"%4%\",\"clientVersion\": \"%1%\", \"colorMode\": \"%2%\", \"language\": \"%3%\"}", SLIC3R_VERSION, dark_mode, language, token );
+ wxString script = GUI::format_wxstr("window._prusaConnect_v1.init(%1%)", init_options);
+ run_script_bridge(script);
+
+}
+void ConnectRequestHandler::on_connect_action_request_open_in_browser(const std::string& message_data)
+{
+ try {
+ std::stringstream ss(message_data);
+ pt::ptree ptree;
+ pt::read_json(ss, ptree);
+ if (const auto url = ptree.get_optional("url"); url) {
+ wxGetApp().open_browser_with_warning_dialog(GUI::from_u8(*url));
+ }
+ } catch (const std::exception &e) {
+ BOOST_LOG_TRIVIAL(error) << "Could not parse _prusaConnect message. " << e.what();
+ return;
+ }
+}
+
+SourceViewDialog::SourceViewDialog(wxWindow* parent, wxString source) :
+ wxDialog(parent, wxID_ANY, "Source Code",
+ wxDefaultPosition, wxSize(700,500),
+ wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER)
+{
+ wxTextCtrl* text = new wxTextCtrl(this, wxID_ANY, source,
+ wxDefaultPosition, wxDefaultSize,
+ wxTE_MULTILINE |
+ wxTE_RICH |
+ wxTE_READONLY);
+
+ wxBoxSizer* sizer = new wxBoxSizer(wxVERTICAL);
+ sizer->Add(text, 1, wxEXPAND);
+ SetSizer(sizer);
+}
+} // namespace Slic3r::GUI
\ No newline at end of file
diff --git a/src/slic3r/GUI/ConnectRequestHandler.hpp b/src/slic3r/GUI/ConnectRequestHandler.hpp
new file mode 100644
index 0000000000..ea64913977
--- /dev/null
+++ b/src/slic3r/GUI/ConnectRequestHandler.hpp
@@ -0,0 +1,44 @@
+#ifndef slic3r_ConnectRequestHandler_hpp_
+#define slic3r_ConnectRequestHandler_hpp_
+
+#include
+