git_game_show 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: eb852185be4e80bb32062b74675572ddcc45ea5e4ec8716969b90d0d73225fe8
4
- data.tar.gz: 6ac3c1001051cb307caf4a6e1c87778fe1d94812c3b7f32f2e27045cef0f00a8
3
+ metadata.gz: 4625a491676e8c880e9bc2177a81dd5a18ba3dfe80759fbed2ab25858fe77413
4
+ data.tar.gz: 5db3afb4bd0d77f191a9072c297d886da3d32542beb8fb547745c15e2360a310
5
5
  SHA512:
6
- metadata.gz: 824c2da32e7802bc354b28196a41eb4b8c4acd84de92208f97b3eaba61a61ba83c6724ddeabc08d62ef0ca00f6617ca6409ae82739cc4ae06e1c126f21b9449e
7
- data.tar.gz: 13fc7daecb192024caf2f64b1373556999e32608209f53de7111afbe5b575917af34e44585821526332e690b224425ebc451b5938f687776e61297fbfff4cc0f
6
+ metadata.gz: 5835535f86082ea1f8fdd2a27b052f60b25b113e047118d5ca2e031d7ff3f5fb9612b4d46ec888745be3fb982492430f24a49b8d0b1d25fb6fd65ad26258d462
7
+ data.tar.gz: 34fc53a39c14184d69313fbadf2a6ac7fe17d9e9c46423cccf3bfafefb3c97915affffe4f09145288f0d144bf6a73e350dae30fa93d7f30426aea23a4b5e163f
data/bin/git-game-show CHANGED
@@ -2,4 +2,22 @@
2
2
 
3
3
  require "git_game_show"
4
4
 
5
+ # Skip auto-update check when running explicit commands
6
+ # Only check when running without arguments or with --version
7
+ if ARGV.empty? || ARGV.include?('--version') || ARGV.include?('-v')
8
+ begin
9
+ # Load the updater if available
10
+ updater_path = File.join(File.dirname(__FILE__), "../lib/git_game_show/updater.rb")
11
+ require updater_path if File.exist?(updater_path)
12
+
13
+ # Auto-check for updates (only when running the welcome screen)
14
+ if defined?(GitGameShow::Updater) && ARGV.empty?
15
+ GitGameShow::Updater.check_for_updates
16
+ end
17
+ rescue => e
18
+ # Silent fail on update check
19
+ end
20
+ end
21
+
22
+ # Start the CLI
5
23
  GitGameShow::CLI.start(ARGV)
@@ -7,16 +7,23 @@ module GitGameShow
7
7
  desc 'version', 'Display Git Game Show version'
8
8
  def version
9
9
  puts "Git Game Show version #{GitGameShow::VERSION}"
10
+
11
+ # Check for updates if the Updater class exists
12
+ GitGameShow::Updater.check_for_updates if defined?(GitGameShow::Updater)
10
13
  end
11
14
 
12
15
  desc '', 'Show welcome screen'
13
16
  def welcome
14
17
  display_welcome_screen
18
+
19
+ # Check for updates if the Updater class exists
20
+ GitGameShow::Updater.check_for_updates if defined?(GitGameShow::Updater)
15
21
 
16
22
  prompt = TTY::Prompt.new
17
23
  choice = prompt.select("What would you like to do?", [
18
24
  {name: "Host a new game", value: :host},
19
25
  {name: "Join a game", value: :join},
26
+ {name: "Check for updates", value: :update},
20
27
  {name: "Exit", value: :exit}
21
28
  ])
22
29
 
@@ -25,6 +32,28 @@ module GitGameShow
25
32
  prompt_for_host_options
26
33
  when :join
27
34
  prompt_for_join_options
35
+ when :update
36
+ if defined?(GitGameShow::Updater)
37
+ # Force check for updates
38
+ current_version = GitGameShow::VERSION
39
+ puts "Current version: #{current_version}"
40
+ puts "Checking for updates..."
41
+
42
+ latest_version = GitGameShow::Updater.send(:fetch_latest_version)
43
+ if latest_version.nil?
44
+ puts "Unable to connect to RubyGems.org. Please check your internet connection."
45
+ elsif GitGameShow::Updater.send(:newer_version_available?, current_version, latest_version)
46
+ GitGameShow::Updater.send(:display_update_prompt, current_version, latest_version)
47
+ else
48
+ puts "✓ You already have the latest version (#{current_version})!".colorize(:green)
49
+ end
50
+
51
+ # Return to welcome screen after checking
52
+ welcome
53
+ else
54
+ puts "Update feature not available. Please update manually with 'gem update git_game_show'."
55
+ welcome
56
+ end
28
57
  when :exit
29
58
  puts "Thanks for playing Git Game Show!"
30
59
  exit(0)
@@ -399,7 +428,13 @@ module GitGameShow
399
428
  # Generate a secure join link with embedded password
400
429
  # If we have a ngrok tunnel, use the ngrok port, otherwise use the original port
401
430
  port_to_use = defined?(ngrok_port) ? ngrok_port : options[:port]
402
- secure_link = "gitgame://#{ip}:#{port_to_use}/#{URI.encode_www_form_component(password)}"
431
+
432
+ # Include protocol information in the secure link to help client determine ws:// vs wss://
433
+ # For ngrok URLs, add a flag to indicate secure WebSocket is needed
434
+ is_ngrok = ip.include?('ngrok.io') || ip.include?('ngrok-free.app') || ip.include?('ngrok.app')
435
+ protocol_flag = is_ngrok ? "secure=" : ""
436
+
437
+ secure_link = "gitgame://#{ip}:#{port_to_use}/#{URI.encode_www_form_component(password)}?#{protocol_flag}"
403
438
 
404
439
  # Start the server with the improved UI and pass the join link
405
440
  server.start_with_ui(secure_link)
@@ -424,11 +459,15 @@ module GitGameShow
424
459
  host = uri.host
425
460
  port = uri.port || GitGameShow::DEFAULT_CONFIG[:port]
426
461
  password = URI.decode_www_form_component(uri.path.sub('/', ''))
462
+
463
+ # Check if this is a secure (ngrok) connection from query params
464
+ is_secure = !uri.query.nil? && uri.query.include?('secure=')
427
465
  else
428
466
  # Legacy format - assume it's host:port
429
467
  host, port = secure_link.split(':')
430
468
  port ||= GitGameShow::DEFAULT_CONFIG[:port]
431
469
  password = options[:password]
470
+ is_secure = false
432
471
 
433
472
  # If no password provided in legacy format, ask for it
434
473
  unless password
@@ -450,7 +489,8 @@ module GitGameShow
450
489
  host: host,
451
490
  port: port.to_i,
452
491
  password: password,
453
- name: name
492
+ name: name,
493
+ secure: is_secure
454
494
  )
455
495
 
456
496
  puts "=== Git Game Show Client ===".colorize(:green)
@@ -4,13 +4,14 @@ require 'timeout'
4
4
 
5
5
  module GitGameShow
6
6
  class PlayerClient
7
- attr_reader :host, :port, :password, :name
7
+ attr_reader :host, :port, :password, :name, :secure
8
8
 
9
- def initialize(host:, port:, password:, name:)
9
+ def initialize(host:, port:, password:, name:, secure: false)
10
10
  @host = host
11
11
  @port = port
12
12
  @password = password
13
13
  @name = name
14
+ @secure = secure
14
15
  @ws = nil
15
16
  @prompt = TTY::Prompt.new
16
17
  @players = []
@@ -21,7 +22,17 @@ module GitGameShow
21
22
  def connect
22
23
  begin
23
24
  client = self # Store reference to the client instance
24
- @ws = WebSocket::Client::Simple.connect("ws://#{host}:#{port}")
25
+
26
+ # Support both ws:// and wss:// protocols (needed for ngrok)
27
+ # Use wss:// if secure flag is set or if host contains ngrok domains
28
+ protocol = if @secure || host.include?('ngrok.io') || host.include?('ngrok-free.app') || host.include?('ngrok.app')
29
+ puts "Using secure WebSocket connection (wss://)".colorize(:cyan)
30
+ 'wss'
31
+ else
32
+ 'ws'
33
+ end
34
+
35
+ @ws = WebSocket::Client::Simple.connect("#{protocol}://#{host}:#{port}")
25
36
 
26
37
  @ws.on :open do
27
38
  puts "Connected to server".colorize(:green)
@@ -0,0 +1,107 @@
1
+ require 'net/http'
2
+ require 'json'
3
+ require 'uri'
4
+ require 'rubygems'
5
+ require 'colorize'
6
+ require 'tty-prompt'
7
+
8
+ module GitGameShow
9
+ class Updater
10
+ class << self
11
+ def check_for_updates
12
+ current_version = GitGameShow::VERSION
13
+ latest_version = fetch_latest_version
14
+
15
+ return if latest_version.nil?
16
+
17
+ # Compare versions
18
+ if newer_version_available?(current_version, latest_version)
19
+ display_update_prompt(current_version, latest_version)
20
+ end
21
+ end
22
+
23
+ private
24
+
25
+ def fetch_latest_version
26
+ begin
27
+ uri = URI.parse("https://rubygems.org/api/v1/gems/git_game_show.json")
28
+ response = Net::HTTP.get_response(uri)
29
+
30
+ if response.code == "200"
31
+ data = JSON.parse(response.body)
32
+ return data["version"]
33
+ else
34
+ # Silently fail on network errors
35
+ return nil
36
+ end
37
+ rescue => e
38
+ # Silently fail on connection errors
39
+ return nil
40
+ end
41
+ end
42
+
43
+ def newer_version_available?(current, latest)
44
+ # Convert version strings to comparable arrays
45
+ current_parts = current.split('.').map(&:to_i)
46
+ latest_parts = latest.split('.').map(&:to_i)
47
+
48
+ # Compare each part numerically
49
+ latest_parts.zip(current_parts).each do |latest_part, current_part|
50
+ return true if latest_part > current_part
51
+ return false if latest_part < current_part
52
+ end
53
+
54
+ # If we get here and versions are different lengths, the longer one is newer
55
+ return latest_parts.length > current_parts.length
56
+ end
57
+
58
+ def display_update_prompt(current_version, latest_version)
59
+ prompt = TTY::Prompt.new
60
+
61
+ # Clear the terminal for better visibility
62
+ puts "\n\n"
63
+
64
+ puts "┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓".colorize(:cyan)
65
+ puts "┃ UPDATE AVAILABLE FOR GIT GAME SHOW ┃".colorize(:cyan)
66
+ puts "┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫".colorize(:cyan)
67
+ puts "┃ ┃".colorize(:cyan)
68
+ puts "┃ Current version: #{current_version.ljust(38)} ┃".colorize(:cyan)
69
+ puts "┃ Latest version: #{latest_version.ljust(38)} ┃".colorize(:cyan)
70
+ puts "┃ ┃".colorize(:cyan)
71
+ puts "┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛".colorize(:cyan)
72
+ puts "\n"
73
+
74
+ update_now = prompt.yes?("Would you like to update now?")
75
+
76
+ if update_now
77
+ perform_update
78
+ else
79
+ puts "You can update later by running: gem update git_game_show".colorize(:yellow)
80
+ puts "\nContinuing with current version...\n\n"
81
+ end
82
+ end
83
+
84
+ def perform_update
85
+ puts "\nUpdating Git Game Show to the latest version...".colorize(:cyan)
86
+
87
+ begin
88
+ # Use system to capture both stdout and stderr
89
+ update_command = "gem update git_game_show"
90
+ result = system(update_command)
91
+
92
+ if result
93
+ puts "\n✅ Update completed successfully!".colorize(:green)
94
+ puts "Please restart Git Game Show to use the new version.".colorize(:yellow)
95
+ exit(0)
96
+ else
97
+ puts "\n❌ Update failed with exit code: #{$?.exitstatus}".colorize(:red)
98
+ puts "You can manually update by running: gem update git_game_show".colorize(:yellow)
99
+ end
100
+ rescue => e
101
+ puts "\n❌ Update failed: #{e.message}".colorize(:red)
102
+ puts "You can manually update by running: gem update git_game_show".colorize(:yellow)
103
+ end
104
+ end
105
+ end
106
+ end
107
+ end
@@ -1,4 +1,4 @@
1
1
  module GitGameShow
2
2
  # Current version of Git Game Show
3
- VERSION = "0.1.2"
4
- end
3
+ VERSION = "0.1.3"
4
+ end
data/lib/git_game_show.rb CHANGED
@@ -12,6 +12,7 @@ require 'uri'
12
12
  require 'clipboard'
13
13
  require 'readline'
14
14
  require 'timeout'
15
+ require 'net/http'
15
16
 
16
17
  # Define module and constants first before loading any other files
17
18
  module GitGameShow
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: git_game_show
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Paulson
@@ -210,6 +210,7 @@ files:
210
210
  - lib/git_game_show/game_server.rb
211
211
  - lib/git_game_show/mini_game.rb
212
212
  - lib/git_game_show/player_client.rb
213
+ - lib/git_game_show/updater.rb
213
214
  - lib/git_game_show/version.rb
214
215
  - mini_games/author_quiz.rb
215
216
  - mini_games/commit_message_completion.rb