mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-09-10 10:47:16 +00:00
Do not connect to default BBL device during app startup (#10214)
* Do not connect to default device during app startup * Connect to last selected machine automatically even if it's lan machine Simplify default machine connection logic * Select last machine automatically when available * Check for LAN connection state after updating combobox selection. This matches the logic of `SendPrint.cpp`. * Avoid showing same error message multiple times until next connection attempt. --------- Co-authored-by: SoftFever <softfeverever@gmail.com>
This commit is contained in:
@@ -6750,28 +6750,19 @@ std::map<std::string ,MachineObject*> DeviceManager::get_local_machine_list()
|
|||||||
|
|
||||||
void DeviceManager::load_last_machine()
|
void DeviceManager::load_last_machine()
|
||||||
{
|
{
|
||||||
if (userMachineList.empty()) {
|
// Get all available machines, include cloud machines and lan machines that have access right
|
||||||
// Orca: connect LAN printers instead
|
auto all_machines = get_my_machine_list();
|
||||||
const auto local_machine = std::find_if(localMachineList.begin(), localMachineList.end(), [](const std::pair<std::string, MachineObject*>& it) -> bool { return it.second->has_access_right();});
|
if (all_machines.empty())
|
||||||
if (local_machine != localMachineList.end()) {
|
return;
|
||||||
this->set_selected_machine(local_machine->second->dev_id);
|
|
||||||
}
|
// Then connect to the machine we last selected if available
|
||||||
}
|
const std::string last_monitor_machine = m_agent ? m_agent->get_user_selected_machine() : "";
|
||||||
else if (userMachineList.size() == 1) {
|
const auto last_machine = all_machines.find(last_monitor_machine);
|
||||||
this->set_selected_machine(userMachineList.begin()->second->dev_id);
|
if (last_machine != all_machines.end()) {
|
||||||
|
this->set_selected_machine(last_machine->second->dev_id);
|
||||||
} else {
|
} else {
|
||||||
if (m_agent) {
|
// If not, then select the first available one
|
||||||
std::string last_monitor_machine = m_agent->get_user_selected_machine();
|
this->set_selected_machine(all_machines.begin()->second->dev_id);
|
||||||
bool found = false;
|
|
||||||
for (auto it = userMachineList.begin(); it != userMachineList.end(); it++) {
|
|
||||||
if (last_monitor_machine == it->first) {
|
|
||||||
this->set_selected_machine(last_monitor_machine);
|
|
||||||
found = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!found)
|
|
||||||
this->set_selected_machine(userMachineList.begin()->second->dev_id);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1728,16 +1728,20 @@ void GUI_App::init_networking_callbacks()
|
|||||||
event.SetString(obj->dev_id);
|
event.SetString(obj->dev_id);
|
||||||
GUI::wxGetApp().sidebar().load_ams_list(obj->dev_id, obj);
|
GUI::wxGetApp().sidebar().load_ams_list(obj->dev_id, obj);
|
||||||
} else if (state == ConnectStatus::ConnectStatusFailed) {
|
} else if (state == ConnectStatus::ConnectStatusFailed) {
|
||||||
|
// Orca: avoid showing same error message multiple times until next connection attempt.
|
||||||
|
const auto already_disconnected = m_device_manager->selected_machine.empty();
|
||||||
m_device_manager->set_selected_machine("", true);
|
m_device_manager->set_selected_machine("", true);
|
||||||
wxString text;
|
if (!already_disconnected) {
|
||||||
if (msg == "5") {
|
wxString text;
|
||||||
obj->set_access_code("");
|
if (msg == "5") {
|
||||||
obj->erase_user_access_code();
|
obj->set_access_code("");
|
||||||
text = wxString::Format(_L("Incorrect password"));
|
obj->erase_user_access_code();
|
||||||
wxGetApp().show_dialog(text);
|
text = wxString::Format(_L("Incorrect password"));
|
||||||
} else {
|
wxGetApp().show_dialog(text);
|
||||||
text = wxString::Format(_L("Connect %s failed! [SN:%s, code=%s]"), from_u8(obj->dev_name), obj->dev_id, msg);
|
} else {
|
||||||
wxGetApp().show_dialog(text);
|
text = wxString::Format(_L("Connect %s failed! [SN:%s, code=%s]"), from_u8(obj->dev_name), obj->dev_id, msg);
|
||||||
|
wxGetApp().show_dialog(text);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
event.SetInt(-1);
|
event.SetInt(-1);
|
||||||
} else if (state == ConnectStatus::ConnectStatusLost) {
|
} else if (state == ConnectStatus::ConnectStatusLost) {
|
||||||
@@ -4196,6 +4200,10 @@ void GUI_App::enable_user_preset_folder(bool enable)
|
|||||||
|
|
||||||
void GUI_App::on_set_selected_machine(wxCommandEvent &evt)
|
void GUI_App::on_set_selected_machine(wxCommandEvent &evt)
|
||||||
{
|
{
|
||||||
|
// Orca: do not connect to default device during app startup, because some of the lan machines might not online yet
|
||||||
|
// and user will be prompted by several "Connect XXX failed" error message.
|
||||||
|
return;
|
||||||
|
|
||||||
DeviceManager* dev = Slic3r::GUI::wxGetApp().getDeviceManager();
|
DeviceManager* dev = Slic3r::GUI::wxGetApp().getDeviceManager();
|
||||||
if (dev) {
|
if (dev) {
|
||||||
dev->set_selected_machine(m_agent->get_user_selected_machine());
|
dev->set_selected_machine(m_agent->get_user_selected_machine());
|
||||||
|
|||||||
@@ -2373,6 +2373,10 @@ void SelectMachineDialog::update_user_printer()
|
|||||||
m_comboBox_printer->Set(machine_list_name);
|
m_comboBox_printer->Set(machine_list_name);
|
||||||
|
|
||||||
MachineObject* obj = dev->get_selected_machine();
|
MachineObject* obj = dev->get_selected_machine();
|
||||||
|
if (!obj) {
|
||||||
|
dev->load_last_machine();
|
||||||
|
obj = dev->get_selected_machine();
|
||||||
|
}
|
||||||
|
|
||||||
if (obj) {
|
if (obj) {
|
||||||
if (obj->is_lan_mode_printer() && !obj->has_access_right()) {
|
if (obj->is_lan_mode_printer() && !obj->has_access_right()) {
|
||||||
@@ -2410,13 +2414,10 @@ void SelectMachineDialog::update_user_printer()
|
|||||||
|
|
||||||
for (auto i = 0; i < m_list.size(); i++) {
|
for (auto i = 0; i < m_list.size(); i++) {
|
||||||
if (m_list[i]->dev_id == m_printer_last_select) {
|
if (m_list[i]->dev_id == m_printer_last_select) {
|
||||||
|
m_comboBox_printer->SetSelection(i);
|
||||||
if (obj && !obj->get_lan_mode_connection_state()) {
|
wxCommandEvent event(wxEVT_COMBOBOX);
|
||||||
m_comboBox_printer->SetSelection(i);
|
event.SetEventObject(m_comboBox_printer);
|
||||||
wxCommandEvent event(wxEVT_COMBOBOX);
|
wxPostEvent(m_comboBox_printer, event);
|
||||||
event.SetEventObject(m_comboBox_printer);
|
|
||||||
wxPostEvent(m_comboBox_printer, event);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2594,7 +2595,7 @@ void SelectMachineDialog::on_selection_changed(wxCommandEvent &event)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (obj) {
|
if (obj && !obj->get_lan_mode_connection_state()) {
|
||||||
obj->command_get_version();
|
obj->command_get_version();
|
||||||
obj->command_request_push_all();
|
obj->command_request_push_all();
|
||||||
if (!dev->get_selected_machine()) {
|
if (!dev->get_selected_machine()) {
|
||||||
|
|||||||
@@ -917,6 +917,11 @@ void SendToPrinterDialog::update_user_printer()
|
|||||||
m_comboBox_printer->Set(machine_list_name);
|
m_comboBox_printer->Set(machine_list_name);
|
||||||
|
|
||||||
MachineObject* obj = dev->get_selected_machine();
|
MachineObject* obj = dev->get_selected_machine();
|
||||||
|
if (!obj) {
|
||||||
|
dev->load_last_machine();
|
||||||
|
obj = dev->get_selected_machine();
|
||||||
|
}
|
||||||
|
|
||||||
if (obj) {
|
if (obj) {
|
||||||
m_printer_last_select = obj->dev_id;
|
m_printer_last_select = obj->dev_id;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user