mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-07-27 21:02:23 +00:00
Load saved LAN printers when the device manager first gets an agent
When the network plugin is not yet installed at startup, on_init_network builds the DeviceManager without an agent, so its constructor skips loading the persisted LAN printers. After the plugin is installed and the network stack hot-reloads, the manager is reused via set_agent(), which never loaded them - so previously paired printers stayed missing from the device list until an app restart. Load them once a real agent first arrives.
This commit is contained in:
@@ -24,12 +24,23 @@ namespace Slic3r
|
|||||||
|
|
||||||
DevPrinterConfigUtil::InitFilePath(resources_dir());
|
DevPrinterConfigUtil::InitFilePath(resources_dir());
|
||||||
|
|
||||||
// Load saved local machines
|
// Load saved local machines (needs an agent; when built without one the load is
|
||||||
|
// deferred to set_agent()).
|
||||||
if (agent) {
|
if (agent) {
|
||||||
|
load_local_machines_from_config();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeviceManager::load_local_machines_from_config()
|
||||||
|
{
|
||||||
AppConfig* config = GUI::wxGetApp().app_config;
|
AppConfig* config = GUI::wxGetApp().app_config;
|
||||||
const auto local_machines = config->get_local_machines();
|
if (!config)
|
||||||
|
return;
|
||||||
|
const auto& local_machines = config->get_local_machines();
|
||||||
for (auto& it : local_machines) {
|
for (auto& it : local_machines) {
|
||||||
const auto& m = it.second;
|
const auto& m = it.second;
|
||||||
|
if (localMachineList.count(m.dev_id))
|
||||||
|
continue;
|
||||||
MachineObject* obj = new MachineObject(this, m_agent, m.dev_name, m.dev_id, m.dev_ip);
|
MachineObject* obj = new MachineObject(this, m_agent, m.dev_name, m.dev_id, m.dev_ip);
|
||||||
obj->printer_type = m.printer_type;
|
obj->printer_type = m.printer_type;
|
||||||
obj->dev_connection_type = "lan";
|
obj->dev_connection_type = "lan";
|
||||||
@@ -47,7 +58,6 @@ namespace Slic3r
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void DeviceManager::update_local_machine(const MachineObject& m)
|
void DeviceManager::update_local_machine(const MachineObject& m)
|
||||||
{
|
{
|
||||||
@@ -98,6 +108,11 @@ namespace Slic3r
|
|||||||
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ": updating agent for "
|
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ": updating agent for "
|
||||||
<< localMachineList.size() << " local and "
|
<< localMachineList.size() << " local and "
|
||||||
<< userMachineList.size() << " user machines";
|
<< userMachineList.size() << " user machines";
|
||||||
|
|
||||||
|
// First real agent after an agent-less construction (network plugin wasn't ready at
|
||||||
|
// startup): run the persisted-LAN-printer load the constructor had to skip. See
|
||||||
|
// load_local_machines_from_config().
|
||||||
|
const bool first_real_agent = (m_agent == nullptr && agent != nullptr);
|
||||||
m_agent = agent;
|
m_agent = agent;
|
||||||
|
|
||||||
std::lock_guard<std::mutex> lock(listMutex);
|
std::lock_guard<std::mutex> lock(listMutex);
|
||||||
@@ -111,6 +126,10 @@ namespace Slic3r
|
|||||||
it.second->set_agent(agent);
|
it.second->set_agent(agent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (first_real_agent) {
|
||||||
|
load_local_machines_from_config();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeviceManager::EnableMultiMachine(bool enable)
|
void DeviceManager::EnableMultiMachine(bool enable)
|
||||||
|
|||||||
@@ -96,6 +96,13 @@ public:
|
|||||||
std::map<std::string, std::vector<std::string>> device_subseries;
|
std::map<std::string, std::vector<std::string>> device_subseries;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
// Load the LAN printers persisted in AppConfig into localMachineList. Runs from the
|
||||||
|
// constructor when an agent is available and, for the case where the DeviceManager was
|
||||||
|
// first built without one (network plugin not yet installed at startup), from set_agent()
|
||||||
|
// once a real agent finally arrives - so paired printers survive a plugin install/hot
|
||||||
|
// reload without an app restart.
|
||||||
|
void load_local_machines_from_config();
|
||||||
|
|
||||||
void keep_alive();
|
void keep_alive();
|
||||||
void check_pushing();
|
void check_pushing();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user