@@ -183,16 +183,16 @@ class QWebviewBrowser(val project: Project, private val parentDisposable: Dispos
183183 ToolkitConnectionManager .getInstance(project)
184184 .activeConnectionForFeature(QConnection .getInstance()) as ? AwsBearerTokenConnection
185185 )?.let { connection ->
186- runInEdt {
187- SsoLogoutAction (connection).actionPerformed(
188- AnActionEvent .createFromDataContext(
189- " qBrowser" ,
190- null ,
191- DataContext .EMPTY_CONTEXT
192- )
186+ runInEdt {
187+ SsoLogoutAction (connection).actionPerformed(
188+ AnActionEvent .createFromDataContext(
189+ " qBrowser" ,
190+ null ,
191+ DataContext .EMPTY_CONTEXT
193192 )
194- }
193+ )
195194 }
195+ }
196196 }
197197
198198 is BrowserMessage .Reauth -> {
@@ -220,6 +220,10 @@ class QWebviewBrowser(val project: Project, private val parentDisposable: Dispos
220220 )
221221 }
222222
223+ is BrowserMessage .ListProfiles -> {
224+ handleListProfilesMessage()
225+ }
226+
223227 is BrowserMessage .PublishWebviewTelemetry -> {
224228 publishTelemetry(message)
225229 }
@@ -272,48 +276,6 @@ class QWebviewBrowser(val project: Project, private val parentDisposable: Dispos
272276
273277 when (stage) {
274278 " PROFILE_SELECT" -> {
275- ApplicationManager .getApplication().executeOnPooledThread {
276- var errorMessage: String = " "
277- val profiles = try {
278- QRegionProfileManager .getInstance().listRegionProfiles(project)
279- } catch (e: Exception ) {
280- e.message?.let {
281- errorMessage = it
282- }
283- LOG .warn { " Failed to call listRegionProfiles API: $errorMessage " }
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)
292- }
293-
294- null
295- }
296-
297- if (profiles?.size == 1 ) {
298- LOG .debug { " User only have access to 1 Q profile, auto-selecting profile ${profiles.first().profileName} for ${project.name} " }
299- QRegionProfileManager .getInstance().switchProfile(project, profiles.first(), QProfileSwitchIntent .Update )
300- }
301-
302- // required EDT as this entire block is executed on thread pool
303- runInEdt {
304- val jsonData = """
305- {
306- stage: '$stage ',
307- status: '${if (profiles != null ) " succeeded" else " failed" } ',
308- profiles: ${writeValueAsString(profiles ? : " " )} ,
309- errorMessage: '$errorMessage '
310- }
311- """ .trimIndent()
312-
313- executeJS(" window.ideClient.prepareUi($jsonData )" )
314- }
315- }
316-
317279 val jsonData = """
318280 {
319281 stage: '$stage ',
@@ -353,6 +315,51 @@ class QWebviewBrowser(val project: Project, private val parentDisposable: Dispos
353315 jcefBrowser.loadHTML(getWebviewHTML(webScriptUri, query))
354316 }
355317
318+ private fun handleListProfilesMessage () {
319+ ApplicationManager .getApplication().executeOnPooledThread {
320+ var errorMessage: String = " "
321+ val profiles = try {
322+ QRegionProfileManager .getInstance().listRegionProfiles(project)
323+ } catch (e: Exception ) {
324+ e.message?.let {
325+ errorMessage = it
326+ }
327+ LOG .warn { " Failed to call listRegionProfiles API: $errorMessage " }
328+ val qConn = ToolkitConnectionManager .getInstance(project).activeConnectionForFeature(QConnection .getInstance())
329+ Telemetry .amazonq.didSelectProfile.use { span ->
330+ span.source(QProfileSwitchIntent .Auth .value)
331+ .amazonQProfileRegion(QRegionProfileManager .getInstance().activeProfile(project)?.region ? : " not-set" )
332+ .ssoRegion((qConn as ? AwsBearerTokenConnection )?.region)
333+ .credentialStartUrl((qConn as ? AwsBearerTokenConnection )?.startUrl)
334+ .result(MetricResult .Failed )
335+ .reason(e.message)
336+ }
337+
338+ null
339+ }
340+
341+ if (profiles?.size == 1 ) {
342+ LOG .debug { " User only have access to 1 Q profile, auto-selecting profile ${profiles.first().profileName} for ${project.name} " }
343+ QRegionProfileManager .getInstance().switchProfile(project, profiles.first(), QProfileSwitchIntent .Update )
344+ return @executeOnPooledThread
345+ }
346+
347+ // required EDT as this entire block is executed on thread pool
348+ runInEdt {
349+ val jsonData = """
350+ {
351+ stage: 'PROFILE_SELECT',
352+ status: '${if (profiles != null ) " succeeded" else " failed" } ',
353+ profiles: ${writeValueAsString(profiles ? : " " )} ,
354+ errorMessage: '$errorMessage '
355+ }
356+ """ .trimIndent()
357+
358+ executeJS(" window.ideClient.prepareUi($jsonData )" )
359+ }
360+ }
361+ }
362+
356363 companion object {
357364 private val LOG = getLogger<QWebviewBrowser >()
358365 private const val WEB_SCRIPT_URI = " http://webview/js/getStart.js"
0 commit comments