procon_bypass_man 0.1.11 → 0.1.15

Sign up to get free protection for your applications and to get access to all the features.
Files changed (94) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/release.yml +33 -0
  3. data/.gitignore +1 -0
  4. data/CHANGELOG.md +13 -0
  5. data/Gemfile +1 -1
  6. data/Gemfile.lock +14 -12
  7. data/README.md +11 -7
  8. data/bin/dev_api_server.rb +1 -1
  9. data/lib/procon_bypass_man/background/job_performer.rb +16 -0
  10. data/lib/procon_bypass_man/background/{report_thread.rb → job_runner.rb} +13 -10
  11. data/lib/procon_bypass_man/background/jobs/base_job.rb +7 -0
  12. data/lib/procon_bypass_man/background/jobs/concerns/has_external_api_setting.rb +5 -0
  13. data/lib/procon_bypass_man/background/jobs/concerns/has_internal_api_setting.rb +5 -0
  14. data/lib/procon_bypass_man/background/jobs/concerns/job_runnable.rb +16 -0
  15. data/lib/procon_bypass_man/background/jobs/fetch_and_run_remote_pbm_action_job.rb +29 -0
  16. data/lib/procon_bypass_man/background/jobs/report_boot_job.rb +12 -0
  17. data/lib/procon_bypass_man/background/jobs/report_error_job.rb +11 -0
  18. data/lib/procon_bypass_man/background/jobs/report_event_base_job.rb +5 -0
  19. data/lib/procon_bypass_man/background/jobs/report_load_config_job.rb +11 -0
  20. data/lib/procon_bypass_man/background/jobs/report_pressed_buttons_job.rb +15 -0
  21. data/lib/procon_bypass_man/background/jobs/report_reload_config_job.rb +11 -0
  22. data/lib/procon_bypass_man/background/jobs/sync_device_stats_job.rb +16 -0
  23. data/lib/procon_bypass_man/background.rb +14 -0
  24. data/lib/procon_bypass_man/boot_message.rb +16 -8
  25. data/lib/procon_bypass_man/{configuration → buttons_setting_configuration}/layer.rb +34 -29
  26. data/lib/procon_bypass_man/{configuration → buttons_setting_configuration}/loader.rb +5 -4
  27. data/lib/procon_bypass_man/{configuration → buttons_setting_configuration}/validator.rb +0 -0
  28. data/lib/procon_bypass_man/buttons_setting_configuration.rb +6 -7
  29. data/lib/procon_bypass_man/bypass/usb_hid_logger.rb +18 -7
  30. data/lib/procon_bypass_man/bypass.rb +15 -14
  31. data/lib/procon_bypass_man/commands/bypass_command.rb +86 -0
  32. data/lib/procon_bypass_man/commands/connect_device_command.rb +16 -0
  33. data/lib/procon_bypass_man/commands/print_boot_message_command.rb +9 -0
  34. data/lib/procon_bypass_man/commands/run_local_shell_command.rb +6 -0
  35. data/lib/procon_bypass_man/commands/run_remote_pbm_action_dispatch_command.rb +21 -0
  36. data/lib/procon_bypass_man/commands/send_error_command.rb +19 -0
  37. data/lib/procon_bypass_man/commands/send_reload_config_event_command.rb +11 -0
  38. data/lib/procon_bypass_man/commands/write_device_id_command.rb +12 -0
  39. data/lib/procon_bypass_man/commands/write_session_id_command.rb +7 -0
  40. data/lib/procon_bypass_man/commands.rb +8 -0
  41. data/lib/procon_bypass_man/configuration.rb +47 -6
  42. data/lib/procon_bypass_man/device_connector.rb +33 -26
  43. data/lib/procon_bypass_man/device_status.rb +44 -0
  44. data/lib/procon_bypass_man/io_monitor.rb +9 -4
  45. data/lib/procon_bypass_man/plugin/splatoon2/macro/fast_return.rb +17 -0
  46. data/lib/procon_bypass_man/plugin/splatoon2/macro/jump_to_left_key.rb +17 -0
  47. data/lib/procon_bypass_man/plugin/splatoon2/macro/jump_to_right_key.rb +17 -0
  48. data/lib/procon_bypass_man/plugin/splatoon2/macro/jump_to_up_key.rb +17 -0
  49. data/lib/procon_bypass_man/plugin/splatoon2/mode/guruguru.rb +59 -0
  50. data/lib/procon_bypass_man/plugin/splatoon2/version.rb +9 -0
  51. data/lib/procon_bypass_man/plugin.rb +11 -0
  52. data/lib/procon_bypass_man/procon/analog_stick_cap.rb +1 -1
  53. data/lib/procon_bypass_man/procon/{data.rb → consts.rb} +1 -1
  54. data/lib/procon_bypass_man/procon/layer_changer.rb +40 -0
  55. data/lib/procon_bypass_man/procon/user_operation.rb +11 -17
  56. data/lib/procon_bypass_man/procon.rb +6 -12
  57. data/lib/procon_bypass_man/{readonly_procon.rb → procon_reader.rb} +3 -4
  58. data/lib/procon_bypass_man/remote_pbm_action/base_action.rb +53 -0
  59. data/lib/procon_bypass_man/remote_pbm_action/change_pbm_version_action.rb +25 -0
  60. data/lib/procon_bypass_man/remote_pbm_action/lib/update_remote_pbm_action_status_command.rb +24 -0
  61. data/lib/procon_bypass_man/remote_pbm_action/reboot_os_action.rb +21 -0
  62. data/lib/procon_bypass_man/remote_pbm_action/restore_pbm_setting.rb +28 -0
  63. data/lib/procon_bypass_man/remote_pbm_action/stop_pbm_action.rb +21 -0
  64. data/lib/procon_bypass_man/remote_pbm_action.rb +32 -0
  65. data/lib/procon_bypass_man/runner.rb +14 -115
  66. data/lib/procon_bypass_man/scheduler.rb +92 -0
  67. data/lib/procon_bypass_man/{callbacks.rb → support/callbacks.rb} +0 -0
  68. data/lib/procon_bypass_man/support/compress_array.rb +56 -0
  69. data/lib/procon_bypass_man/support/http_client.rb +102 -0
  70. data/lib/procon_bypass_man/{on_memory_cache.rb → support/on_memory_cache.rb} +0 -0
  71. data/lib/procon_bypass_man/support/report_http_client.rb +19 -0
  72. data/lib/procon_bypass_man/{timer.rb → support/safe_timeout.rb} +1 -1
  73. data/lib/procon_bypass_man/support/send_device_stats_http_client.rb +9 -0
  74. data/lib/procon_bypass_man/support/server_pool.rb +42 -0
  75. data/lib/procon_bypass_man/support/signal_handler.rb +11 -0
  76. data/lib/procon_bypass_man/support/update_remote_pbm_action_status_http_client.rb +9 -0
  77. data/lib/procon_bypass_man/support/uptime.rb +25 -0
  78. data/lib/procon_bypass_man/value_objects/remote_pbm_action_object.rb +38 -0
  79. data/lib/procon_bypass_man/version.rb +1 -1
  80. data/lib/procon_bypass_man.rb +71 -36
  81. data/procon_bypass_man.gemspec +3 -3
  82. data/project_template/README.md +18 -11
  83. data/project_template/app.rb +2 -3
  84. data/project_template/setting.yml +8 -8
  85. data/sig/{README.rb → README.md} +0 -0
  86. data/sig/main.rbs +10 -11
  87. metadata +85 -26
  88. data/lib/procon_bypass_man/outbound/base.rb +0 -53
  89. data/lib/procon_bypass_man/outbound/error_reporter.rb +0 -13
  90. data/lib/procon_bypass_man/outbound/pressed_buttons_reporter.rb +0 -13
  91. data/lib/procon_bypass_man/outbound/reporter.rb +0 -12
  92. data/lib/procon_bypass_man/procon/layer_changeable.rb +0 -28
  93. data/lib/procon_bypass_man/procon/pressed_button_helper.rb +0 -15
  94. data/lib/procon_bypass_man/uptime.rb +0 -15
@@ -1,53 +0,0 @@
1
- module ProconBypassMan
2
- module Outbound
3
- class Base
4
- class Client
5
- class Result < Struct.new(:stats); end
6
-
7
- def initialize(path: , server: )
8
- @path = path
9
- if server.is_a?(Array)
10
- # TODO エラーが起きたらローテーションする
11
- @server = server.first
12
- else
13
- @server = server
14
- end
15
- @hostname = `hostname`.chomp
16
- end
17
-
18
- def post(body: )
19
- # TODO ここでvalidationする
20
- if @server.nil?
21
- ProconBypassMan.logger.info('送信先が未設定なのでスキップしました')
22
- return Result.new(false)
23
- end
24
-
25
- unless body.is_a?(Hash)
26
- body = { value: body }
27
- end
28
-
29
- uri = URI.parse("#{@server}#{@path}")
30
- http = Net::HTTP.new(uri.host, uri.port)
31
- http.use_ssl = uri.scheme === "https"
32
- params = { hostname: @hostname }.merge(body)
33
- response = http.post(
34
- uri.path,
35
- params.to_json,
36
- { "Content-Type" => "application/json" },
37
- )
38
- case response.code
39
- when /^200/
40
- return Result.new(true)
41
- else
42
- ProconBypassMan.logger.error("200以外(#{response.code})が帰ってきました. #{response.body}")
43
- return Result.new(false)
44
- end
45
- rescue => e
46
- puts e
47
- ProconBypassMan.logger.error("erro: #{e}")
48
- Result.new(false)
49
- end
50
- end
51
- end
52
- end
53
- end
@@ -1,13 +0,0 @@
1
- require "procon_bypass_man/outbound/base"
2
-
3
- class ProconBypassMan::ErrorReporter < ProconBypassMan::Outbound::Base
4
- PATH = "/api/error_reports"
5
-
6
- def self.report(body: )
7
- Client.new(
8
- path: PATH,
9
- server: ProconBypassMan.config.api_server,
10
- ).post(body: body.full_message)
11
- end
12
- end
13
-
@@ -1,13 +0,0 @@
1
- require "procon_bypass_man/outbound/base"
2
-
3
- class ProconBypassMan::PressedButtonsReporter < ProconBypassMan::Outbound::Base
4
- PATH = "/api/pressed_buttons"
5
-
6
- def self.report(body: )
7
- Client.new(
8
- path: PATH,
9
- server: ProconBypassMan.config.internal_api_servers,
10
- ).post(body: body)
11
- end
12
- end
13
-
@@ -1,12 +0,0 @@
1
- require "procon_bypass_man/outbound/base"
2
-
3
- class ProconBypassMan::Reporter < ProconBypassMan::Outbound::Base
4
- PATH = "/api/reports"
5
-
6
- def self.report(body: )
7
- Client.new(
8
- path: PATH,
9
- server: ProconBypassMan.config.api_server,
10
- ).post(body: body)
11
- end
12
- end
@@ -1,28 +0,0 @@
1
- module ProconBypassMan::Procon::LayerChangeable
2
- def next_layer_key
3
- case
4
- when pressed_up?
5
- :up
6
- when pressed_right?
7
- :right
8
- when pressed_left?
9
- :left
10
- when pressed_down?
11
- :down
12
- else
13
- ProconBypassMan.logger.warn("next_layer_key is unknown")
14
- :up
15
- end
16
- end
17
-
18
- def change_layer?
19
- if ProconBypassMan::ButtonsSettingConfiguration.instance.prefix_keys.empty?
20
- raise "prefix_keysが未設定です"
21
- end
22
- ProconBypassMan::ButtonsSettingConfiguration.instance.prefix_keys.map { |b| pressed_button?(b) }.all?
23
- end
24
-
25
- def pressed_next_layer?
26
- change_layer? && (pressed_up? || pressed_right? || pressed_left? || pressed_down?)
27
- end
28
- end
@@ -1,15 +0,0 @@
1
- module ProconBypassMan::Procon::PressedButtonHelper
2
- module Dynamic
3
- @@compiled = false
4
- def compile_if_not_compile_yet!
5
- unless @@compiled
6
- ::ProconBypassMan::Procon::ButtonCollection::BUTTONS_MAP.each do |button, _value|
7
- define_method "pressed_#{button}?" do
8
- pressed_button?(button)
9
- end
10
- end
11
- end
12
- @@compiled = true
13
- end
14
- end
15
- end
@@ -1,15 +0,0 @@
1
- require "time"
2
-
3
- module ProconBypassMan
4
- class Uptime
5
- def self.from_boot
6
- result = `uptime -s`.chomp
7
- return -1 if result == '' # darwin系だとsオプションが使えない
8
- boot_time = result.to_i
9
- return Time.now.to_i - boot_time.to_i
10
- rescue => e
11
- ProconBypassMan.logger.error(e)
12
- return -1
13
- end
14
- end
15
- end