Skip to content

Commit f94c3da

Browse files
Merge pull request #201 from gjsjohnmurray/ivory-emu
Sort our Accounts menu entries when loading them
2 parents b8ee1c7 + 033ca3f commit f94c3da

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/authenticationProvider.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ export class ServerManagerAuthenticationProvider implements AuthenticationProvid
181181
this._sessions[index] = session;
182182
changed.push(session);
183183
} else {
184+
// No point re-sorting here because onDidChangeSessions always appends added items to the provider's entries in the Accounts menu
184185
this._sessions.push(session);
185186
added.push(session);
186187
}
@@ -278,7 +279,20 @@ export class ServerManagerAuthenticationProvider implements AuthenticationProvid
278279
const accessToken = await this._secretStorage.get(credentialKey);
279280
return new ServerManagerAuthenticationSession(session.serverName, session.userName, accessToken);
280281
}),
281-
)).filter((session) => session.accessToken);
282+
)).filter((session) => session.accessToken).sort((a, b) => {
283+
const aUserNameLowercase = a.userName.toLowerCase();
284+
const bUserNameLowercase = b.userName.toLowerCase();
285+
if (aUserNameLowercase < bUserNameLowercase) {
286+
return -1;
287+
}
288+
if (aUserNameLowercase > bUserNameLowercase) {
289+
return 1;
290+
}
291+
if (a.serverName < b.serverName) {
292+
return -1;
293+
}
294+
return 1;
295+
});
282296
}
283297

284298
private async _storeStrippedSessions() {

0 commit comments

Comments
 (0)