@@ -14,6 +14,8 @@ import * as wsl from "./utils/wslUtils";
1414class LeetCodeManager extends EventEmitter {
1515private currentUser :string | undefined ;
1616private userStatus :UserStatus ;
17+ private readonly successRegex :RegExp = / (?: .* ) S u c c e s s f u l l y .* l o g i n a s ( .* ) / i;
18+ private readonly failRegex :RegExp = / .* \[ E R R O R \] .* / i;
1719
1820constructor ( ) {
1921super ( ) ;
@@ -42,11 +44,6 @@ class LeetCodeManager extends EventEmitter {
4244detail :"Use LeetCode account to login" ,
4345value :"LeetCode" ,
4446} ,
45- {
46- label :"LeetCode Cookie" ,
47- detail :"Use LeetCode cookie copied from browser to login" ,
48- value :"Cookie" ,
49- } ,
5047{
5148label :"Third-Party: GitHub" ,
5249detail :"Use GitHub account to login" ,
@@ -57,6 +54,11 @@ class LeetCodeManager extends EventEmitter {
5754detail :"Use LinkedIn account to login" ,
5855value :"LinkedIn" ,
5956} ,
57+ {
58+ label :"LeetCode Cookie" ,
59+ detail :"Use LeetCode cookie copied from browser to login" ,
60+ value :"Cookie" ,
61+ } ,
6062) ;
6163const choice :IQuickItemEx < string > | undefined = await vscode . window . showQuickPick ( picks ) ;
6264if ( ! choice ) {
@@ -87,20 +89,22 @@ class LeetCodeManager extends EventEmitter {
8789if ( data . includes ( "twoFactorCode" ) ) {
8890const twoFactor :string | undefined = await vscode . window . showInputBox ( {
8991prompt :"Enter two-factor code." ,
92+ ignoreFocusOut :true ,
9093validateInput :( s :string ) :string | undefined => s && s . trim ( ) ?undefined :"The input must not be empty" ,
9194} ) ;
9295if ( ! twoFactor ) {
9396childProc . kill ( ) ;
9497return resolve ( undefined ) ;
9598}
9699childProc . stdin . write ( `${ twoFactor } \n` ) ;
100+ }
101+ const successMatch :RegExpMatchArray | null = data . match ( this . successRegex ) ;
102+ if ( successMatch && successMatch [ 1 ] ) {
97103childProc . stdin . end ( ) ;
98- } else {
99- const match :RegExpMatchArray | null = data . match ( / (?: .* ) S u c c e s s f u l l y .* l o g i n a s ( .* ) / i) ;
100- if ( match && match [ 1 ] ) {
101- childProc . stdin . end ( ) ;
102- return resolve ( match [ 1 ] ) ;
103- }
104+ return resolve ( successMatch [ 1 ] ) ;
105+ } else if ( data . match ( this . failRegex ) ) {
106+ childProc . stdin . end ( ) ;
107+ return reject ( new Error ( "Faile to login" ) ) ;
104108}
105109} ) ;
106110
@@ -109,6 +113,7 @@ class LeetCodeManager extends EventEmitter {
109113childProc . on ( "error" , reject ) ;
110114const name :string | undefined = await vscode . window . showInputBox ( {
111115prompt :"Enter username or E-mail." ,
116+ ignoreFocusOut :true ,
112117validateInput :( s :string ) :string | undefined => s && s . trim ( ) ?undefined :"The input must not be empty" ,
113118} ) ;
114119if ( ! name ) {
@@ -119,18 +124,14 @@ class LeetCodeManager extends EventEmitter {
119124const pwd :string | undefined = await vscode . window . showInputBox ( {
120125prompt :isByCookie ?"Enter cookie" :"Enter password." ,
121126password :true ,
127+ ignoreFocusOut :true ,
122128validateInput :( s :string ) :string | undefined => s ?undefined :isByCookie ?"Cookie must not be empty" :"Password must not be empty" ,
123129} ) ;
124130if ( ! pwd ) {
125131childProc . kill ( ) ;
126132return resolve ( undefined ) ;
127133}
128134childProc . stdin . write ( `${ pwd } \n` ) ;
129- childProc . on ( "close" , ( code :number ) => {
130- if ( code !== 0 ) {
131- reject ( new Error ( "Failed to login." ) ) ;
132- }
133- } ) ;
134135} ) ;
135136if ( userName ) {
136137vscode . window . showInformationMessage ( `Successfully${ inMessage } .` ) ;