correct beahvior when disconnecting device other way than button in slicer
This commit is contained in:
parent
507134accb
commit
0db9815467
3 changed files with 37 additions and 10 deletions
|
@ -3600,6 +3600,8 @@ void Plater::priv::on_process_completed(wxCommandEvent &evt)
|
|||
else if(RemovableDriveManager::get_instance().get_is_writing())
|
||||
{
|
||||
RemovableDriveManager::get_instance().set_is_writing(false);
|
||||
//RemovableDriveManager::get_instance().erase_callbacks();
|
||||
//RemovableDriveManager::get_instance().add_callback(std::bind(&Plater::drive_ejected_callback, q));
|
||||
show_action_buttons(false);
|
||||
}
|
||||
}
|
||||
|
@ -4168,8 +4170,7 @@ void Plater::priv::show_action_buttons(const bool is_ready_to_slice) const
|
|||
const auto prin_host_opt = config->option<ConfigOptionString>("print_host");
|
||||
const bool send_gcode_shown = prin_host_opt != nullptr && !prin_host_opt->value.empty();
|
||||
|
||||
const bool disconnect_shown = !(RemovableDriveManager::get_instance().is_last_drive_removed()); // #dk_FIXME
|
||||
|
||||
bool disconnect_shown = !RemovableDriveManager::get_instance().is_last_drive_removed() ; // #dk_FIXME
|
||||
// when a background processing is ON, export_btn and/or send_btn are showing
|
||||
if (wxGetApp().app_config->get("background_processing") == "1")
|
||||
{
|
||||
|
@ -4735,6 +4736,11 @@ void Plater::export_gcode()
|
|||
p->export_gcode(std::move(output_path), PrintHostJob());
|
||||
RemovableDriveManager::get_instance().update(0, true);
|
||||
RemovableDriveManager::get_instance().set_last_save_path(path);
|
||||
if(!RemovableDriveManager::get_instance().is_last_drive_removed())
|
||||
{
|
||||
RemovableDriveManager::get_instance().erase_callbacks();
|
||||
RemovableDriveManager::get_instance().add_callback(std::bind(&Plater::drive_ejected_callback, this));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -5019,15 +5025,18 @@ void Plater::send_gcode()
|
|||
void Plater::eject_drive()
|
||||
{
|
||||
RemovableDriveManager::get_instance().update(0, true);
|
||||
RemovableDriveManager::get_instance().erase_callbacks();
|
||||
RemovableDriveManager::get_instance().add_callback(std::bind(&Plater::drive_ejected_callback, this));
|
||||
//RemovableDriveManager::get_instance().erase_callbacks();
|
||||
//RemovableDriveManager::get_instance().add_callback(std::bind(&Plater::drive_ejected_callback, this));
|
||||
RemovableDriveManager::get_instance().eject_drive(RemovableDriveManager::get_instance().get_last_save_path());
|
||||
|
||||
}
|
||||
void Plater::drive_ejected_callback()
|
||||
{
|
||||
wxString message = "Unmounting succesesful. The device " + RemovableDriveManager::get_instance().get_last_save_name() + "(" + RemovableDriveManager::get_instance().get_last_save_path() + ")" + " can now be safely removed from the computer.";
|
||||
wxMessageBox(message);
|
||||
if (RemovableDriveManager::get_instance().get_did_eject())
|
||||
{
|
||||
wxString message = "Unmounting succesesful. The device " + RemovableDriveManager::get_instance().get_last_save_name() + "(" + RemovableDriveManager::get_instance().get_last_save_path() + ")" + " can now be safely removed from the computer.";
|
||||
wxMessageBox(message);
|
||||
}
|
||||
p->show_action_buttons(false);
|
||||
}
|
||||
|
||||
|
|
|
@ -106,7 +106,7 @@ void RemovableDriveManager::eject_drive(const std::string &path)
|
|||
return;
|
||||
}
|
||||
CloseHandle(handle);
|
||||
|
||||
m_did_eject = true;
|
||||
m_current_drives.erase(it);
|
||||
break;
|
||||
}
|
||||
|
@ -365,6 +365,7 @@ void RemovableDriveManager::eject_drive(const std::string &path)
|
|||
std::cerr<<"Ejecting failed\n";
|
||||
return;
|
||||
}
|
||||
m_did_eject = true;
|
||||
m_current_drives.erase(it);
|
||||
|
||||
break;
|
||||
|
@ -401,12 +402,18 @@ RemovableDriveManager::RemovableDriveManager():
|
|||
m_last_update(0),
|
||||
m_last_save_path(""),
|
||||
m_last_save_name(""),
|
||||
m_is_writing(false)
|
||||
m_is_writing(false),
|
||||
m_did_eject(false)
|
||||
#if __APPLE__
|
||||
, m_rdmmm(new RDMMMWrapper())
|
||||
#endif
|
||||
{}
|
||||
|
||||
RemovableDriveManager::~RemovableDriveManager()
|
||||
{
|
||||
#if __APPLE__
|
||||
delete m_rdmmm;
|
||||
#endif
|
||||
}
|
||||
void RemovableDriveManager::init()
|
||||
{
|
||||
//add_callback([](void) { RemovableDriveManager::get_instance().print(); });
|
||||
|
@ -517,7 +524,7 @@ std::string RemovableDriveManager::get_drive_name(const std::string& path)
|
|||
bool RemovableDriveManager::is_last_drive_removed()
|
||||
{
|
||||
//std::cout<<"is last: "<<m_last_save_path;
|
||||
m_drives_count = m_current_drives.size();
|
||||
//m_drives_count = m_current_drives.size();
|
||||
if(m_last_save_path == "")
|
||||
{
|
||||
//std::cout<<"\n";
|
||||
|
@ -541,9 +548,17 @@ void RemovableDriveManager::reset_last_save_path()
|
|||
void RemovableDriveManager::set_is_writing(const bool b)
|
||||
{
|
||||
m_is_writing = b;
|
||||
if (b)
|
||||
{
|
||||
m_did_eject = false;
|
||||
}
|
||||
}
|
||||
bool RemovableDriveManager::get_is_writing()
|
||||
{
|
||||
return m_is_writing;
|
||||
}
|
||||
bool RemovableDriveManager::get_did_eject()
|
||||
{
|
||||
return m_did_eject;
|
||||
}
|
||||
}}//namespace Slicer::Gui
|
||||
|
|
|
@ -29,6 +29,7 @@ public:
|
|||
}
|
||||
RemovableDriveManager(RemovableDriveManager const&) = delete;
|
||||
void operator=(RemovableDriveManager const&) = delete;
|
||||
~RemovableDriveManager();
|
||||
//call only once. on apple register for unmnount callbacks. on windows register for device notification is prepared but not called (eject usb drive on widnows doesnt trigger the callback, sdc ard does), also enumerates devices for first time so init shoud be called on linux too.
|
||||
void init();
|
||||
//update() searches for removable devices, returns false if empty. /time = 0 is forced update, time expects wxGetLocalTime()
|
||||
|
@ -53,6 +54,7 @@ public:
|
|||
bool is_last_drive_removed_with_update(const long time = 0);
|
||||
void set_is_writing(const bool b);
|
||||
bool get_is_writing();
|
||||
bool get_did_eject();
|
||||
std::string get_drive_name(const std::string& path);
|
||||
private:
|
||||
RemovableDriveManager();
|
||||
|
@ -70,6 +72,7 @@ private:
|
|||
std::string m_last_save_path;
|
||||
std::string m_last_save_name;
|
||||
bool m_is_writing;//on device
|
||||
bool m_did_eject;
|
||||
|
||||
#if _WIN32
|
||||
//registers for notifications by creating invisible window
|
||||
|
|
Loading…
Reference in a new issue