33import * as cp from "child_process" ;
44import { EventEmitter } from "events" ;
55import * as vscode from "vscode" ;
6- import { leetcodeChannel } from "./leetCodeChannel" ;
76import { UserStatus } from "./shared" ;
87import { leetCodeBinaryPath } from "./shared" ;
98import { executeCommand } from "./utils/cpUtils" ;
109import { DialogType , promptForOpenOutputChannel } from "./utils/uiUtils" ;
1110
1211export interface ILeetCodeManager extends EventEmitter {
13- getLoginStatus ( ) : void ;
12+ getLoginStatus ( channel : vscode . OutputChannel ) : void ;
1413 getStatus ( ) : UserStatus ;
1514 getUser ( ) : string | undefined ;
16- signIn ( ) : void ;
17- signOut ( ) : void ;
15+ signIn ( channel : vscode . OutputChannel ) : void ;
16+ signOut ( channel : vscode . OutputChannel ) : void ;
1817}
1918
2019class LeetCodeManager extends EventEmitter implements ILeetCodeManager {
@@ -27,9 +26,9 @@ class LeetCodeManager extends EventEmitter implements ILeetCodeManager {
2726 this . userStatus = UserStatus . SignedOut ;
2827 }
2928
30- public async getLoginStatus ( ) : Promise < void > {
29+ public async getLoginStatus ( channel : vscode . OutputChannel ) : Promise < void > {
3130 try {
32- const result = await executeCommand ( "node" , [ leetCodeBinaryPath , "user" ] ) ;
31+ const result = await executeCommand ( channel , "node" , [ leetCodeBinaryPath , "user" ] ) ;
3332 this . currentUser = result . slice ( "You are now login as" . length ) . trim ( ) ;
3433 this . userStatus = UserStatus . SignedIn ;
3534 } catch ( error ) {
@@ -40,18 +39,18 @@ class LeetCodeManager extends EventEmitter implements ILeetCodeManager {
4039 }
4140 }
4241
43- public async signIn ( ) : Promise < void > {
42+ public async signIn ( channel : vscode . OutputChannel ) : Promise < void > {
4443 try {
4544 const userName : string | undefined = await new Promise ( async ( resolve : ( res : string | undefined ) => void , reject : ( e : Error ) => void ) : Promise < void > => {
4645 let result : string = "" ;
4746 const childProc : cp . ChildProcess = cp . spawn ( "node" , [ leetCodeBinaryPath , "user" , "-l" ] ) ;
4847 childProc . stdout . on ( "data" , ( data : string | Buffer ) => {
4948 data = data . toString ( ) ;
5049 result = result . concat ( data ) ;
51- leetcodeChannel . append ( data ) ;
50+ channel . append ( data ) ;
5251 } ) ;
5352
54- childProc . stderr . on ( "data" , ( data : string | Buffer ) => leetcodeChannel . append ( data . toString ( ) ) ) ;
53+ childProc . stderr . on ( "data" , ( data : string | Buffer ) => channel . append ( data . toString ( ) ) ) ;
5554
5655 childProc . on ( "error" , reject ) ;
5756 const name : string | undefined = await vscode . window . showInputBox ( {
@@ -90,20 +89,20 @@ class LeetCodeManager extends EventEmitter implements ILeetCodeManager {
9089 this . emit ( "statusChanged" ) ;
9190 }
9291 } catch ( error ) {
93- promptForOpenOutputChannel ( "Failed to sign in. Please open the output channel for details" , DialogType . error ) ;
92+ promptForOpenOutputChannel ( "Failed to sign in. Please open the output channel for details" , DialogType . error , channel ) ;
9493 }
9594
9695 }
9796
98- public async signOut ( ) : Promise < void > {
97+ public async signOut ( channel : vscode . OutputChannel ) : Promise < void > {
9998 try {
100- await executeCommand ( "node" , [ leetCodeBinaryPath , "user" , "-L" ] ) ;
99+ await executeCommand ( channel , "node" , [ leetCodeBinaryPath , "user" , "-L" ] ) ;
101100 vscode . window . showInformationMessage ( "Successfully signed out." ) ;
102101 this . currentUser = undefined ;
103102 this . userStatus = UserStatus . SignedOut ;
104103 this . emit ( "statusChanged" ) ;
105104 } catch ( error ) {
106- promptForOpenOutputChannel ( "Failed to sign out. Please open the output channel for details" , DialogType . error ) ;
105+ promptForOpenOutputChannel ( "Failed to sign out. Please open the output channel for details" , DialogType . error , channel ) ;
107106 }
108107 }
109108
0 commit comments