Windows do not send an update on insert / eject of an SD card into

an external SD card reader. Windows also do not send an update
on software eject of a FLASH drive. We can likely use the Windows
WMI API, but it will be quite time consuming to implement,
therefore we lower the polling interval back to two seconds.

https://www.codeproject.com/Articles/10539/Making-WMI-Queries-In-C
https://docs.microsoft.com/en-us/windows/win32/wmisdk/wmi-start-page
https://docs.microsoft.com/en-us/windows/win32/wmisdk/com-api-for-wmi
https://docs.microsoft.com/en-us/windows/win32/wmisdk/example--receiving-event-notifications-through-wmi-
This commit is contained in:
bubnikv 2020-03-13 19:30:41 +01:00
parent d3236f5e70
commit 3234823a1a

View file

@ -450,9 +450,14 @@ void RemovableDriveManager::thread_proc()
{
std::unique_lock<std::mutex> lck(m_thread_stop_mutex);
#ifdef _WIN32
// Wait 30 seconds for the stop signal, wake up time to time to remove those devices that the user ejected in file explorer
// or another application (for example in Cura). This is a workaround, as Windows does not send an event on software eject of a drive.
m_thread_stop_condition.wait_for(lck, std::chrono::seconds(30), [this]{ return m_stop || m_wakeup; });
// Windows do not send an update on insert / eject of an SD card into an external SD card reader.
// Windows also do not send an update on software eject of a FLASH drive.
// We can likely use the Windows WMI API, but it will be quite time consuming to implement.
// https://www.codeproject.com/Articles/10539/Making-WMI-Queries-In-C
// https://docs.microsoft.com/en-us/windows/win32/wmisdk/wmi-start-page
// https://docs.microsoft.com/en-us/windows/win32/wmisdk/com-api-for-wmi
// https://docs.microsoft.com/en-us/windows/win32/wmisdk/example--receiving-event-notifications-through-wmi-
m_thread_stop_condition.wait_for(lck, std::chrono::seconds(2), [this]{ return m_stop || m_wakeup; });
#else
m_thread_stop_condition.wait_for(lck, std::chrono::seconds(2), [this]{ return m_stop; });
#endif