diff --git a/src/slic3r/GUI/SyncAmsInfoDialog.cpp b/src/slic3r/GUI/SyncAmsInfoDialog.cpp index 3c3ea8b609..43922e3fac 100644 --- a/src/slic3r/GUI/SyncAmsInfoDialog.cpp +++ b/src/slic3r/GUI/SyncAmsInfoDialog.cpp @@ -3176,6 +3176,7 @@ SyncAmsInfoDialog::~SyncAmsInfoDialog() { void SyncAmsInfoDialog::set_info(SyncInfo &info) { m_input_info = info; + reinit_dialog(); } void SyncAmsInfoDialog::update_lan_machine_list() diff --git a/src/slic3r/Utils/MoonrakerPrinterAgent.cpp b/src/slic3r/Utils/MoonrakerPrinterAgent.cpp index c89a34ed19..149936d77b 100644 --- a/src/slic3r/Utils/MoonrakerPrinterAgent.cpp +++ b/src/slic3r/Utils/MoonrakerPrinterAgent.cpp @@ -246,6 +246,7 @@ int MoonrakerPrinterAgent::connect_printer(std::string dev_id, std::string dev_i } ws_last_emit_ms.store(0); ws_last_dispatch_ms.store(0); + ams_last_fetch_ms.store(0); last_print_state.clear(); // Launch connection in background thread (capture by value to avoid data races) @@ -2090,6 +2091,12 @@ void MoonrakerPrinterAgent::run_status_stream(std::string dev_id, std::string ba subscribe["id"] = 1; ws.write(net::buffer(subscribe.dump())); + // Eager fetch so AMS data is available immediately after connecting, + // without waiting on the loop's own refresh clock below. + fetch_filament_info(dev_id, FilamentSyncMode::subscription); + ams_last_fetch_ms.store(static_cast( + std::chrono::duration_cast(std::chrono::steady_clock::now().time_since_epoch()).count())); + // Read loop while (!ws_stop.load()) { ws.next_layer().expires_after(std::chrono::seconds(2)); @@ -2101,8 +2108,6 @@ void MoonrakerPrinterAgent::run_status_stream(std::string dev_id, std::string ba std::chrono::duration_cast(std::chrono::steady_clock::now().time_since_epoch()).count()); const auto last_ms = ws_last_emit_ms.load(); if (last_ms == 0 || now_ms - last_ms >= 10000) { - fetch_filament_info(dev_id, FilamentSyncMode::subscription); - nlohmann::json message; { std::lock_guard lock(payload_mutex); @@ -2122,8 +2127,19 @@ void MoonrakerPrinterAgent::run_status_stream(std::string dev_id, std::string ba connection_lost = true; break; } + // AMS/filament refresh on its own clock: gated independently of + // ws_last_emit_ms so a steady telemetry stream can't starve it. + { + const auto now_ms = static_cast( + std::chrono::duration_cast(std::chrono::steady_clock::now().time_since_epoch()).count()); + const auto last_ams_ms = ams_last_fetch_ms.load(); + if (last_ams_ms == 0 || now_ms - last_ams_ms >= AMS_REFRESH_INTERVAL_MS) { + fetch_filament_info(dev_id, FilamentSyncMode::subscription); + ams_last_fetch_ms.store(now_ms); + } + } handle_ws_message(dev_id, beast::buffers_to_string(buffer.data()), base_url, api_key); - // Check if handle_ws_message triggered reconnection request + // Check if handle_ws_message triggered reconnection request` if (ws_reconnect_requested.exchange(false)) { connection_lost = true; break; diff --git a/src/slic3r/Utils/MoonrakerPrinterAgent.hpp b/src/slic3r/Utils/MoonrakerPrinterAgent.hpp index 29ebefdc4b..62e5ca7846 100644 --- a/src/slic3r/Utils/MoonrakerPrinterAgent.hpp +++ b/src/slic3r/Utils/MoonrakerPrinterAgent.hpp @@ -233,6 +233,11 @@ private: std::atomic ws_last_emit_ms{0}; std::thread ws_thread; + // AMS/filament refresh cadence, independent of telemetry dispatch so a steady + // stream of status updates can't starve it (ws_last_emit_ms is reset by those). + static constexpr uint64_t AMS_REFRESH_INTERVAL_MS = 10000; + std::atomic ams_last_fetch_ms{0}; + // Throttling configuration for WebSocket updates // Critical changes (state transitions) dispatch immediately; telemetry is throttled static constexpr uint64_t STATUS_UPDATE_INTERVAL_MS = 1000; // 1 update/sec for telemetry