Class: Ukey::UsbWatcher
- Inherits:
-
Object
- Object
- Ukey::UsbWatcher
- Defined in:
- lib/ukey/usb_watcher.rb
Overview
Watches usb devices and locks screen if removed
Instance Method Summary collapse
-
#initialize(device_name: '', interval: 5) ⇒ UsbWatcher
constructor
A new instance of UsbWatcher.
- #list_devices ⇒ Object
- #watch ⇒ Object
Constructor Details
#initialize(device_name: '', interval: 5) ⇒ UsbWatcher
Returns a new instance of UsbWatcher.
8 9 10 11 12 |
# File 'lib/ukey/usb_watcher.rb', line 8 def initialize(device_name: '', interval: 5) @device_name = device_name @interval = interval @usb = LIBUSB::Context.new end |
Instance Method Details
#list_devices ⇒ Object
27 28 29 |
# File 'lib/ukey/usb_watcher.rb', line 27 def list_devices usb.devices.map(&:product) end |
#watch ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/ukey/usb_watcher.rb', line 14 def watch loop do if screen_locked? sleep(interval * 2) else lock_screen if device_removed? sleep(interval) end end rescue SystemExit, Interrupt, KeyboardInterrupt puts "\nWatcher terminated." end |