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:
Noisyfox
2025-07-26 00:18:56 +08:00
committed by GitHub
parent 68110eeecc
commit 85e66de431
4 changed files with 43 additions and 38 deletions

View File

@@ -6750,28 +6750,19 @@ std::map<std::string ,MachineObject*> DeviceManager::get_local_machine_list()
void DeviceManager::load_last_machine()
{
if (userMachineList.empty()) {
// Orca: connect LAN printers instead
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 (local_machine != localMachineList.end()) {
this->set_selected_machine(local_machine->second->dev_id);
}
}
else if (userMachineList.size() == 1) {
this->set_selected_machine(userMachineList.begin()->second->dev_id);
// Get all available machines, include cloud machines and lan machines that have access right
auto all_machines = get_my_machine_list();
if (all_machines.empty())
return;
// Then connect to the machine we last selected if available
const std::string last_monitor_machine = m_agent ? m_agent->get_user_selected_machine() : "";
const auto last_machine = all_machines.find(last_monitor_machine);
if (last_machine != all_machines.end()) {
this->set_selected_machine(last_machine->second->dev_id);
} else {
if (m_agent) {
std::string last_monitor_machine = m_agent->get_user_selected_machine();
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);
}
// If not, then select the first available one
this->set_selected_machine(all_machines.begin()->second->dev_id);
}
}

View File

@@ -1728,7 +1728,10 @@ void GUI_App::init_networking_callbacks()
event.SetString(obj->dev_id);
GUI::wxGetApp().sidebar().load_ams_list(obj->dev_id, obj);
} 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);
if (!already_disconnected) {
wxString text;
if (msg == "5") {
obj->set_access_code("");
@@ -1739,6 +1742,7 @@ void GUI_App::init_networking_callbacks()
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);
} else if (state == ConnectStatus::ConnectStatusLost) {
m_device_manager->set_selected_machine("", true);
@@ -4196,6 +4200,10 @@ void GUI_App::enable_user_preset_folder(bool enable)
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();
if (dev) {
dev->set_selected_machine(m_agent->get_user_selected_machine());

View File

@@ -2373,6 +2373,10 @@ void SelectMachineDialog::update_user_printer()
m_comboBox_printer->Set(machine_list_name);
MachineObject* obj = dev->get_selected_machine();
if (!obj) {
dev->load_last_machine();
obj = dev->get_selected_machine();
}
if (obj) {
if (obj->is_lan_mode_printer() && !obj->has_access_right()) {
@@ -2410,8 +2414,6 @@ void SelectMachineDialog::update_user_printer()
for (auto i = 0; i < m_list.size(); i++) {
if (m_list[i]->dev_id == m_printer_last_select) {
if (obj && !obj->get_lan_mode_connection_state()) {
m_comboBox_printer->SetSelection(i);
wxCommandEvent event(wxEVT_COMBOBOX);
event.SetEventObject(m_comboBox_printer);
@@ -2419,7 +2421,6 @@ void SelectMachineDialog::update_user_printer()
}
}
}
}
else {
m_printer_last_select = "";
update_select_layout(nullptr);
@@ -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_request_push_all();
if (!dev->get_selected_machine()) {

View File

@@ -917,6 +917,11 @@ void SendToPrinterDialog::update_user_printer()
m_comboBox_printer->Set(machine_list_name);
MachineObject* obj = dev->get_selected_machine();
if (!obj) {
dev->load_last_machine();
obj = dev->get_selected_machine();
}
if (obj) {
m_printer_last_select = obj->dev_id;
} else {