From 7ba5718be6670e1d2a3fac991cbec35d4455334c Mon Sep 17 00:00:00 2001 From: Ian Chua Date: Wed, 12 Aug 2026 18:41:51 +0800 Subject: [PATCH] fix: remove redundant cache --- src/slic3r/GUI/DeviceManager.cpp | 2 +- src/slic3r/GUI/MediaFilePanel.cpp | 3 +-- src/slic3r/GUI/MediaFilePanel.h | 1 - src/slic3r/GUI/MediaPlayCtrl.cpp | 20 ++++++++++++-------- src/slic3r/GUI/MediaPlayCtrl.h | 1 - src/slic3r/GUI/SendToPrinter.cpp | 1 - src/slic3r/Utils/BBLPrinterAgent.cpp | 21 +++++++++++++++------ src/slic3r/Utils/BBLPrinterAgent.hpp | 1 + src/slic3r/Utils/IPrinterAgent.hpp | 8 ++++++++ src/slic3r/Utils/NetworkAgent.cpp | 8 ++++++++ src/slic3r/Utils/NetworkAgent.hpp | 1 + 11 files changed, 47 insertions(+), 20 deletions(-) diff --git a/src/slic3r/GUI/DeviceManager.cpp b/src/slic3r/GUI/DeviceManager.cpp index f824fd3ad1..9697408cb6 100644 --- a/src/slic3r/GUI/DeviceManager.cpp +++ b/src/slic3r/GUI/DeviceManager.cpp @@ -2569,7 +2569,7 @@ void MachineObject::set_print_state(std::string status) int MachineObject::connect(bool use_openssl) { if (get_dev_ip().empty()) return -1; - std::string username = "bblp"; + std::string username = m_agent ? m_agent->default_lan_username() : std::string(); std::string password = get_access_code(); if (m_agent) { diff --git a/src/slic3r/GUI/MediaFilePanel.cpp b/src/slic3r/GUI/MediaFilePanel.cpp index ee7b7143d3..0601b96949 100644 --- a/src/slic3r/GUI/MediaFilePanel.cpp +++ b/src/slic3r/GUI/MediaFilePanel.cpp @@ -207,7 +207,6 @@ MediaFilePanel::MediaFilePanel(wxWindow * parent) Bind(wxEVT_SHOW, onShowHide); parent->GetParent()->Bind(wxEVT_SHOW, onShowHide); - m_lan_user = wxGetApp().getAgent()->default_lan_username(); } MediaFilePanel::~MediaFilePanel() @@ -467,7 +466,7 @@ void MediaFilePanel::fetchUrl(boost::weak_ptr wfs) m_waiting_support = false; NetworkAgent *agent = wxGetApp().getAgent(); if (agent && (m_lan_mode || !m_remote_proto) && m_local_proto && !m_lan_ip.empty()) { - std::string url = agent->get_local_camera_url({m_lan_ip, m_lan_user, m_lan_passwd, LVL_None, + std::string url = agent->get_local_camera_url({m_lan_ip, agent->default_lan_username(), m_lan_passwd, LVL_None, m_machine, agent->get_version(), m_dev_ver, "", wxGetApp().app_config->get("slicer_uuid"), SLIC3R_VERSION}); fs->SetUrl(url); return; diff --git a/src/slic3r/GUI/MediaFilePanel.h b/src/slic3r/GUI/MediaFilePanel.h index 72fbc96a13..41596c38c1 100644 --- a/src/slic3r/GUI/MediaFilePanel.h +++ b/src/slic3r/GUI/MediaFilePanel.h @@ -80,7 +80,6 @@ private: std::string m_machine; std::string m_lan_ip; - std::string m_lan_user; std::string m_lan_passwd; std::string m_dev_ver; bool m_lan_mode = false; diff --git a/src/slic3r/GUI/MediaPlayCtrl.cpp b/src/slic3r/GUI/MediaPlayCtrl.cpp index b255bdac32..0a796981d1 100644 --- a/src/slic3r/GUI/MediaPlayCtrl.cpp +++ b/src/slic3r/GUI/MediaPlayCtrl.cpp @@ -7,7 +7,6 @@ #include "I18N.hpp" #include "MsgDialog.hpp" #include "DownloadProgressDialog.hpp" -#include "slic3r/Utils/BBLNetworkPlugin.hpp" #include @@ -127,8 +126,6 @@ MediaPlayCtrl::MediaPlayCtrl(wxWindow *parent, wxMediaCtrl2 *media_ctrl, const w parent->Bind(wxEVT_SHOW, &MediaPlayCtrl::on_show_hide, this); parent->GetParent()->GetParent()->Bind(wxEVT_SHOW, &MediaPlayCtrl::on_show_hide, this); - m_lan_user = "bblp"; - m_lan_passwd = "bblp"; } MediaPlayCtrl::~MediaPlayCtrl() @@ -159,8 +156,10 @@ void MediaPlayCtrl::SetMachineObject(MachineObject* obj) m_device_busy = obj->is_camera_busy_off(); m_tutk_state = obj->tutk_state; - if (DevPrinterConfigUtil::get_printer_series_str(obj->printer_type) == "series_o" && BBLNetworkPlugin::instance().use_legacy_network()) { - // Legacy plugin cannot support remote play for H2D, force using local mode + auto *agent = wxGetApp().getAgent(); + if (agent && !agent->supports_remote_liveview(obj->printer_type)) { + // The selected printer agent may force local mode for incompatible + // plugin/printer combinations. m_remote_proto = LiveviewRemote::LVR_None; } } else { @@ -283,12 +282,17 @@ void MediaPlayCtrl::Play() BOOST_LOG_TRIVIAL(info) << "MediaPlayCtrl::Play: " << m_lan_proto << m_remote_proto << m_disable_lan; NetworkAgent *agent = wxGetApp().getAgent(); - std::string agent_version = agent ? agent->get_version() : ""; + if (!agent) { + Stop(_L("Please confirm if the printer is connected.")); + return; + } + std::string agent_version = agent->get_version(); + const std::string lan_user = agent->default_lan_username(); if (m_lan_proto > LiveviewLocal::LVL_Disable && (m_lan_mode || !m_remote_proto) && !m_disable_lan && !m_lan_ip.empty()) { m_disable_lan = m_remote_proto && !m_lan_mode; // try remote next time std::string url = agent->get_local_camera_url({ m_lan_ip, - m_lan_user, + lan_user, m_lan_passwd, LiveviewLocal(m_lan_proto), into_u8(m_machine), @@ -525,7 +529,7 @@ void MediaPlayCtrl::ToggleStream() if (m_lan_proto > LiveviewLocal::LVL_Disable && (m_lan_mode || !m_remote_proto) && !m_disable_lan && !m_lan_ip.empty()) { NetworkAgent *agent = wxGetApp().getAgent(); if (!agent) return; - std::string url = agent->get_local_camera_url({m_lan_ip, m_lan_user, m_lan_passwd, LiveviewLocal(m_lan_proto), + std::string url = agent->get_local_camera_url({m_lan_ip, agent->default_lan_username(), m_lan_passwd, LiveviewLocal(m_lan_proto), into_u8(m_machine), agent->get_version(), m_dev_ver, "", wxGetApp().app_config->get("slicer_uuid"), SLIC3R_VERSION}); BOOST_LOG_TRIVIAL(info) << "MediaPlayCtrl::ToggleStream: " << hide_passwd(hide_id_middle_string(url, url.find(m_lan_ip), m_lan_ip.length()), {m_lan_passwd}); std::string file_url = data_dir() + "/cameratools/url.txt"; diff --git a/src/slic3r/GUI/MediaPlayCtrl.h b/src/slic3r/GUI/MediaPlayCtrl.h index f5e5dcddfc..5a7c53f695 100644 --- a/src/slic3r/GUI/MediaPlayCtrl.h +++ b/src/slic3r/GUI/MediaPlayCtrl.h @@ -80,7 +80,6 @@ private: std::string m_machine; int m_lan_proto = 0; std::string m_lan_ip; - std::string m_lan_user; std::string m_lan_passwd; std::string m_dev_ver; std::string m_tutk_state; diff --git a/src/slic3r/GUI/SendToPrinter.cpp b/src/slic3r/GUI/SendToPrinter.cpp index acbf911660..10620dbabf 100644 --- a/src/slic3r/GUI/SendToPrinter.cpp +++ b/src/slic3r/GUI/SendToPrinter.cpp @@ -1797,7 +1797,6 @@ void SendToPrinterDialog::show_file_transfer_error(PrintDialogStatus status, wxS if (m_url_timer && m_url_timer->IsRunning()) m_url_timer->Stop(); m_connection_status = ConnectionStatus::CONNECTION_FAILED; - GetConnection(); show_status(status); update_print_status_msg(message, false, true); } diff --git a/src/slic3r/Utils/BBLPrinterAgent.cpp b/src/slic3r/Utils/BBLPrinterAgent.cpp index af6053f721..9a49d86b8a 100644 --- a/src/slic3r/Utils/BBLPrinterAgent.cpp +++ b/src/slic3r/Utils/BBLPrinterAgent.cpp @@ -468,6 +468,15 @@ std::string BBLPrinterAgent::get_local_file_transfer_url(const FileTransferURLPa return "bambu:///local/" + params.ip_address + "?port=6000&user=" + params.username + "&passwd=" + params.password; } +bool BBLPrinterAgent::supports_remote_liveview(const std::string& printer_type) const +{ + // The legacy Bambu networking plugin cannot provide remote live view for + // the O-series printers. Keep this compatibility rule in the Bambu agent + // instead of exposing plugin/version details to GUI code. + return !(DevPrinterConfigUtil::get_printer_series_str(printer_type) == "series_o" && + BBLNetworkPlugin::instance().use_legacy_network()); +} + int BBLPrinterAgent::get_file_transfer_url(std::string dev_id, std::function callback, FileTransferURLParams params) { @@ -490,14 +499,14 @@ int BBLPrinterAgent::get_file_transfer_url(std::string dev_id, std::functionget_camera_url( std::move(dev_id) + "|" + params.device_version + "|" + protocols, - [callback = std::move(callback)](CameraURLResult camera_result) { + [callback = std::move(callback)](CameraURLResult result) { if (!callback) return; - FileTransferURLResult result; - result.is_success = camera_result.is_success; - result.url = std::move(camera_result.url); - result.error_code = camera_result.error_code; - callback(std::move(result)); + FileTransferURLResult transfer_result; + transfer_result.is_success = result.is_success; + transfer_result.url = std::move(result.url); + transfer_result.error_code = result.error_code; + callback(std::move(transfer_result)); }, CameraURLParams{ "", diff --git a/src/slic3r/Utils/BBLPrinterAgent.hpp b/src/slic3r/Utils/BBLPrinterAgent.hpp index 8d767faa1c..63d796a806 100644 --- a/src/slic3r/Utils/BBLPrinterAgent.hpp +++ b/src/slic3r/Utils/BBLPrinterAgent.hpp @@ -118,6 +118,7 @@ public: int send_message_to_printer(std::string dev_id, std::string json_str, int qos, int flag) override; std::string get_local_camera_url(CameraURLParams params) override; std::string get_local_file_transfer_url(const FileTransferURLParams& params) override; + bool supports_remote_liveview(const std::string& printer_type) const override; int get_file_transfer_url(std::string dev_id, std::function callback, FileTransferURLParams params) override; std::string default_lan_username() const override { return "bblp"; } diff --git a/src/slic3r/Utils/IPrinterAgent.hpp b/src/slic3r/Utils/IPrinterAgent.hpp index 08e72aa906..3b4a72e00b 100644 --- a/src/slic3r/Utils/IPrinterAgent.hpp +++ b/src/slic3r/Utils/IPrinterAgent.hpp @@ -197,6 +197,14 @@ public: */ virtual std::string get_local_file_transfer_url(const FileTransferURLParams& params) { return ""; } + /** + * Whether remote live view is available for the selected printer and agent + * protocol. Implementations may use their plugin/version compatibility + * rules; the neutral default keeps existing agents permissive. + */ + virtual bool supports_remote_liveview(const std::string& printer_type) const + { (void) printer_type; return true; } + virtual int get_file_transfer_url(std::string, std::function callback, FileTransferURLParams) { if (callback) diff --git a/src/slic3r/Utils/NetworkAgent.cpp b/src/slic3r/Utils/NetworkAgent.cpp index 62a2e21f51..f93a0cf882 100644 --- a/src/slic3r/Utils/NetworkAgent.cpp +++ b/src/slic3r/Utils/NetworkAgent.cpp @@ -868,6 +868,14 @@ std::string NetworkAgent::get_local_file_transfer_url(const FileTransferURLParam return {}; } +bool NetworkAgent::supports_remote_liveview(const std::string& printer_type) const +{ + // Preserve the historical permissive behavior while the printer agent is + // being selected. A missing agent must not turn a supported remote + // protocol into LVNone before the Bambu agent has been installed. + return !m_printer_agent || m_printer_agent->supports_remote_liveview(printer_type); +} + int NetworkAgent::get_file_transfer_url(std::string dev_id, std::function callback, FileTransferURLParams params) { diff --git a/src/slic3r/Utils/NetworkAgent.hpp b/src/slic3r/Utils/NetworkAgent.hpp index 0f3a055e03..75cca1e314 100644 --- a/src/slic3r/Utils/NetworkAgent.hpp +++ b/src/slic3r/Utils/NetworkAgent.hpp @@ -207,6 +207,7 @@ public: int send_message_to_printer(std::string dev_id, std::string json_str, int qos, int flag); std::string get_local_camera_url(CameraURLParams params); std::string get_local_file_transfer_url(const FileTransferURLParams& params); + bool supports_remote_liveview(const std::string& printer_type) const; int get_file_transfer_url(std::string dev_id, std::function callback, FileTransferURLParams params = {}); std::string default_lan_username() const;