Forced SD card / USB drive eject now sends out the event immediately

on Windows as well as on Unix platforms including OSX.
This commit is contained in:
bubnikv 2020-03-09 11:47:20 +01:00
parent e83fb4582c
commit aac691c0e7
2 changed files with 7 additions and 20 deletions

View File

@ -103,7 +103,10 @@ void RemovableDriveManager::eject_drive()
return;
}
CloseHandle(handle);
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);
}
}
@ -476,19 +479,9 @@ 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
#endif // WIN32
{
assert(m_callback_evt_handler);
if (m_callback_evt_handler)
wxPostEvent(m_callback_evt_handler, RemovableDrivesChangedEvent(EVT_REMOVABLE_DRIVES_CHANGED));
}
assert(m_callback_evt_handler);
if (m_callback_evt_handler)
wxPostEvent(m_callback_evt_handler, RemovableDrivesChangedEvent(EVT_REMOVABLE_DRIVES_CHANGED));
}
m_current_drives = std::move(current_drives);
}

View File

@ -101,12 +101,6 @@ private:
// m_current_drives is guarded by m_drives_mutex
// sorted ascending by path
std::vector<DriveData> m_current_drives;
// 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.