Sha256: 1cbfc22faf109f83d5aa71b2a458752725e5e185632eb77c12869842ab07b0ec

Contents?: true

Size: 1.53 KB

Versions: 3

Compression:

Stored size: 1.53 KB

Contents

# frozen_string_literal: true

require_relative '../sendkey/keyboard.rb'

module Fusuma
  module Plugin
    module Executors
      # Control Window or Workspaces by executing wctrl
      class SendkeyExecutor < Executor
        def config_param_types
          {
            'device_path': String
          }
        end

        # execute sendkey command
        # @param event [Event]
        # @return [nil]
        def execute(event)
          return if search_command(event).nil?

          MultiLogger.info(sendkey: search_param(event))
          pid = fork do
            Process.daemon(true)
            exec(search_command(event))
          end

          Process.detach(pid)
        end

        # check executable
        # @param event [Event]
        # @return [TrueClass, FalseClass]
        def executable?(event)
          event.tag.end_with?('_detector') &&
            event.record.type == :index &&
            search_command(event)
        end

        # @param event [Event]
        # @return [String]
        # @return [NilClass]
        def search_command(event)
          @keyboard ||= begin
                          device = Sendkey::Device.new(path: config_params(:device_path))
                          Sendkey::Keyboard.new(device: device)
                        end
          @keyboard.type_command(param: search_param(event))
        end

        private

        def search_param(event)
          index = Config::Index.new([*event.record.index.keys, :sendkey])
          Config.search(index)
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
fusuma-plugin-sendkey-0.2.1 lib/fusuma/plugin/executors/sendkey_executor.rb
fusuma-plugin-sendkey-0.2.0 lib/fusuma/plugin/executors/sendkey_executor.rb
fusuma-plugin-sendkey-0.1.1 lib/fusuma/plugin/executors/sendkey_executor.rb