File tree Expand file tree Collapse file tree 1 file changed +8
-9
lines changed Expand file tree Collapse file tree 1 file changed +8
-9
lines changed Original file line number Diff line number Diff line change @@ -112,20 +112,24 @@ def get_oauth_code(client, options)
112
112
113
113
require 'launchy'
114
114
require 'webrick'
115
+
115
116
code = nil
116
117
server = WEBrick ::HTTPServer . new (
117
118
Port : @port ,
118
119
Logger : WEBrick ::Log . new ( STDOUT , 0 ) ,
119
120
AccessLog : [ ]
120
121
)
122
+
121
123
server . mount_proc '/' do |req , res |
122
124
code = req . query [ 'code' ]
123
125
res . status = 202
124
126
res . body = 'Login successful, you may close this browser window.'
125
- server . stop
127
+ server . shutdown
126
128
end
129
+
127
130
trap ( 'INT' ) { server . shutdown }
128
131
client . redirect_uri = "http://localhost:#{ @port } "
132
+
129
133
silence_output do
130
134
launchy = Launchy . open ( client . authorization_uri ( options ) . to_s )
131
135
server_thread = Thread . new do
@@ -134,15 +138,10 @@ def get_oauth_code(client, options)
134
138
ensure server . shutdown
135
139
end
136
140
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
145
143
end
144
+
146
145
code || raise ( 'Local Google Oauth failed to get code' )
147
146
ensure
148
147
trap ( 'INT' , 'DEFAULT' )
You can’t perform that action at this time.
0 commit comments