File tree Expand file tree Collapse file tree 1 file changed +11
-1
lines changed Expand file tree Collapse file tree 1 file changed +11
-1
lines changed Original file line number Diff line number Diff 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 * h t t p s : \/ \/ l e e t c o d e / 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
122132export const leetCodeManager : LeetCodeManager = new LeetCodeManager ( ) ;
You can’t perform that action at this time.
0 commit comments