Skip to content

Commit be4f2d5

Browse files
authored
[bugfix] Correct the content shown in status-bar (#202)
1 parent f77737d commit be4f2d5

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/leetCodeManager.ts

+11-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class LeetCodeManager extends EventEmitter {
2424
public async getLoginStatus(): Promise<void> {
2525
try {
2626
const result: string = await leetCodeExecutor.getUserInfo();
27-
this.currentUser = result.slice("You are now login as".length).trim();
27+
this.currentUser = this.tryParseUserName(result);
2828
this.userStatus = UserStatus.SignedIn;
2929
} catch (error) {
3030
this.currentUser = undefined;
@@ -117,6 +117,16 @@ class LeetCodeManager extends EventEmitter {
117117
public getUser(): string | undefined {
118118
return this.currentUser;
119119
}
120+
121+
private tryParseUserName(output: string): string {
122+
const reg: RegExp = /^\s*.\s*(.+?)\s*https:\/\/leetcode/m;
123+
const match: RegExpMatchArray | null = output.match(reg);
124+
if (match && match.length === 2) {
125+
return match[1].trim();
126+
}
127+
128+
return "Unknown";
129+
}
120130
}
121131

122132
export const leetCodeManager: LeetCodeManager = new LeetCodeManager();

0 commit comments

Comments
 (0)