mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Windows device detection: Don't do expensive polling while waiting for device disconnect
This commit is contained in:
parent
8092fd185a
commit
3240c330c1
@ -60,7 +60,8 @@ class DevicePlugin(Plugin):
|
|||||||
import traceback
|
import traceback
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
|
|
||||||
def is_usb_connected_windows(self, devices_on_system, debug=False):
|
def is_usb_connected_windows(self, devices_on_system, debug=False,
|
||||||
|
only_presence=False):
|
||||||
|
|
||||||
def id_iterator():
|
def id_iterator():
|
||||||
if hasattr(self.VENDOR_ID, 'keys'):
|
if hasattr(self.VENDOR_ID, 'keys'):
|
||||||
@ -85,7 +86,7 @@ class DevicePlugin(Plugin):
|
|||||||
self.test_bcd_windows(device_id, bcd):
|
self.test_bcd_windows(device_id, bcd):
|
||||||
if debug:
|
if debug:
|
||||||
self.print_usb_device_info(device_id)
|
self.print_usb_device_info(device_id)
|
||||||
if self.can_handle_windows(device_id, debug=debug):
|
if only_presence or self.can_handle_windows(device_id, debug=debug):
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@ -97,7 +98,8 @@ class DevicePlugin(Plugin):
|
|||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def is_usb_connected(self, devices_on_system, debug=False):
|
def is_usb_connected(self, devices_on_system, debug=False,
|
||||||
|
only_presence=False):
|
||||||
'''
|
'''
|
||||||
Return True, device_info if a device handled by this plugin is currently connected.
|
Return True, device_info if a device handled by this plugin is currently connected.
|
||||||
|
|
||||||
@ -105,7 +107,7 @@ class DevicePlugin(Plugin):
|
|||||||
'''
|
'''
|
||||||
if iswindows:
|
if iswindows:
|
||||||
return self.is_usb_connected_windows(devices_on_system,
|
return self.is_usb_connected_windows(devices_on_system,
|
||||||
debug=debug), None
|
debug=debug, only_presence=only_presence), None
|
||||||
|
|
||||||
vendors_on_system = set([x[0] for x in devices_on_system])
|
vendors_on_system = set([x[0] for x in devices_on_system])
|
||||||
vendors = self.VENDOR_ID if hasattr(self.VENDOR_ID, '__len__') else [self.VENDOR_ID]
|
vendors = self.VENDOR_ID if hasattr(self.VENDOR_ID, '__len__') else [self.VENDOR_ID]
|
||||||
|
@ -139,8 +139,11 @@ class DeviceScanner(object):
|
|||||||
'''Fetch list of connected USB devices from operating system'''
|
'''Fetch list of connected USB devices from operating system'''
|
||||||
self.devices = self.scanner()
|
self.devices = self.scanner()
|
||||||
|
|
||||||
def is_device_connected(self, device, debug=False):
|
def is_device_connected(self, device, debug=False, only_presence=False):
|
||||||
return device.is_usb_connected(self.devices, debug=debug)
|
''' If only_presence is True don't perform any expensive checks (used
|
||||||
|
only in windows)'''
|
||||||
|
return device.is_usb_connected(self.devices, debug=debug,
|
||||||
|
only_presence=only_presence)
|
||||||
|
|
||||||
|
|
||||||
def main(args=sys.argv):
|
def main(args=sys.argv):
|
||||||
|
@ -134,7 +134,8 @@ class DeviceManager(Thread):
|
|||||||
self.scanner.scan()
|
self.scanner.scan()
|
||||||
if self.is_device_connected:
|
if self.is_device_connected:
|
||||||
connected, detected_device = \
|
connected, detected_device = \
|
||||||
self.scanner.is_device_connected(self.connected_device)
|
self.scanner.is_device_connected(self.connected_device,
|
||||||
|
only_presence=True)
|
||||||
if not connected:
|
if not connected:
|
||||||
self.connected_device_removed()
|
self.connected_device_removed()
|
||||||
else:
|
else:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user