@@ -182,16 +182,16 @@ class QWebviewBrowser(val project: Project, private val parentDisposable: Dispos
182182 ToolkitConnectionManager .getInstance(project)
183183 .activeConnectionForFeature(QConnection .getInstance()) as ? AwsBearerTokenConnection
184184 )?.let { connection ->
185- runInEdt {
186- SsoLogoutAction (connection).actionPerformed(
187- AnActionEvent .createFromDataContext(
188- " qBrowser" ,
189- null ,
190- DataContext .EMPTY_CONTEXT
185+ runInEdt {
186+ SsoLogoutAction (connection).actionPerformed(
187+ AnActionEvent .createFromDataContext(
188+ " qBrowser" ,
189+ null ,
190+ DataContext .EMPTY_CONTEXT
191+ )
191192 )
192- )
193+ }
193194 }
194- }
195195 }
196196
197197 is BrowserMessage .Reauth -> {
@@ -261,56 +261,79 @@ class QWebviewBrowser(val project: Project, private val parentDisposable: Dispos
261261 writeValueAsString(it)
262262 }
263263
264- // TODO: pass "REAUTH" if connection expires
265- // Perform the potentially blocking AWS call outside the EDT to fetch available region profiles.
266- ApplicationManager .getApplication().executeOnPooledThread {
267- val stage = if (isQExpired(project)) {
268- " REAUTH"
269- } else if (isQConnected(project) && QRegionProfileManager .getInstance().isPendingProfileSelection(project)) {
270- " PROFILE_SELECT"
271- } else {
272- " START"
273- }
264+ val stage = if (isQExpired(project)) {
265+ " REAUTH"
266+ } else if (isQConnected(project) && QRegionProfileManager .getInstance().isPendingProfileSelection(project)) {
267+ " PROFILE_SELECT"
268+ } else {
269+ " START"
270+ }
271+
272+ when (stage) {
273+ " PROFILE_SELECT" -> {
274+ ApplicationManager .getApplication().executeOnPooledThread {
275+ var errorMessage: String = " "
276+ val profiles = try {
277+ QRegionProfileManager .getInstance().listRegionProfiles(project)
278+ } catch (e: Exception ) {
279+ e.message?.let {
280+ errorMessage = it
281+ }
282+ LOG .warn { " Failed to call listRegionProfiles API: $errorMessage " }
283+ val qConn = ToolkitConnectionManager .getInstance(project).activeConnectionForFeature(QConnection .getInstance())
284+ Telemetry .amazonq.didSelectProfile.use { span ->
285+ span.source(QProfileSwitchIntent .Auth .value)
286+ .amazonQProfileRegion(QRegionProfileManager .getInstance().activeProfile(project)?.region ? : " not-set" )
287+ .ssoRegion((qConn as ? AwsBearerTokenConnection )?.region)
288+ .credentialStartUrl((qConn as ? AwsBearerTokenConnection )?.startUrl)
289+ .result(MetricResult .Failed )
290+ .reason(e.message)
291+ }
274292
275- var errorMessage: String? = null
276- var profiles: List <QRegionProfile > = emptyList()
277-
278- if (stage == " PROFILE_SELECT" ) {
279- try {
280- profiles = QRegionProfileManager .getInstance().listRegionProfiles(project).orEmpty()
281- } catch (e: Exception ) {
282- errorMessage = e.message
283- LOG .warn { " Failed to call listRegionProfiles API" }
284- val qConn = ToolkitConnectionManager .getInstance(project).activeConnectionForFeature(QConnection .getInstance())
285- Telemetry .amazonq.didSelectProfile.use { span ->
286- span.source(QProfileSwitchIntent .Auth .value)
287- .amazonQProfileRegion(QRegionProfileManager .getInstance().activeProfile(project)?.region ? : " not-set" )
288- .ssoRegion((qConn as ? AwsBearerTokenConnection )?.region)
289- .credentialStartUrl((qConn as ? AwsBearerTokenConnection )?.startUrl)
290- .result(MetricResult .Failed )
291- .reason(e.message)
293+ null
294+ }
295+
296+ // required EDT as this entire block is executed on thread pool
297+ runInEdt {
298+ val jsonData = """
299+ {
300+ stage: '$stage ',
301+ status: '${if (profiles != null ) " succeeded" else " failed" } ',
302+ profiles: ${writeValueAsString(profiles ? : " " )} ,
303+ errorMessage: '$errorMessage '
304+ }
305+ """ .trimIndent()
306+
307+ println (jsonData)
308+ executeJS(" window.ideClient.prepareUi($jsonData )" )
292309 }
293310 }
294- }
295311
296- val jsonData = """
297- {
298- stage: '$stage ',
299- regions: $regions ,
300- idcInfo: {
301- profileName: '${lastLoginIdcInfo.profileName} ',
302- startUrl: '${lastLoginIdcInfo.startUrl} ',
303- region: '${lastLoginIdcInfo.region} '
304- },
305- cancellable: ${state.browserCancellable} ,
306- feature: '${state.feature} ',
307- existConnections: ${writeValueAsString(selectionSettings.values.map { it.currentSelection }.toList())} ,
308- profiles: ${writeValueAsString(profiles)} ,
309- errorMessage: ${errorMessage?.let { " \" $it \" " } ? : " null" }
312+ val jsonData = """
313+ {
314+ stage: '$stage ',
315+ status: 'pending'
316+ }
317+ """ .trimIndent()
318+ executeJS(" window.ideClient.prepareUi($jsonData )" )
310319 }
311- """ .trimIndent()
312320
313- runInEdt {
321+ else -> {
322+ val jsonData = """
323+ {
324+ stage: '$stage ',
325+ regions: $regions ,
326+ idcInfo: {
327+ profileName: '${lastLoginIdcInfo.profileName} ',
328+ startUrl: '${lastLoginIdcInfo.startUrl} ',
329+ region: '${lastLoginIdcInfo.region} '
330+ },
331+ cancellable: ${state.browserCancellable} ,
332+ feature: '${state.feature} ',
333+ existConnections: ${writeValueAsString(selectionSettings.values.map { it.currentSelection }.toList())} ,
334+ }
335+ """ .trimIndent()
336+
314337 executeJS(" window.ideClient.prepareUi($jsonData )" )
315338 }
316339 }
0 commit comments