File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -112,20 +112,24 @@ def get_oauth_code(client, options)
112112
113113 require 'launchy'
114114 require 'webrick'
115+
115116 code = nil
116117 server = WEBrick ::HTTPServer . new (
117118 Port : @port ,
118119 Logger : WEBrick ::Log . new ( STDOUT , 0 ) ,
119120 AccessLog : [ ]
120121 )
122+
121123 server . mount_proc '/' do |req , res |
122124 code = req . query [ 'code' ]
123125 res . status = 202
124126 res . body = 'Login successful, you may close this browser window.'
125- server . stop
127+ server . shutdown
126128 end
129+
127130 trap ( 'INT' ) { server . shutdown }
128131 client . redirect_uri = "http://localhost:#{ @port } "
132+
129133 silence_output do
130134 launchy = Launchy . open ( client . authorization_uri ( options ) . to_s )
131135 server_thread = Thread . new do
@@ -134,15 +138,10 @@ def get_oauth_code(client, options)
134138 ensure server . shutdown
135139 end
136140 end
137- while server_thread . alive?
138- unless launchy . alive? && launchy . value . success?
139- server . shutdown
140- raise RuntimeError . new ( 'Failed to launch browser with Launchy' )
141- end
142-
143- sleep 0.1
144- end
141+
142+ server_thread . join
145143 end
144+
146145 code || raise ( 'Local Google Oauth failed to get code' )
147146 ensure
148147 trap ( 'INT' , 'DEFAULT' )
You can’t perform that action at this time.
0 commit comments