diff --git a/src/slic3r/GUI/RemovableDriveManager.cpp b/src/slic3r/GUI/RemovableDriveManager.cpp index 2264cc954e..5054d061e1 100644 --- a/src/slic3r/GUI/RemovableDriveManager.cpp +++ b/src/slic3r/GUI/RemovableDriveManager.cpp @@ -348,7 +348,10 @@ void RemovableDriveManager::eject_drive() return; } - m_drive_data_last_eject = *it_drive_data; + assert(m_callback_evt_handler); + if (m_callback_evt_handler) + wxPostEvent(m_callback_evt_handler, RemovableDriveEjectEvent(EVT_REMOVABLE_DRIVE_EJECTED, std::move(*it_drive_data))); + m_current_drives.erase(it_drive_data); } } @@ -473,12 +476,15 @@ void RemovableDriveManager::update() tbb::mutex::scoped_lock lock(m_drives_mutex); std::sort(current_drives.begin(), current_drives.end()); if (current_drives != m_current_drives) { +#ifdef WIN32 if (! m_drive_data_last_eject.empty() && std::find(current_drives.begin(), current_drives.end(), m_drive_data_last_eject) == current_drives.end()) { assert(m_callback_evt_handler); if (m_callback_evt_handler) wxPostEvent(m_callback_evt_handler, RemovableDriveEjectEvent(EVT_REMOVABLE_DRIVE_EJECTED, std::move(m_drive_data_last_eject))); m_drive_data_last_eject.clear(); - } else { + } else +#endif // WIN32 + { assert(m_callback_evt_handler); if (m_callback_evt_handler) wxPostEvent(m_callback_evt_handler, RemovableDrivesChangedEvent(EVT_REMOVABLE_DRIVES_CHANGED)); diff --git a/src/slic3r/GUI/RemovableDriveManager.hpp b/src/slic3r/GUI/RemovableDriveManager.hpp index 3b808d9d79..7ada13e5a7 100644 --- a/src/slic3r/GUI/RemovableDriveManager.hpp +++ b/src/slic3r/GUI/RemovableDriveManager.hpp @@ -65,6 +65,8 @@ public: // Verify whether the path provided is on removable media. If so, save the path for further eject and return true, otherwise return false. bool set_and_verify_last_save_path(const std::string &path); // Eject drive of a file set by set_and_verify_last_save_path(). + // On Unix / OSX, the function blocks and sends out the EVT_REMOVABLE_DRIVE_EJECTED event on success. + // On Windows, the function does not block, and the eject is detected in the background thread. void eject_drive(); struct RemovableDrivesStatus { @@ -102,7 +104,9 @@ private: // When user requested an eject, the drive to be forcefuly ejected is stored here, so the next update will // recognize that the eject was finished with success and an eject event is sent out. // guarded with m_drives_mutex +#ifdef WIN32 DriveData m_drive_data_last_eject; +#endif // WIN32 mutable tbb::mutex m_drives_mutex; // Returns drive path (same as path in DriveData) if exists otherwise empty string.