mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-08-28 20:37:42 +00:00
Move Moonraker commands off the UI thread
Pause/resume/stop, g-code sends, temps, and light ran synchronous HTTP on the UI thread, freezing the app up to 10s per click on slow or unreachable printers. Run them on a single agent-owned FIFO worker so g-code ordering is preserved, while command translation stays synchronous so unsupported- command dialogs still work. Add a pending-disabled state to the pause, resume, and abort buttons for Moonraker-family printers: the icon only flips once the WebSocket reports the real state, which also rules out double-click races.
This commit is contained in:
@@ -9,6 +9,9 @@
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include <condition_variable>
|
||||
#include <deque>
|
||||
#include <functional>
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
@@ -125,7 +128,11 @@ protected:
|
||||
|
||||
// Send a G-code script via Moonraker (/printer/gcode/script)
|
||||
bool send_gcode(const std::string& dev_id, const std::string& gcode) const;
|
||||
bool send_gcode(const std::string& dev_id, const std::string& gcode,
|
||||
const std::string& base_url, const std::string& api_key) const;
|
||||
bool post_print_action(const std::string& action) const;
|
||||
bool post_print_action(const std::string& action,
|
||||
const std::string& base_url, const std::string& api_key) const;
|
||||
|
||||
private:
|
||||
int handle_request(const std::string& dev_id, const std::string& json_str);
|
||||
@@ -221,7 +228,15 @@ private:
|
||||
// Connection thread management
|
||||
std::atomic<uint64_t> connect_generation{0};
|
||||
std::thread connect_thread;
|
||||
std::recursive_mutex connect_mutex;
|
||||
mutable std::recursive_mutex connect_mutex;
|
||||
|
||||
void enqueue_command(std::function<void()> fn);
|
||||
void run_command_worker();
|
||||
std::thread cmd_thread;
|
||||
std::deque<std::function<void()>> cmd_queue;
|
||||
std::mutex cmd_mutex;
|
||||
std::condition_variable cmd_cv;
|
||||
bool cmd_stop = false;
|
||||
};
|
||||
|
||||
} // namespace Slic3r
|
||||
|
||||
Reference in New Issue
Block a user