diff --git a/src/slic3r/GUI/MainFrame.cpp b/src/slic3r/GUI/MainFrame.cpp index e35723912b..2ec5139f6a 100644 --- a/src/slic3r/GUI/MainFrame.cpp +++ b/src/slic3r/GUI/MainFrame.cpp @@ -878,6 +878,7 @@ void MainFrame::remove_connect_webview_tab() m_tabpanel->SetSelection(0); dynamic_cast(m_tabpanel)->RemovePage(4); m_connect_webview_added = false; + m_connect_webview->logout(); } void MainFrame::add_printer_webview_tab(const wxString& url) @@ -1188,6 +1189,9 @@ void MainFrame::on_sys_color_changed() for (auto tab : wxGetApp().tabs_list) tab->sys_color_changed(); + m_connect_webview->sys_color_changed(); + m_printer_webview->sys_color_changed(); + MenuFactory::sys_color_changed(m_menubar); this->Refresh(); diff --git a/src/slic3r/GUI/MainFrame.hpp b/src/slic3r/GUI/MainFrame.hpp index fd67f7149e..4206c4496e 100644 --- a/src/slic3r/GUI/MainFrame.hpp +++ b/src/slic3r/GUI/MainFrame.hpp @@ -43,7 +43,7 @@ class Plater; class MainFrame; class PreferencesDialog; class GalleryDialog; -class WebViewPanel; +class ConnectWebViewPanel; class PrinterWebViewPanel; enum QuickSlice @@ -98,7 +98,7 @@ class MainFrame : public DPIFrame size_t m_last_selected_tab; Search::OptionsSearcher m_searcher; - WebViewPanel* m_connect_webview{ nullptr }; + ConnectWebViewPanel* m_connect_webview{ nullptr }; bool m_connect_webview_added{ false }; PrinterWebViewPanel* m_printer_webview{ nullptr }; bool m_printer_webview_added{ false }; diff --git a/src/slic3r/GUI/WebViewDialog.cpp b/src/slic3r/GUI/WebViewDialog.cpp index 7209a8f941..2111350252 100644 --- a/src/slic3r/GUI/WebViewDialog.cpp +++ b/src/slic3r/GUI/WebViewDialog.cpp @@ -423,6 +423,12 @@ case type: \ #endif } +void WebViewPanel::sys_color_changed() +{ +#ifdef _WIN32 + wxGetApp().UpdateDarkUI(this); +#endif +} SourceViewDialog::SourceViewDialog(wxWindow* parent, wxString source) : wxDialog(parent, wxID_ANY, "Source Code", @@ -444,10 +450,8 @@ ConnectRequestHandler::ConnectRequestHandler() { m_actions["REQUEST_ACCESS_TOKEN"] = std::bind(&ConnectRequestHandler::on_request_access_token, this); m_actions["REQUEST_CONFIG"] = std::bind(&ConnectRequestHandler::on_request_config, this); - m_actions["REQUEST_LANGUAGE"] = std::bind(&ConnectRequestHandler::on_request_language_action, this); - m_actions["REQUEST_SESSION_ID"] = std::bind(&ConnectRequestHandler::on_request_session_id_action, this); m_actions["UPDATE_SELECTED_PRINTER"] = std::bind(&ConnectRequestHandler::on_request_update_selected_printer_action, this); - + m_actions["WEBAPP_READY"] = std::bind(&ConnectRequestHandler::request_compatible_printers, this); } ConnectRequestHandler::~ConnectRequestHandler() { @@ -486,6 +490,12 @@ void ConnectRequestHandler::handle_message(const std::string& message) m_actions[action_string](); } } + +void ConnectRequestHandler::resend_config() +{ + on_request_config(); +} + void ConnectRequestHandler::on_request_access_token() { std::string token = wxGetApp().plater()->get_user_account()->get_access_token(); @@ -512,23 +522,6 @@ void ConnectRequestHandler::on_request_config() run_script_bridge(script); } -void ConnectRequestHandler::on_request_language_action() -{ - assert(true); - // TODO: - //std::string lang = "en"; - //wxString script = GUI::format_wxstr("window._prusaConnect_v1.setAccessToken(\'en\')", lang); - //run_script(script); -} -void ConnectRequestHandler::on_request_session_id_action() -{ - assert(true); - /* - std::string token = wxGetApp().plater()->get_user_account()->get_access_token(); - wxString script = GUI::format_wxstr("window._prusaConnect_v1.setAccessToken(\'%1%\')", token); - run_script(script); - */ -} ConnectWebViewPanel::ConnectWebViewPanel(wxWindow* parent) : WebViewPanel(parent, L"https://dev.connect.prusa3d.com/connect-slicer-app/") @@ -541,6 +534,17 @@ void ConnectWebViewPanel::on_script_message(wxWebViewEvent& evt) handle_message(into_u8(evt.GetString())); } +void ConnectWebViewPanel::logout() +{ + wxString script = L"window._prusaConnect_v1.logout()"; + run_script(script); +} + +void ConnectWebViewPanel::sys_color_changed() +{ + resend_config(); +} + void ConnectWebViewPanel::on_request_update_selected_printer_action() { assert(!m_message_data.empty()); @@ -615,6 +619,9 @@ void PrinterWebViewPanel::send_credentials() } +void PrinterWebViewPanel::sys_color_changed() +{ +} WebViewDialog::WebViewDialog(wxWindow* parent, const wxString& url, const wxString& dialog_name, const wxSize& size) : wxDialog(parent, wxID_ANY, dialog_name, wxDefaultPosition, size, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER) @@ -650,7 +657,6 @@ PrinterPickWebViewDialog::PrinterPickWebViewDialog(wxWindow* parent, std::string : WebViewDialog(parent, L"https://dev.connect.prusa3d.com/connect-slicer-app/printer-list", _L("Choose a printer"), wxSize(std::max(parent->GetClientSize().x / 2, 100 * wxGetApp().em_unit()), std::max(parent->GetClientSize().y / 2, 50 * wxGetApp().em_unit()))) , m_ret_val(ret_val) { - m_actions["WEBAPP_READY"] = std::bind(&PrinterPickWebViewDialog::request_compatible_printers, this); Centre(); } void PrinterPickWebViewDialog::on_show(wxShowEvent& evt) diff --git a/src/slic3r/GUI/WebViewDialog.hpp b/src/slic3r/GUI/WebViewDialog.hpp index ae1bdbe665..2dfbcbf6a7 100644 --- a/src/slic3r/GUI/WebViewDialog.hpp +++ b/src/slic3r/GUI/WebViewDialog.hpp @@ -72,6 +72,7 @@ public: wxString get_default_url() const { return m_default_url; } void set_default_url(const wxString& url) { m_default_url = url; } + virtual void sys_color_changed(); protected: wxWebView* m_browser; @@ -112,14 +113,14 @@ public: ~ConnectRequestHandler(); void handle_message(const std::string& message); + void resend_config(); protected: // action callbacs stored in m_actions virtual void on_request_access_token(); virtual void on_request_config(); - virtual void on_request_language_action(); - virtual void on_request_session_id_action(); virtual void on_request_update_selected_printer_action() = 0; virtual void run_script_bridge(const wxString& script) = 0; + virtual void request_compatible_printers() = 0; std::map> m_actions; std::string m_message_data; @@ -131,8 +132,11 @@ class ConnectWebViewPanel : public WebViewPanel, public ConnectRequestHandler public: ConnectWebViewPanel(wxWindow* parent); void on_script_message(wxWebViewEvent& evt) override; + void logout(); + void sys_color_changed() override; protected: void on_request_update_selected_printer_action() override; + void request_compatible_printers() override {} void run_script_bridge(const wxString& script) override {run_script(script); } }; @@ -148,6 +152,7 @@ public: void set_api_key(const std::string& key) { m_api_key = key; } void set_credentials(const std::string& usr, const std::string& psk) { m_usr = usr; m_psk = psk; } void clear() { m_api_key.clear(); m_usr.clear(); m_psk.clear(); m_api_key_sent = false; } + void sys_color_changed() override; private: std::string m_api_key; std::string m_usr; @@ -179,9 +184,9 @@ public: void on_script_message(wxWebViewEvent& evt) override; protected: void on_request_update_selected_printer_action() override; + void request_compatible_printers() override; void run_script_bridge(const wxString& script) override { run_script(script); } private: - void request_compatible_printers(); std::string& m_ret_val; };