@@ -7,79 +7,30 @@ import globals from '../shared/extensionGlobals'
7
7
8
8
import * as vscode from 'vscode'
9
9
import { getLogger } from '../shared/logger'
10
- import { showQuickPick } from '../shared/ui/pickerPrompter'
11
10
import { cast , Optional } from '../shared/utilities/typeConstructors'
12
11
import { Auth } from './auth'
13
12
import { once } from '../shared/utilities/functionUtils'
14
- import { telemetry } from '../shared/telemetry/telemetry'
15
- import { createExitButton , createHelpButton } from '../shared/ui/buttons'
16
13
import { isNonNullable } from '../shared/utilities/tsUtils'
17
14
import { CancellationError } from '../shared/utilities/timeoutUtils'
18
15
import { Connection , SsoConnection , StatefulConnection } from './connection'
19
16
20
- async function promptUseNewConnection ( newConn : Connection , oldConn : Connection , tools : string [ ] , swapNo : boolean ) {
21
- // Multi-select picker would be better ?
22
- const saveConnectionItem = {
23
- label : `Yes, keep using ${ newConn . label } with ${ tools . join ( ', ' ) } while using ${
24
- oldConn . label
25
- } with other services.`,
26
- detail : `To remove later, select "Remove Connection from Tool" from the tool's context (right-click) menu.` ,
27
- data : 'yes' ,
28
- } as const
29
-
30
- const useConnectionItem = {
31
- label : `No, switch everything to authenticate with ${ ( swapNo ? newConn : oldConn ) . label } .` ,
32
- detail : 'This will not log you out; you can reconnect at any time by switching connections.' ,
33
- data : 'no' ,
34
- } as const
35
-
36
- const helpButton = createHelpButton ( )
37
- const openLink = helpButton . onClick . bind ( helpButton )
38
- helpButton . onClick = ( ) => {
39
- telemetry . ui_click . emit ( { elementId : 'connection_multiple_auths_help' } )
40
- openLink ( )
41
- }
42
-
43
- const resp = await showQuickPick ( [ saveConnectionItem , useConnectionItem ] , {
44
- title : `Some tools you've been using don't work with ${ oldConn . label } . Keep using ${ newConn . label } in the background while using ${ oldConn . label } ?` ,
45
- placeholder : 'Confirm choice' ,
46
- buttons : [ helpButton , createExitButton ( ) ] ,
47
- } )
48
-
49
- switch ( resp ) {
50
- case 'yes' :
51
- telemetry . ui_click . emit ( { elementId : 'connection_multiple_auths_yes' } )
52
- break
53
- case 'no' :
54
- telemetry . ui_click . emit ( { elementId : 'connection_multiple_auths_no' } )
55
- break
56
- default :
57
- telemetry . ui_click . emit ( { elementId : 'connection_multiple_auths_exit' } )
58
- }
59
-
60
- return resp
61
- }
62
-
63
- let oldConn : Auth [ 'activeConnection' ]
17
+ let currentConn : Auth [ 'activeConnection' ]
64
18
const auths = new Map < string , SecondaryAuth > ( )
65
19
const multiConnectionListeners = new WeakMap < Auth , vscode . Disposable > ( )
66
20
const registerAuthListener = ( auth : Auth ) => {
67
- return auth . onDidChangeActiveConnection ( async conn => {
68
- const potentialConn = oldConn
69
- if ( conn !== undefined && potentialConn ?. state === 'valid' ) {
21
+ return auth . onDidChangeActiveConnection ( async newConn => {
22
+ // When we change the active connection, there may be
23
+ // secondary auths that were dependent on the previous active connection.
24
+ // To ensure secondary auths still work, when we change to a new active connection,
25
+ // the following will "save" the oldConn with the secondary auths that are using it.
26
+ const oldConn = currentConn
27
+ if ( newConn && oldConn ?. state === 'valid' ) {
70
28
const saveableAuths = Array . from ( auths . values ( ) ) . filter (
71
- a => ! a . isUsingSavedConnection && a . isUsable ( potentialConn ) && ! a . isUsable ( conn )
29
+ a => ! a . hasSavedConnection && a . isUsable ( oldConn ) && ! a . isUsable ( newConn )
72
30
)
73
- const toolNames = saveableAuths . map ( a => a . toolLabel )
74
- if (
75
- saveableAuths . length > 0 &&
76
- ( await promptUseNewConnection ( potentialConn , conn , toolNames , false ) ) === 'yes'
77
- ) {
78
- await Promise . all ( saveableAuths . map ( a => a . saveConnection ( potentialConn ) ) )
79
- }
31
+ await Promise . all ( saveableAuths . map ( a => a . saveConnection ( oldConn ) ) )
80
32
}
81
-
82
- oldConn = conn
33
+ currentConn = newConn
83
34
} )
84
35
}
85
36
@@ -104,15 +55,13 @@ export function getSecondaryAuth<T extends Connection>(
104
55
* Gets all {@link SecondaryAuth} instances that have saved the connection
105
56
*/
106
57
export function getDependentAuths ( conn : Connection ) : SecondaryAuth [ ] {
107
- return Array . from ( auths . values ( ) ) . filter (
108
- auth => auth . isUsingSavedConnection && auth . activeConnection ?. id === conn . id
109
- )
58
+ return Array . from ( auths . values ( ) ) . filter ( auth => auth . hasSavedConnection && auth . activeConnection ?. id === conn . id )
110
59
}
111
60
112
61
export function getAllConnectionsInUse ( auth : Auth ) : StatefulConnection [ ] {
113
62
const connMap = new Map < Connection [ 'id' ] , StatefulConnection > ( )
114
63
const toolConns = Array . from ( auths . values ( ) )
115
- . filter ( a => a . isUsingSavedConnection )
64
+ . filter ( a => a . hasSavedConnection )
116
65
. map ( a => a . activeConnection )
117
66
118
67
for ( const conn of [ auth . activeConnection , ...toolConns ] . filter ( isNonNullable ) ) {
@@ -174,13 +123,18 @@ export class SecondaryAuth<T extends Connection = Connection> {
174
123
}
175
124
176
125
public get activeConnection ( ) : T | undefined {
177
- return (
178
- this . #savedConnection ??
179
- ( this . #activeConnection && this . isUsable ( this . #activeConnection) ? this . #activeConnection : undefined )
180
- )
126
+ if ( this . #savedConnection) {
127
+ return this . #savedConnection
128
+ }
129
+
130
+ if ( this . #activeConnection && this . isUsable ( this . #activeConnection) ) {
131
+ return this . #activeConnection
132
+ }
133
+
134
+ return undefined
181
135
}
182
136
183
- public get isUsingSavedConnection ( ) {
137
+ public get hasSavedConnection ( ) {
184
138
return this . #savedConnection !== undefined
185
139
}
186
140
@@ -202,11 +156,7 @@ export class SecondaryAuth<T extends Connection = Connection> {
202
156
203
157
public async useNewConnection ( conn : T ) {
204
158
if ( this . auth . activeConnection !== undefined && ! this . isUsable ( this . auth . activeConnection ) ) {
205
- if ( ( await promptUseNewConnection ( conn , this . auth . activeConnection , [ this . toolLabel ] , true ) ) === 'yes' ) {
206
- await this . saveConnection ( conn )
207
- } else {
208
- await this . auth . useConnection ( conn )
209
- }
159
+ await this . saveConnection ( conn )
210
160
} else {
211
161
await this . auth . useConnection ( conn )
212
162
}
0 commit comments