fix(ElegooLink): pass printer SN to CC2 device panel URL (#13878)

* fix(ElegooLink): pass printer SN to CC2 device panel URL

The CC2 panel subscribes to MQTT topics keyed by the printer serial number.
Without sn= in the URL it uses a wrong hardcoded fallback SN, subscribes to
the wrong topics, and shows Offline permanently even though the printer is
reachable.

- Cache the SN in elegoo_cc2_test() (already fetches it, was discarding it)
- Look up cache in get_print_host_webui(); fall back to a short LAN HTTP
  call on first use before the test has run
- Append sn= to the panel URL
- Clear the wrong hardcoded fallback SN/IP from the panel bundle
- Add a small synchronous boot script to the panel that fetches the SN
  from the printer before the bundle reads URLSearchParams, as a fallback
  for unpatched binaries

* fix(ElegooLink): persist CC2 serial number in AppConfig dev_sn section

Store the printer SN under [dev_sn] keyed by normalized print_host after
a successful connection test or system/info fetch. Reuse it on later
sessions before hitting the network, matching how access_code is keyed by
dev_id for other LAN printers.

* fix(ElegooLink): answer get_sn IPC instantly from dev_sn cache

The CC2 panel always calls get_sn with a 10s timeout. Remove the HTTP
fallback from get_sn() and resolve IPC from dev_sn/memory only so Device
tab load is not blocked after sn= is already in the URL.

* fix(ElegooLink): skip get_sn IPC when URL already has sn

The CC2 device panel calls get_sn with a 10s timeout on every MQTT
connect even when Orca passes sn= in the query string. Use the URL
serial immediately and only fall back to IPC when it is missing.

* refactor(ElegooLink): resolve CC2 SN via PrintHost::get_sn in GUI

Drop the ElegooLink.hpp include from PrinterWebViewHandler; the webview
IPC handler uses the existing PrintHost virtual instead. Keep CC2 serial
lookup helpers file-local in ElegooLink.cpp and share them between
get_sn() and get_print_host_webui().

* chore: drop redundant <memory> include in PrinterWebViewHandler

---------

Co-authored-by: SoftFever <softfeverever@gmail.com>
This commit is contained in:
DeathKhan
2026-05-28 06:45:03 -05:00
committed by GitHub
parent 8d6ba17aac
commit 417bea04df
3 changed files with 130 additions and 57 deletions

View File

@@ -98,8 +98,6 @@ public:
stop_upload = true;
if (upload_thread.joinable())
upload_thread.join();
if (sn_thread.joinable())
sn_thread.join();
}
void on_script_message(wxWebViewEvent &evt) override
@@ -287,35 +285,21 @@ private:
void handle_get_sn_request(const std::string& request_id, const std::string& method)
{
if (sn_request_in_progress.exchange(true)) {
send_ipc_message("response", request_id, method, 1, "SN request already in progress");
return;
// Panel always calls get_sn with a 10s IPC timeout. Answer immediately from
// dev_sn / cache — do not spawn a thread or perform HTTP (panel uses URL sn on miss).
std::string sn;
if (DynamicPrintConfig* config = get_active_printer_config()) {
const std::unique_ptr<PrintHost> host(PrintHost::get_print_host(config));
if (host)
sn = host->get_sn();
}
if (sn_thread.joinable())
sn_thread.join();
sn_thread = std::thread([this, request_id, method]() {
std::string sn;
DynamicPrintConfig* config = get_active_printer_config();
std::unique_ptr<PrintHost> print_host(config == nullptr ? nullptr : PrintHost::get_print_host(config));
if (print_host != nullptr)
sn = print_host->get_sn();
sn_request_in_progress = false;
json data = {
{"sn", sn}
};
send_ipc_message("response", request_id, method, 0, "success", dump_json(data));
});
json data = { { "sn", sn } };
send_ipc_message("response", request_id, method, 0, "success", dump_json(data));
}
std::atomic<bool> upload_in_progress { false };
std::atomic<bool> sn_request_in_progress { false };
std::atomic<bool> stop_upload { false };
std::thread upload_thread;
std::thread sn_thread;
};
} // namespace