@@ -23,10 +23,6 @@ import { Commands, placeholder } from '../shared/vscode/commands2'
2323import { focusAmazonQPanel , focusAmazonQPanelKeybinding } from '../codewhispererChat/commands/registerCommands'
2424import { TryChatCodeLensProvider , tryChatCodeLensCommand } from '../codewhispererChat/editor/codelens'
2525import { Auth } from '../auth'
26- import { learnMoreUri } from '../codewhisperer/models/constants'
27- import { openUrl } from '../shared/utilities/vsCodeUtils'
28- import { AuthUtil } from '../codewhisperer'
29- import { ConnectionStateChangeEvent } from '../auth/auth'
3026import { telemetry } from '../shared/telemetry'
3127
3228export async function activate ( context : ExtensionContext ) {
@@ -64,10 +60,7 @@ export async function activate(context: ExtensionContext) {
6460 } )
6561
6662 await activateBadge ( )
67- void setupAuthNotification (
68- appInitContext . onDidChangeAmazonQVisibility . event ,
69- Auth . instance . onDidChangeConnectionState
70- )
63+ void setupAuthNotification ( )
7164}
7265
7366function registerApps ( appInitContext : AmazonQAppInitContext ) {
@@ -80,85 +73,38 @@ function registerApps(appInitContext: AmazonQAppInitContext) {
8073 * Display a notification to user for Log In.
8174 *
8275 * Authentication Notification is displayed when:
83- * - The user closes the Amazon Q chat panel, and
84- * - The user has not performed any authentication action.
85- *
86- * Error Notification is displayed when:
87- * - The user closes the Amazon Q chat panel, and
88- * - The user attempts an authentication action but is not logged in.
76+ * - User is not authenticated
77+ * - Once every session
8978 *
90- * @param {Event } onAmazonQChatVisibility - Event indicating the visibility status of the Amazon Q chat.
91- * @param {Event } onDidUpdateConnection - Event indicating the authentication connection update.
9279 */
93- async function setupAuthNotification (
94- onAmazonQChatVisibility : vscode . Event < boolean > ,
95- onDidUpdateConnection : vscode . Event < ConnectionStateChangeEvent | undefined >
96- ) {
97- let isAmazonQVisible = true // Assume Chat is open by default.
80+ async function setupAuthNotification ( ) {
9881 let notificationDisplayed = false // Auth Notification should be displayed only once.
99- let authConnection : ConnectionStateChangeEvent
100-
101- // Updates the visibility state of the Amazon Q chat.
102- const updateVisibility = async ( visible : boolean ) => {
103- isAmazonQVisible = visible
104- await tryShowNotification ( )
105- }
82+ await tryShowNotification ( )
10683
107- // Updates the source of the connection for Amazon Q sign in.
108- const updateConnection = async ( connection : ConnectionStateChangeEvent | undefined ) => {
109- if ( connection ) {
110- authConnection = connection
111- await tryShowNotification ( )
84+ async function tryShowNotification ( ) {
85+ // Do not show the notification if the IDE starts and user is already authenticated.
86+ if ( Auth . instance . activeConnection ) {
87+ notificationDisplayed = true
11288 }
113- }
114-
115- const disposables : vscode . Disposable [ ] = [
116- onAmazonQChatVisibility ( updateVisibility ) ,
117- onDidUpdateConnection ( updateConnection ) ,
118- ]
11989
120- async function tryShowNotification ( ) {
121- if ( notificationDisplayed || Auth . instance . activeConnection ) {
90+ if ( notificationDisplayed ) {
12291 return
12392 }
12493
12594 const source = 'authNotification'
126-
127- if ( ! isAmazonQVisible && ! authConnection && ! AuthUtil . instance . isConnectionExpired ( ) ) {
128- const buttonAction = 'Sign In'
129- notificationDisplayed = true
130- disposables . forEach ( item => item . dispose ( ) )
131-
132- telemetry . toolkit_showNotification . emit ( {
133- component : 'editor' ,
134- id : source ,
135- reason : 'notLoggedIn' ,
136- result : 'Succeeded' ,
137- } )
138- const selection = await vscode . window . showWarningMessage ( 'Start using Amazon Q' , buttonAction )
139-
140- if ( selection === buttonAction ) {
141- void focusAmazonQPanel . execute ( placeholder , source )
142- }
143- } else if ( ! isAmazonQVisible && authConnection . state === 'authenticating' ) {
144- const buttonAction = 'Open documentation'
145- notificationDisplayed = true
146- disposables . forEach ( item => item . dispose ( ) )
147-
148- telemetry . toolkit_showNotification . emit ( {
149- component : 'editor' ,
150- id : source ,
151- reason : 'authenticating' ,
152- result : 'Succeeded' ,
153- } )
154- const selection = await vscode . window . showWarningMessage (
155- 'See Amazon Q documentation for help on signing in' ,
156- buttonAction
157- )
158-
159- if ( selection === buttonAction ) {
160- void openUrl ( vscode . Uri . parse ( `${ learnMoreUri } #q-in-IDE-setup-bid` ) , source )
161- }
95+ const buttonAction = 'Sign In'
96+ notificationDisplayed = true
97+
98+ telemetry . toolkit_showNotification . emit ( {
99+ component : 'editor' ,
100+ id : source ,
101+ reason : 'notLoggedIn' ,
102+ result : 'Succeeded' ,
103+ } )
104+ const selection = await vscode . window . showWarningMessage ( 'Start using Amazon Q' , buttonAction )
105+
106+ if ( selection === buttonAction ) {
107+ void focusAmazonQPanel . execute ( placeholder , source )
162108 }
163109 }
164110}
0 commit comments