Skip to content

Commit

Permalink
fix: handle device removed error
Browse files Browse the repository at this point in the history
- When a virtual device or physical device is removed, an error occurs,
  so catch the error and exit the process
  • Loading branch information
iberianpig committed Oct 13, 2023
1 parent cdfeecc commit 9e8b48a
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions lib/fusuma/plugin/remap/remapper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,7 @@ def run
io = ios.first.first

if io == @layer_manager.reader
begin
@layer_manager.receive_layer
rescue EOFError
@destroy.call
end
@layer_manager.receive_layer

MultiLogger.debug "Remapper#run: layer changed to #{@layer_manager.current_layer}"
next_mapping = @layer_manager.find_mapping
Expand Down Expand Up @@ -93,6 +89,12 @@ def run

uinput.write_input_event(remapped_event)
end
rescue Errno::ENODEV => e # device is removed
MultiLogger.error e.message
rescue EOFError => e # device is closed
MultiLogger.error e.message
ensure
@destroy.call
end

private
Expand Down Expand Up @@ -162,6 +164,7 @@ def set_trap
kbd.ungrab
MultiLogger.info "Ungrabbed #{kbd.device_name}"
rescue Errno::EINVAL
rescue Errno::ENODEV
# already ungrabbed
end

Expand Down

0 comments on commit 9e8b48a

Please sign in to comment.